@@ -1462,6 +1462,88 @@ public function testAssertJsonStructure()
1462
1462
$ response ->assertJsonStructure (['* ' => ['foo ' , 'bar ' , 'foobar ' ]]);
1463
1463
}
1464
1464
1465
+ public function testAssertExactJsonStructure ()
1466
+ {
1467
+ $ response = TestResponse::fromBaseResponse (new Response (new JsonSerializableMixedResourcesStub ));
1468
+
1469
+ // Without structure
1470
+ $ response ->assertExactJsonStructure ();
1471
+
1472
+ // At root
1473
+ try {
1474
+ $ response ->assertExactJsonStructure (['foo ' ]);
1475
+ $ failed = false ;
1476
+ } catch (AssertionFailedError $ e ) {
1477
+ $ failed = true ;
1478
+ }
1479
+
1480
+ $ this ->assertTrue ($ failed );
1481
+
1482
+ $ response ->assertExactJsonStructure (['foo ' , 'foobar ' , 0 , 'bars ' , 'baz ' , 'barfoo ' , 'numeric_keys ' ]);
1483
+
1484
+ // Nested
1485
+ try {
1486
+ $ response ->assertExactJsonStructure (['foobar ' => ['foobar_foo ' ], 'foo ' , 0 , 'bars ' , 'baz ' , 'barfoo ' , 'numeric_keys ' ]);
1487
+ $ failed = false ;
1488
+ } catch (AssertionFailedError $ e ) {
1489
+ $ failed = true ;
1490
+ }
1491
+
1492
+ $ this ->assertTrue ($ failed );
1493
+
1494
+ $ response ->assertExactJsonStructure (['foobar ' => ['foobar_foo ' , 'foobar_bar ' ], 'foo ' , 0 , 'bars ' , 'baz ' , 'barfoo ' , 'numeric_keys ' ]);
1495
+
1496
+ // Wildcard (repeating structure)
1497
+ try {
1498
+ $ response ->assertExactJsonStructure (['bars ' => ['* ' => ['bar ' ]], 'foo ' , 'foobar ' , 0 , 'baz ' , 'barfoo ' , 'numeric_keys ' ]);
1499
+ $ failed = false ;
1500
+ } catch (AssertionFailedError $ e ) {
1501
+ $ failed = true ;
1502
+ }
1503
+
1504
+ $ this ->assertTrue ($ failed );
1505
+
1506
+ $ response ->assertExactJsonStructure (['bars ' => ['* ' => ['bar ' , 'foo ' ]], 'foo ' , 'foobar ' , 0 , 'baz ' , 'barfoo ' , 'numeric_keys ' ]);
1507
+
1508
+ // Wildcard (numeric keys)
1509
+ try {
1510
+ $ response ->assertExactJsonStructure (['numeric_keys ' => ['* ' => ['bar ' ]], 'foo ' , 'foobar ' , 0 , 'bars ' , 'baz ' , 'barfoo ' ]);
1511
+ $ failed = false ;
1512
+ } catch (AssertionFailedError $ e ) {
1513
+ $ failed = true ;
1514
+ }
1515
+
1516
+ $ this ->assertTrue ($ failed );
1517
+
1518
+ $ response ->assertExactJsonStructure (['numeric_keys ' => ['* ' => ['bar ' , 'foo ' ]], 'foo ' , 'foobar ' , 0 , 'bars ' , 'baz ' , 'barfoo ' ]);
1519
+
1520
+ // Nested after wildcard
1521
+ try {
1522
+ $ response ->assertExactJsonStructure (['baz ' => ['* ' => ['foo ' , 'bar ' => ['foo ' ]]], 'foo ' , 'foobar ' , 0 , 'bars ' , 'barfoo ' , 'numeric_keys ' ]);
1523
+ $ failed = false ;
1524
+ } catch (AssertionFailedError $ e ) {
1525
+ $ failed = true ;
1526
+ }
1527
+
1528
+ $ this ->assertTrue ($ failed );
1529
+
1530
+ $ response ->assertExactJsonStructure (['baz ' => ['* ' => ['foo ' , 'bar ' => ['foo ' , 'bar ' ]]], 'foo ' , 'foobar ' , 0 , 'bars ' , 'barfoo ' , 'numeric_keys ' ]);
1531
+
1532
+ // Wildcard (repeating structure) at root
1533
+ $ response = TestResponse::fromBaseResponse (new Response (new JsonSerializableSingleResourceStub ));
1534
+
1535
+ try {
1536
+ $ response ->assertExactJsonStructure (['* ' => ['foo ' , 'bar ' ]]);
1537
+ $ failed = false ;
1538
+ } catch (AssertionFailedError $ e ) {
1539
+ $ failed = true ;
1540
+ }
1541
+
1542
+ $ this ->assertTrue ($ failed );
1543
+
1544
+ $ response ->assertExactJsonStructure (['* ' => ['foo ' , 'bar ' , 'foobar ' ]]);
1545
+ }
1546
+
1465
1547
public function testAssertJsonCount ()
1466
1548
{
1467
1549
$ response = TestResponse::fromBaseResponse (new Response (new JsonSerializableMixedResourcesStub ));
0 commit comments