|
| 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\Framework\Webapi\Test\Unit\Backpressure; |
| 9 | + |
| 10 | +use Magento\Framework\Webapi\Backpressure\BackpressureRequestTypeExtractorInterface; |
| 11 | +use PHPUnit\Framework\MockObject\MockObject; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | +use Magento\Framework\Webapi\Backpressure\CompositeRequestTypeExtractor; |
| 14 | + |
| 15 | +/** |
| 16 | + * Tests the CompositeRequestTypeExtractor class |
| 17 | + */ |
| 18 | +class CompositeRequestTypeExtractorTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var CompositeRequestTypeExtractor |
| 22 | + */ |
| 23 | + private CompositeRequestTypeExtractor $compositeRequestTypeExtractor; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var BackpressureRequestTypeExtractorInterface|MockObject |
| 27 | + */ |
| 28 | + private $extractorMock; |
| 29 | + |
| 30 | + /** |
| 31 | + * @inheritDoc |
| 32 | + */ |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $this->extractorMock = $this->getMockForAbstractClass( |
| 36 | + BackpressureRequestTypeExtractorInterface::class |
| 37 | + ); |
| 38 | + |
| 39 | + $this->compositeRequestTypeExtractor = new CompositeRequestTypeExtractor( |
| 40 | + array_fill(0, 3, $this->extractorMock) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Tests CompositeRequestTypeExtractor |
| 46 | + */ |
| 47 | + public function testExtract() |
| 48 | + { |
| 49 | + $this->extractorMock->expects($this->exactly(2)) |
| 50 | + ->method('extract') |
| 51 | + ->with('someService', 'someMethod', 'someEndpoint') |
| 52 | + ->willReturnOnConsecutiveCalls(null, 'someType'); |
| 53 | + |
| 54 | + $this->assertEquals( |
| 55 | + 'someType', |
| 56 | + $this->compositeRequestTypeExtractor->extract( |
| 57 | + 'someService', |
| 58 | + 'someMethod', |
| 59 | + 'someEndpoint' |
| 60 | + ) |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Tests CompositeRequestTypeExtractor when type |
| 66 | + */ |
| 67 | + public function testExtractTypeNotFound() |
| 68 | + { |
| 69 | + $this->extractorMock->expects($this->exactly(3)) |
| 70 | + ->method('extract') |
| 71 | + ->with('someService', 'someMethod', 'someEndpoint') |
| 72 | + ->willReturn(null); |
| 73 | + $this->assertEquals( |
| 74 | + null, |
| 75 | + $this->compositeRequestTypeExtractor->extract( |
| 76 | + 'someService', |
| 77 | + 'someMethod', |
| 78 | + 'someEndpoint' |
| 79 | + ) |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments