Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel TDD assertSee在NULL对象上返回true_Php_Laravel_Tdd - Fatal编程技术网

Php Laravel TDD assertSee在NULL对象上返回true

Php Laravel TDD assertSee在NULL对象上返回true,php,laravel,tdd,Php,Laravel,Tdd,每当我尝试测试某个不存在的对象属性(实际上为null)时,当使用$this->assertSee($record->someNonExistingProperty)时,测试通过: $this->user->address不存在,但测试返回绿色 这个断言有什么不对?我猜是这样的,它断言它什么都看不见 如果$this->user->address返回null,则您的断言将等同于: $this->get(route('users.index'))->assertSee(null); 我

每当我尝试测试某个不存在的对象属性(实际上为null)时,当使用
$this->assertSee($record->someNonExistingProperty)
时,测试通过:

$this->user->address
不存在,但测试返回绿色


这个断言有什么不对?

我猜是这样的,它断言它什么都看不见

如果
$this->user->address
返回
null
,则您的断言将等同于:

$this->get(route('users.index'))->assertSee(null);

我也会对你的objects属性做一个断言。像这样:

$this->assertTrue($this->user->address !== null);
$this->get(route('users.index'))->assertSee($this->user->address);

assert-see上的文档声明它查找字符串,并将转义给定的任何值


是的,我可以使用
$this->assertNotNull($this->user->address)
作为预保险柜,但我不确定为什么“assertSee”可以通过,即使它不应该通过,因为它取决于
assertSee()
正在检查的内容。如果它试图匹配一个字符串,那么
null
将相当于
'
,它将在DOM中无处不在。我从来没有试过在测试中检查是否可以看到
null
,哈哈
$this->assertTrue($this->user->address !== null);
$this->get(route('users.index'))->assertSee($this->user->address);