2017-10-11 15 views
0

나는 스스로에게 물어 보았다 왜 존재하지 않는가sameThat PHPUNIT 상수, 그 다음 조각 코드 내가 원하는 테스트라는 메서드. 당신이 볼 수 있듯이없는 내가 ==로 인해 equalTo compairs 그것을 사용하는 두 개의 phpunit을가 equalToisType 상수가,동일하거나 동일합니까?

$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); 

위의 예 :

$user = $this->em->getRepository('AppBundle:User')->findBy(1,1); 

마지막이 내 테스트입니다 ===, 그래서 findBy("1",1) 대신 테스트가 실패하지 않으므로 isType 상수를 추가 했으므로 이제 테스트가 실패합니다.

assertSame()이라는 어설 션이 있는데, 왜 PHPUNIT의 상수는 같지 않습니까? 예 : sameThat 또는 sameTo.

+2

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

+0

''equalTo()'와''isType()'은 [상수]가 아닌 [인스턴스 메소드] (http://php.net/manual/en/language.oop5.basic.php) /php.net/manual/en/language.oop5.constants.php) – axiac

답변

3

"상수"를 쓸 때 "제약 조건"이라고 가정하면 identicalTo()을 찾고 있습니다. 이것이 assertSame()에 의해 사용되는 제약 조건입니다.