首先,您應該使用最新版本的PHPUnit(v6.x)。 PHPUnit_Framework_TestCase的存在使它看起來像你使用的是舊版本。但我離題...
你想要一個數據提供者。
class myTestCase extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerTestMyCase
**/
public function testMyCase($date, $expectedRowCount) {
$sql = "select * from testCase where date = '$date'";
$stmt = self::$pdo->prepare($sql);
$result = $stmt->execute($sql);
//We expect the query will always work.
$this->assertTrue($result);
//We are expecting the rowcount will be consistent with the expected rowcounts.
$this->assertSame($expectedRowCount,$stmt->rowCount());
}
public funtion providerTestMyCase() {
return [ [ '2017-08-01' , 76 ]
, [ '2017-08-02' , 63 ]
, [ '2017-08-03' , 49 ]
, [ '2017-08-04' , 31 ]
, [ '2017-08-05' , 95 ]
]
}
}
閱讀和重新閱讀:Database Testing以及@dataProvider
mmm似乎不可能。檢查這個答案可以以某種方式幫助你https://stackoverflow.com/a/32467538/2270041 – Matteo
assertTrue()的第二個參數預計是一個字符串,參見https://github.com/ sebastianbergmann/PHPUnit的/ BLOB/6.3.0/src目錄/框架/ Assert.php#L1148-L1151。 – localheinz
請參閱https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers。 – localheinz