6 declare(strict_types=1);
30 private $objectManager;
36 private $jsonSerializer;
39 private $metadataPool;
46 if (!$db->isDbDumpExists()) {
47 throw new \LogicException(
'DB dump does not exist.');
49 $db->restoreFromDbDump();
51 parent::setUpBeforeClass();
54 protected function setUp() : void
57 $this->graphql = $this->objectManager->get(\
Magento\
GraphQl\Controller\GraphQl::class);
58 $this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
59 $this->metadataPool = $this->objectManager->get(MetadataPool::class);
67 public function testDispatch() : void
78 products(filter: {sku: {eq:
"simple1"}})
91 'operationName' => null
97 $headers = $this->objectManager->create(\
Zend\Http\Headers::class)
98 ->addHeaders([
'Content-Type' =>
'application/json']);
102 $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
104 $this->assertArrayNotHasKey(
'errors',
$output,
'Response has errors');
105 $this->assertTrue(!empty(
$output[
'data'][
'products'][
'items']),
'Products array has items');
106 $this->assertTrue(!empty(
$output[
'data'][
'products'][
'items'][0]),
'Products array has items');
107 $this->assertEquals(
$output[
'data'][
'products'][
'items'][0][
'id'],
$product->getData($linkField));
108 $this->assertEquals(
$output[
'data'][
'products'][
'items'][0][
'sku'],
$product->getSku());
109 $this->assertEquals(
$output[
'data'][
'products'][
'items'][0][
'name'],
$product->getName());
117 public function testError() : void
119 $this->markTestSkipped(
'Causes failiure with php unit and php 7.2');
123 customAttributeMetadata(attributes:[
126 entity_type:
"invalid" 142 'operationName' => null
148 $headers = $this->objectManager->create(\
Zend\Http\Headers::class)
149 ->addHeaders([
'Content-Type' =>
'application/json']);
152 $outputResponse = $this->jsonSerializer->unserialize(
$response->getContent());
153 if (isset($outputResponse[
'errors'][0])) {
154 if (is_array($outputResponse[
'errors'][0])) {
155 foreach ($outputResponse[
'errors'] as $error) {
158 \
Magento\Framework\GraphQl\Exception\GraphQlInputException::EXCEPTION_CATEGORY
160 if (isset($error[
'message'])) {
161 $this->assertEquals($error[
'message'],
'Invalid entity_type specified: invalid');
163 if (isset($error[
'trace'])) {
164 if (is_array($error[
'trace'])) {
165 $this->assertNotEmpty($error[
'trace']);
static setUpBeforeClass()
static getObjectManager()