2017-10-11 121 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()使用的限制。