|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Framework\GraphQlSchemaStitching\Test\Unit; |
| 10 | + |
| 11 | +use Magento\Framework\GraphQlSchemaStitching\GraphQlReader; |
| 12 | +use Magento\Framework\ObjectManagerInterface; |
| 13 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 14 | +use PHPUnit\Framework\MockObject\MockObject; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use Magento\Framework\Config\FileResolverInterface; |
| 17 | +use Magento\Framework\Config\FileIterator; |
| 18 | +use Magento\Framework\Component\ComponentRegistrar; |
| 19 | + |
| 20 | +/** |
| 21 | + * Test of the stitching of graphql schemas together |
| 22 | + */ |
| 23 | +class GraphQlReaderTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * Object Manager Instance |
| 27 | + * |
| 28 | + * @var ObjectManager |
| 29 | + */ |
| 30 | + private $objectManager; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var GraphQlReader|MockObject |
| 34 | + */ |
| 35 | + private $graphQlReader; |
| 36 | + |
| 37 | + protected function setUp(): void |
| 38 | + { |
| 39 | + /** @var ObjectManagerInterface $objectManager */ |
| 40 | + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 41 | + |
| 42 | + $this->graphQlReader = $this->objectManager->create( |
| 43 | + GraphQlReader::class |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * This test ensures that the global graphql schemas have all the required dependencies and can be stitched together |
| 49 | + * |
| 50 | + * The $results variables contains the actual schema as it will be on a production site which will vary per each |
| 51 | + * update of magento, so asserting the array matches the entire schema does not make full sense here as any change |
| 52 | + * in graphql in any magento module would break the test. |
| 53 | + * |
| 54 | + * Testing this way means we do not need to store the module meta data that was introduced in |
| 55 | + * https://github.com/magento/magento2/pull/28747 which means we can greatly improve the performance of this |
| 56 | + */ |
| 57 | + public function testStitchGlobalGraphQLSchema() |
| 58 | + { |
| 59 | + $results = $this->graphQlReader->read('global'); |
| 60 | + |
| 61 | + $this->assertArrayHasKey('Price', $results); |
| 62 | + $this->assertArrayHasKey('Query', $results); |
| 63 | + $this->assertArrayHasKey('Mutation', $results); |
| 64 | + $this->assertArrayHasKey('ProductInterface', $results); |
| 65 | + $this->assertArrayHasKey('SimpleProduct', $results); |
| 66 | + } |
| 67 | +} |
0 commit comments