sameThat 或 sameTo phpunit 常量在哪里?
Where are sameThat or sameTo phpunit constants?
我问自己 为什么不存在 PHPUNIT 常量中称为 sameThat
的方法,我要测试的下一段代码。
$user = $this->em->getRepository('AppBundle:User')->findBy(1,1);
最后这是我的测试:
$this->userRepository->expects($this->at(0))
->method('findBy')
->with(
$this->callback(function($arg) use ($test) {
$part = 'In the first call to findBy method, the first parameter: ';
$test->assertThat($arg, $this->logicalAnd(
$this->equalTo(1),
$this->isType('integer')
), $part .'it was found issues'
);//assertThat
return true;
}),
)
->willReturn($this->user);
上面的例子,大家可以看到,有两个PHPUNIT常量equalTo
和isType
,我都用了,因为equalTo
和==
比较,没有===
,所以,我改为findBy("1",1)
,测试没有失败,所以,我添加了isType
常量来确定,所以,现在测试失败了。
有一个断言叫assertSame()
,为什么PHPUNIT的常量没有一个相等的?例如 sameThat
或 sameTo
.
假设您在写 "constant" 时的意思是 "constraint",那么您正在寻找 identicalTo()
。这是 assertSame()
.
使用的约束
我问自己 为什么不存在 PHPUNIT 常量中称为 sameThat
的方法,我要测试的下一段代码。
$user = $this->em->getRepository('AppBundle:User')->findBy(1,1);
最后这是我的测试:
$this->userRepository->expects($this->at(0))
->method('findBy')
->with(
$this->callback(function($arg) use ($test) {
$part = 'In the first call to findBy method, the first parameter: ';
$test->assertThat($arg, $this->logicalAnd(
$this->equalTo(1),
$this->isType('integer')
), $part .'it was found issues'
);//assertThat
return true;
}),
)
->willReturn($this->user);
上面的例子,大家可以看到,有两个PHPUNIT常量equalTo
和isType
,我都用了,因为equalTo
和==
比较,没有===
,所以,我改为findBy("1",1)
,测试没有失败,所以,我添加了isType
常量来确定,所以,现在测试失败了。
有一个断言叫assertSame()
,为什么PHPUNIT的常量没有一个相等的?例如 sameThat
或 sameTo
.
假设您在写 "constant" 时的意思是 "constraint",那么您正在寻找 identicalTo()
。这是 assertSame()
.