19
19
* @magentoAppArea graphql
20
20
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_url_key.php
21
21
*/
22
-
23
22
class GraphQlControllerTest extends \PHPUnit \Framework \TestCase
24
23
{
25
24
const CONTENT_TYPE = 'application/json ' ;
26
25
27
- /**
28
- * @var \Magento\Framework\ObjectManagerInterface
29
- */
26
+ /** @var \Magento\Framework\ObjectManagerInterface */
30
27
private $ objectManager ;
31
28
32
- /**
33
- * @var GraphQl $graphql
34
- */
29
+ /** @var GraphQl */
35
30
private $ graphql ;
36
31
37
32
/** @var SerializerInterface */
@@ -42,7 +37,6 @@ class GraphQlControllerTest extends \PHPUnit\Framework\TestCase
42
37
43
38
protected function setUp ()
44
39
{
45
- // parent::setUp();
46
40
$ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
47
41
$ this ->graphql = $ this ->objectManager ->get (\Magento \GraphQl \Controller \GraphQl::class);
48
42
$ this ->jsonSerializer = $ this ->objectManager ->get (SerializerInterface::class);
@@ -88,7 +82,10 @@ public function testDispatch()
88
82
$ response = $ this ->graphql ->dispatch ($ request );
89
83
$ output = $ this ->jsonSerializer ->unserialize ($ response ->getContent ());
90
84
$ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
91
- $ this ->assertTrue (count ($ output ['data ' ]['products ' ]['items ' ]) > 0 , 'Products array has items ' );
85
+
86
+ $ this ->assertArrayNotHasKey ('errors ' , $ output , 'Response has errors ' );
87
+ $ this ->assertTrue (!empty ($ output ['data ' ]['products ' ]['items ' ]), 'Products array has items ' );
88
+ $ this ->assertTrue (!empty ($ output ['data ' ]['products ' ]['items ' ][0 ]), 'Products array has items ' );
92
89
$ this ->assertEquals ($ output ['data ' ]['products ' ]['items ' ][0 ]['id ' ], $ product ->getData ($ linkField ));
93
90
$ this ->assertEquals ($ output ['data ' ]['products ' ]['items ' ][0 ]['sku ' ], $ product ->getSku ());
94
91
$ this ->assertEquals ($ output ['data ' ]['products ' ]['items ' ][0 ]['name ' ], $ product ->getName ());
0 commit comments