Php Laravel TDD assertSee在NULL对象上返回true
每当我尝试测试某个不存在的对象属性(实际上为null)时,当使用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); 我
$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);