assertArraySubset() public static method

Asserts that an array has a specified subset.
public static assertArraySubset ( array | ArrayAccess $subset, array | ArrayAccess $array, boolean $strict = false, string $message = '' )
$subset array | ArrayAccess
$array array | ArrayAccess
$strict boolean Check for object identity
$message string
Esempio n. 1
0
 /**
  * Assert that the response is a superset of the given JSON.
  *
  * @param  array  $data
  * @return void
  */
 public function assertHasJson(array $data)
 {
     PHPUnit::assertArraySubset($data, $this->decodeResponseJson());
 }
 /**
  * Assert that the resource's relationships contains the provided subset.
  *
  * @param object|array $expected
  * @param string|null $message
  * @return $this
  */
 public function assertRelationshipsSubset($expected, $message = null)
 {
     $expected = ObjectUtils::toArray($expected);
     $actual = ObjectUtils::toArray($this->getRelationships() ?: []);
     $message = $message ? $this->withIndex($message) : $this->withIndex('Unexpected resource relationships') . ': ' . json_encode($actual);
     PHPUnit::assertArraySubset($expected, $actual, $message);
     return $this;
 }
Esempio n. 3
0
 /**
  * Expect that an array has a specified subset.
  *
  * @param array|ArrayAccess $subset
  * @param bool $strict Check for object identity
  * @param string $message
  *
  * @return Expect
  */
 public function toHaveSubset($subset, $strict = false, $message = '')
 {
     Assert::assertArraySubset($subset, $this->value, $strict, $message);
     return $this;
 }
 /**
  * See that there is a resource object as primary data.
  *
  * @param array $expected
  *      the expected array representation of the resource.
  * @return $this
  */
 protected function seeDataResource(array $expected)
 {
     if (!isset($expected[Keys::KEYWORD_TYPE])) {
         PHPUnit::fail(sprintf('Expected resource must have a "%s" key.', Keys::KEYWORD_TYPE));
     }
     $attributes = isset($expected[Keys::KEYWORD_ATTRIBUTES]) ? $expected[Keys::KEYWORD_ATTRIBUTES] : [];
     $relationships = isset($expected[Keys::KEYWORD_RELATIONSHIPS]) ? $this->normalizeResourceRelationships($expected[Keys::KEYWORD_RELATIONSHIPS]) : [];
     /** Check the structure is as expected. */
     $structure = [Keys::KEYWORD_TYPE, Keys::KEYWORD_ID];
     if (!empty($attributes)) {
         $structure[Keys::KEYWORD_ATTRIBUTES] = array_keys($attributes);
     }
     if (!empty($relationships)) {
         $structure[Keys::KEYWORD_RELATIONSHIPS] = array_keys($relationships);
     }
     $this->seeJsonStructure([Keys::KEYWORD_DATA => $structure]);
     $data = $this->decodeResponseJson()[Keys::KEYWORD_DATA];
     /** Have we got the correct resource type? */
     PHPUnit::assertEquals($expected[Keys::KEYWORD_TYPE], $data[Keys::KEYWORD_TYPE], 'Unexpected resource type');
     /** Have we got the correct resource id? */
     if (isset($expected[Keys::KEYWORD_ID])) {
         PHPUnit::assertEquals($expected[Keys::KEYWORD_ID], $data[Keys::KEYWORD_ID], 'Unexpected resource id');
     }
     /** Have we got the correct attributes? */
     PHPUnit::assertArraySubset($attributes, $data[Keys::KEYWORD_ATTRIBUTES], false, "Unexpected resource attributes\n" . json_encode($data[Keys::KEYWORD_ATTRIBUTES]));
     /** Have we got the correct relationships? */
     $actualRelationships = isset($data[Keys::KEYWORD_RELATIONSHIPS]) ? $data[Keys::KEYWORD_RELATIONSHIPS] : [];
     PHPUnit::assertArraySubset($relationships, $actualRelationships, false, "Unexpected resource relationships\n" . json_encode($actualRelationships));
     return $this;
 }