@@ -29,25 +29,45 @@ trait ApiTestAssertionsTrait
2929
3030 /**
3131 * Asserts that the retrieved JSON contains has the specified subset.
32+ *
3233 * This method delegates to self::assertArraySubset().
3334 *
35+ * @param array|string $subset
36+ *
3437 * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
3538 * @throws \Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
3639 * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
3740 * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
3841 * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
3942 */
40- public static function assertJsonContains (array $ subset , bool $ checkForObjectIdentity = true , string $ message = '' ): void
43+ public static function assertJsonContains ($ subset , bool $ checkForObjectIdentity = true , string $ message = '' ): void
4144 {
45+ if (\is_string ($ subset )) {
46+ $ subset = json_decode ($ subset , true );
47+ }
48+ if (!\is_array ($ subset )) {
49+ throw new \InvalidArgumentException ('$subset must be array or string (JSON array or JSON object) ' );
50+ }
51+
4252 static ::assertArraySubset ($ subset , self ::getHttpResponse ()->toArray (false ), $ checkForObjectIdentity , $ message );
4353 }
4454
4555 /**
46- * Asserts that the retrieved JSON is equal to the following array.
56+ * Asserts that the retrieved JSON is equal to $json.
57+ *
4758 * Both values are canonicalized before the comparision.
59+ *
60+ * @param array|string $json
4861 */
49- public static function assertJsonEquals (array $ json , string $ message = '' ): void
62+ public static function assertJsonEquals ($ json , string $ message = '' ): void
5063 {
64+ if (\is_string ($ json )) {
65+ $ json = json_decode ($ json , true );
66+ }
67+ if (!\is_array ($ json )) {
68+ throw new \InvalidArgumentException ('$json must be array or string (JSON array or JSON object) ' );
69+ }
70+
5171 static ::assertEqualsCanonicalizing ($ json , self ::getHttpResponse ()->toArray (false ), $ message );
5272 }
5373
0 commit comments