assertArraySubset()


assertArraySubset(array $subset, array $array[, bool $strict = '', string $message = ''])

$array 不包含 $subset 时报告错误,错误讯息由 $message 指定。

$strict 是一个标志,用于表明是否需要对数组中的对象进行全等判定。


例 A.3: assertArraySubset() 的用法

  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3.  
  4. class ArraySubsetTest extends TestCase
  5. {
  6. public function testFailure()
  7. {
  8. $this->assertArraySubset(['config' => ['key-a', 'key-b']], ['config' => ['key-a']]);
  9. }
  10. }
  11. ?>
  1. phpunit ArrayHasKeyTest
  2. PHPUnit 4.4.0 by Sebastian Bergmann.
  3.  
  4. F
  5.  
  6. Time: 0 seconds, Memory: 5.00Mb
  7.  
  8. There was 1 failure:
  9.  
  10. 1) Epilog\EpilogTest::testNoFollowOption
  11. Failed asserting that an array has the subset Array &0 (
  12. 'config' => Array &1 (
  13. 0 => 'key-a'
  14. 1 => 'key-b'
  15. )
  16. ).
  17.  
  18. /home/sb/ArraySubsetTest.php:6
  19.  
  20. FAILURES!
  21. Tests: 1, Assertions: 1, Failures: 1.