abstract class App_Tests_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase {
protected $App;
/**
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
public function log($text)
{
$file = '/Applications/MAMP/htdocs/zumba/app/vendors/billing/tests/abstract/log.txt';
$current = file_get_contents($file);
$current .= $text."\n";
file_put_contents($file, $current);
}
final public function getConnection()
{
$this->log("Initiate Get Connection");
$this->App = new App();
if ($this->conn === null) {
if (self::$pdo == null) {
self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] );
}
$this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']);
}
return $this->conn;
}
protected function getDataSet()
{
$this->log("Initiate GetDataSet");
return new ZumbaDbUnitArrayDataSet(array(
'guestbook' => array(
array('id' => 1, 'content' => 'Hello buddy!', 'user' => 'joe', 'created' => '2010-04-24 17:15:23'),
array('id' => 2, 'content' => 'I like it!', 'user' => null, 'created' => '2010-04-26 12:14:20'),
),
));
}
protected function setUp() {
$this->log("Initiate Setup");
$this->App = new App();
}
protected function tearDown() {
$this->log("Initiate Tear Down");
unset($this->App);
}
}
我添加了一个日志来跟踪进度但结果相同
Configuration read from
F Initiate Setup Initiate Tear Down
Time: 0 seconds, Memory: 6.25Mb
There was 1 failure:
1) BillingControlTest::test_funrun
Failed asserting that false is true.
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
我执行此文件
class BillingControlTest extends App_Tests_DatabaseTestCase {
function test_funrun()
{
$returnVal = $this->App->query("UPDATE guestbook SET created = NOW() WHERE id = 1");
$this->assertTrue($returnVal);
}
}
如你所见。它贯穿setup和tearDown但跳过getConnection和getDataset。我正在关注网站上的教程。