@@ -29,25 +29,45 @@ trait ApiTestAssertionsTrait
29
29
30
30
/**
31
31
* Asserts that the retrieved JSON contains has the specified subset.
32
+ *
32
33
* This method delegates to self::assertArraySubset().
33
34
*
35
+ * @param array|string $subset
36
+ *
34
37
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
35
38
* @throws \Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
36
39
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
37
40
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
38
41
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
39
42
*/
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
41
44
{
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
+
42
52
static ::assertArraySubset ($ subset , self ::getHttpResponse ()->toArray (false ), $ checkForObjectIdentity , $ message );
43
53
}
44
54
45
55
/**
46
- * Asserts that the retrieved JSON is equal to the following array.
56
+ * Asserts that the retrieved JSON is equal to $json.
57
+ *
47
58
* Both values are canonicalized before the comparision.
59
+ *
60
+ * @param array|string $json
48
61
*/
49
- public static function assertJsonEquals (array $ json , string $ message = '' ): void
62
+ public static function assertJsonEquals ($ json , string $ message = '' ): void
50
63
{
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
+
51
71
static ::assertEqualsCanonicalizing ($ json , self ::getHttpResponse ()->toArray (false ), $ message );
52
72
}
53
73
0 commit comments