0
確定,所以這是與開始以數字串僅失敗一個簡單的單元測試。PHP 7.2的非井形成數值遇到測試失敗,但爲什麼呢?
我的原班在這裏
class InstanceID implements InstanceIDInterface
{
private $id;
public function __construct(int $id)
{
$this->id = $id;
}
}
這裏是單元測試
class InstanceIDTest extends \PHPUnit_Framework_TestCase
{
public function testCanInitializeWithValidID()
{
$InstanceID = new InstanceID(3456);
$this->assertInstanceOf('InstanceID', $InstanceID);
}
/**
* @dataProvider invalidStrings
*/
public function testNonNumericStringShouldNotBeAccepted($id)
{
$this->expectException(TypeError::class);
$InstanceID = new InstanceID($id);
}
public function invalidStrings() {
return [
["ABC1234"], // works
["1234WUK"], // error
["W1234W"], // works
["1234yHk92383"] // error
];
}
}
,這是試運行結果
There were 2 errors:
1) InstanceIDTest::testNonNumericStringShouldNotBeAccepted with data set #1 ('1234WUK')
A non well formed numeric value encountered
2) InstanceIDTest::testNonNumericStringShouldNotBeAccepted with data set #3 ('1234yHk92383')
A non well formed numeric value encountered
問題是爲什麼錯誤不是通過 $這個 - > expectException(類型錯誤::類)被抓; 線?