-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gusakov Nikita
committed
Apr 21, 2014
1 parent
5f93a66
commit 9ad9165
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Flame\Test; | ||
|
||
use Flame\Connection; | ||
use Flame\Statement; | ||
|
||
class StatementTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @var Statement | ||
*/ | ||
private $insertQuery; | ||
|
||
/** | ||
* @var Statement | ||
*/ | ||
private $selectQuery; | ||
|
||
protected function setUp() | ||
{ | ||
$this->connection = new Connection('sqlite::memory:'); | ||
$this->connection->query('CREATE TABLE users (id INT PRIMARY KEY, username CHAR(50), age INT)'); | ||
$this->insertQuery = $this->connection->prepare('INSERT INTO users (username, age) VALUES(s:username, i:age)'); | ||
$this->selectQuery = $this->connection->prepare('SELECT * FROM users'); | ||
|
||
$this->insertQuery->execute(['username' => 'nkt', 'age' => 20]); | ||
} | ||
|
||
public function testValueConverters() | ||
{ | ||
$this->insertQuery->execute(['username' => null, 'age' => '20foobar']); | ||
$insertedData = $this->connection->query('SELECT username, age FROM users ORDER BY id DESC')->fetch(\PDO::FETCH_ASSOC); | ||
|
||
$this->assertEquals(['username' => null, 'age' => '20'], $insertedData); | ||
} | ||
|
||
public function testFetchCallback() | ||
{ | ||
$i = 0; | ||
$results = $this->selectQuery->execute()->fetchCallback(function ($data) use (&$i) { | ||
$i++; | ||
|
||
return $data['id']; | ||
}); | ||
$this->assertCount($i, $results); | ||
} | ||
|
||
public function testCloseCursor() | ||
{ | ||
iterator_to_array($this->selectQuery->execute()); | ||
$this->assertEquals($this->selectQuery, $this->selectQuery->closeCursor()); | ||
} | ||
|
||
public function testInvoke() | ||
{ | ||
$stmt = $this->selectQuery; | ||
|
||
$this->assertSame($this->selectQuery, $stmt()); | ||
} | ||
|
||
public function testToString() | ||
{ | ||
$this->assertEquals($this->insertQuery->queryString, (string)$this->insertQuery); | ||
} | ||
} |