2017-10-11 123 views
0

我在问自己为什么不存在一个名为sameThat的方法在phpunit常量里面,我想测试下一段代码。哪里是相同的或相同的phpunit常量?

$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的常数equalToisType,无论我用它,因为equalTo compairs与==,无===,所以,我改变了findBy("1",1),测试没有失败,所以,我加了isType不变,所以现在测试失败了。

有一个称为assertSame()的断言,为什么没有一个等于PHPUNIT的常量?例如sameThatsameTo

+2

'$ test-> assertSame(1,$ arg);'? – xmike

+0

'equalTo()'和'isType()'是[实例方法](http://php.net/manual/en/language.oop5.basic.php)(即函数)而不是[常量](http:///php.net/manual/en/language.oop5.constants.php) – axiac

回答

3

假设你的意思是“约束”,当你写“常量”,那么你正在寻找identicalTo()。这是assertSame()使用的限制。