Skip to content

Instantly share code, notes, and snippets.

@wata727
Last active November 29, 2015 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wata727/187dfb13cb5a6bccf7a6 to your computer and use it in GitHub Desktop.
Save wata727/187dfb13cb5a6bccf7a6 to your computer and use it in GitHub Desktop.
FuelPHPでdbunitを使ってテストするサンプル
<?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