|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\GraphQlCache\Test\Unit\Controller\Plugin; |
| 9 | + |
| 10 | +use Magento\Framework\App\FrontControllerInterface; |
| 11 | +use Magento\Framework\App\Request\Http; |
| 12 | +use Magento\Framework\App\Response\Http as ResponseHttp; |
| 13 | +use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
| 14 | +use Magento\GraphQl\Controller\HttpRequestProcessor; |
| 15 | +use Magento\GraphQlCache\Controller\Plugin\GraphQl; |
| 16 | +use Magento\GraphQlCache\Model\CacheableQuery; |
| 17 | +use Magento\GraphQlCache\Model\CacheId\CacheIdCalculator; |
| 18 | +use Magento\PageCache\Model\Config; |
| 19 | +use PHPUnit\Framework\MockObject\MockObject; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | +use Psr\Log\LoggerInterface; |
| 22 | + |
| 23 | +/** |
| 24 | + * Test beforeDispatch |
| 25 | + */ |
| 26 | +class GraphQlTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @var GraphQl |
| 30 | + */ |
| 31 | + private $graphql; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var CacheableQuery|MockObject |
| 35 | + */ |
| 36 | + private $cacheableQueryMock; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var Config|MockObject |
| 40 | + */ |
| 41 | + private $configMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var ResponseHttp|MockObject |
| 45 | + */ |
| 46 | + private $responseMock; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var HttpRequestProcessor|MockObject |
| 50 | + */ |
| 51 | + private $requestProcessorMock; |
| 52 | + |
| 53 | + /** |
| 54 | + * @var CacheIdCalculator|MockObject |
| 55 | + */ |
| 56 | + private $cacheIdCalculatorMock; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var LoggerInterface|MockObject |
| 60 | + */ |
| 61 | + private $loggerMock; |
| 62 | + |
| 63 | + /** |
| 64 | + * @var FrontControllerInterface|MockObject |
| 65 | + */ |
| 66 | + private $subjectMock; |
| 67 | + |
| 68 | + /** |
| 69 | + * @var Http|MockObject |
| 70 | + */ |
| 71 | + private $requestMock; |
| 72 | + |
| 73 | + protected function setUp(): void |
| 74 | + { |
| 75 | + $this->cacheableQueryMock = $this->createMock(CacheableQuery::class); |
| 76 | + $this->cacheIdCalculatorMock = $this->createMock(CacheIdCalculator::class); |
| 77 | + $this->configMock = $this->createMock(Config::class); |
| 78 | + $this->loggerMock = $this->getMockBuilder(LoggerInterface::class) |
| 79 | + ->onlyMethods(['critical']) |
| 80 | + ->disableOriginalConstructor() |
| 81 | + ->getMockForAbstractClass(); |
| 82 | + $this->requestProcessorMock = $this->getMockBuilder(HttpRequestProcessor::class) |
| 83 | + ->onlyMethods(['validateRequest','processHeaders']) |
| 84 | + ->disableOriginalConstructor() |
| 85 | + ->getMockForAbstractClass(); |
| 86 | + $this->responseMock = $this->createMock(ResponseHttp::class); |
| 87 | + $this->subjectMock = $this->createMock(FrontControllerInterface::class); |
| 88 | + $this->requestMock = $this->createMock(Http::class); |
| 89 | + $this->graphql = new GraphQl( |
| 90 | + $this->cacheableQueryMock, |
| 91 | + $this->cacheIdCalculatorMock, |
| 92 | + $this->configMock, |
| 93 | + $this->loggerMock, |
| 94 | + $this->requestProcessorMock, |
| 95 | + $this->responseMock |
| 96 | + ); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * test beforeDispatch function for validation purpose |
| 101 | + */ |
| 102 | + public function testBeforeDispatch(): void |
| 103 | + { |
| 104 | + $this->requestProcessorMock |
| 105 | + ->expects($this->any()) |
| 106 | + ->method('validateRequest'); |
| 107 | + $this->requestProcessorMock |
| 108 | + ->expects($this->any()) |
| 109 | + ->method('processHeaders'); |
| 110 | + $this->loggerMock |
| 111 | + ->expects($this->any()) |
| 112 | + ->method('critical'); |
| 113 | + $this->assertNull($this->graphql->beforeDispatch($this->subjectMock, $this->requestMock)); |
| 114 | + } |
| 115 | +} |
0 commit comments