2014-05-22 3 views
5

phpunit을 사용하여 단위 테스트를 작성하고 있는데 배열에 특정 값이 포함되어 있다고 주장하려고합니다.하지만 찾을 수있는 함수는 assertArrayHasKey()뿐입니다. 어떤 assertArrayHasValue도 없습니다.PHP : 배열에 특정 값이 있다고 주장하는 방법?

$a = [5, 8, 16]; 
assertArrayHasValue(8, $a); 

모든 팁 환영합니다 :

그래서 나는 이런 식으로 뭔가를 원하는 분명합니다! 이 시도

+0

http://ouzo.readthedocs.org/en/latest/documentation/tests.html#array-assertions뿐만 아니라 주장의 목록을 참조하십시오. http://stackoverflow.com/questions/569369/list-of-all-phpunit-assertions –

+0

[PHPUnit을 사용하여 값이 배열에 포함되어 있는지 테스트] 가능한 복제본 (https://stackoverflow.com/questions/31638220/test) -if-array-value-using-phpunit) – Tiger

답변

5

당신은 기능 assertContains()

와 함께 할 수 있습니다 : 당신은 ouzo goodies library을 사용할 수 있습니다

$a = [5, 8, 16]; 
$this->assertContains(8, $a); 

ASSERT_CONTAINS

2

.

$animals = ['cat', 'dog', 'pig']; 
Assert::thatArray($animals)->hasSize(3)->contains('cat'); 

예를 들어 체인화 할 수있는 많은 흥미로운 주장이 있습니다.

Assert::thatArray($users)->onMethod('getAge')->containsOnly(35, 24); 

은 어쩌면 도움이 될 것입니다, 여기에

관련 문제