Last active
November 29, 2015 17:26
-
-
Save wata727/187dfb13cb5a6bccf7a6 to your computer and use it in GitHub Desktop.
FuelPHPでdbunitを使ってテストするサンプル
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
<?php | |
/** | |
* 使用バージョン | |
* FuelPHP 1.7.0 | |
* PHPUnit 4.8.18 | |
* DBUnit 2.0.2 | |
* | |
* /user/createはGETメソッドで単純に決められたデータを登録するだけのイメージ | |
* | |
* @group Orm | |
*/ | |
class Test_Users extends \PHPUnit_Extensions_Database_TestCase | |
{ | |
protected function getConnection() | |
{ | |
$db = Database_Connection::instance(); | |
return $this->createDefaultDBConnection($db->connection(), 'test'); | |
} | |
protected function getDataSet() | |
{ | |
return $this->createArrayDataSet(array( | |
'users' => array( | |
array('id' => 1, 'name' => 'watanabe'), | |
) | |
)); | |
} | |
public function test_usercreate() | |
{ | |
$this->assertEquals(1, $this->getConnection()->getRowCount('users')); | |
$response = Request::forge('user/create')->execute()->response(); | |
$queryTable = $this->getConnection()->createQueryTable( | |
'users', 'SELECT * from users' | |
); | |
$expectedTable = $this->createArrayDataSet(array( | |
'users' => array( | |
array('id' => 1, 'name' => 'watanabe'), | |
array('id' => 2, 'name' => 'kazuma'), | |
) | |
))->getTable('users'); | |
$this->assertTablesEqual($expectedTable, $queryTable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment