AssertArrayContains.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Assert;
  7. use PHPUnit\Framework\Assert;
  8. /**
  9. * Check that actual data contains all values from expected data
  10. * But actual data can have more values than expected data
  11. */
  12. class AssertArrayContains
  13. {
  14. /**
  15. * @param array $expected
  16. * @param array $actual
  17. * @return void
  18. */
  19. public static function assert(array $expected, array $actual)
  20. {
  21. foreach ($expected as $key => $value) {
  22. Assert::assertArrayHasKey(
  23. $key,
  24. $actual,
  25. "Expected value for key '{$key}' is missed"
  26. );
  27. if (is_array($value)) {
  28. self::assert($value, $actual[$key]);
  29. } else {
  30. Assert::assertEquals(
  31. $value,
  32. $actual[$key],
  33. "Expected value for key '{$key}' doesn't match"
  34. );
  35. }
  36. }
  37. }
  38. }