|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Magento\Developer\Console\Command; |
| 4 | + |
| 5 | +use Magento\Developer\Model\Di\Information; |
| 6 | +use Magento\Framework\App\AreaList; |
| 7 | +use Magento\TestFramework\Helper\Bootstrap; |
| 8 | +use PHPUnit\Framework\MockObject\MockObject; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Symfony\Component\Console\Tester\CommandTester; |
| 11 | +use Magento\Framework\ObjectManagerInterface; |
| 12 | + |
| 13 | +class DiInfoCommandTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var ObjectManagerInterface |
| 17 | + */ |
| 18 | + private ObjectManagerInterface $objectManager; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var Information|MockObject |
| 22 | + */ |
| 23 | + private Information|MockObject $informationMock; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var AreaList|MockObject |
| 27 | + */ |
| 28 | + private AreaList|MockObject $areaListMock; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var DiInfoCommand |
| 32 | + */ |
| 33 | + private DiInfoCommand $command; |
| 34 | + |
| 35 | + /** |
| 36 | + * @inheritdoc |
| 37 | + */ |
| 38 | + protected function setUp(): void |
| 39 | + { |
| 40 | + $this->objectManager = Bootstrap::getObjectManager(); |
| 41 | + $this->informationMock = $this->createMock(Information::class); |
| 42 | + $this->areaListMock = $this->createMock(AreaList::class); |
| 43 | + $this->command = new DiInfoCommand($this->informationMock, $this->objectManager, $this->areaListMock); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @return void |
| 48 | + */ |
| 49 | + public function testExecuteWithGlobalArea(): void |
| 50 | + { |
| 51 | + $this->informationMock->expects($this->any()) |
| 52 | + ->method('getPreference') |
| 53 | + ->with('Magento\Framework\App\RouterList') |
| 54 | + ->willReturn('Magento\Framework\App\RouterList'); |
| 55 | + |
| 56 | + $this->informationMock->expects($this->any()) |
| 57 | + ->method('getParameters') |
| 58 | + ->with('Magento\Framework\App\RouterList') |
| 59 | + ->willReturn([ |
| 60 | + ['objectManager', 'Magento\Framework\ObjectManagerInterface', null], |
| 61 | + ['routerList', null, null] |
| 62 | + ]); |
| 63 | + |
| 64 | + $this->informationMock->expects($this->once()) |
| 65 | + ->method('getVirtualTypes') |
| 66 | + ->with('Magento\Framework\App\RouterList') |
| 67 | + ->willReturn([]); |
| 68 | + |
| 69 | + $this->informationMock->expects($this->any()) |
| 70 | + ->method('getPlugins') |
| 71 | + ->with('Magento\Framework\App\RouterList') |
| 72 | + ->willReturn([ |
| 73 | + 'before' => [], |
| 74 | + 'around' => [], |
| 75 | + 'after' => [] |
| 76 | + ]); |
| 77 | + |
| 78 | + $commandTester = new CommandTester($this->command); |
| 79 | + $commandTester->execute( |
| 80 | + [ |
| 81 | + DiInfoCommand::CLASS_NAME => "Magento\Framework\App\RouterList", |
| 82 | + DiInfoCommand::AREA_CODE => null |
| 83 | + ], |
| 84 | + ); |
| 85 | + $this->assertStringContainsString( |
| 86 | + 'DI configuration for the class Magento\Framework\App\RouterList in the GLOBAL area', |
| 87 | + $commandTester->getDisplay() |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @return void |
| 93 | + */ |
| 94 | + public function testExecuteWithAreaCode(): void |
| 95 | + { |
| 96 | + $className = "Magento\Framework\App\RouterList"; |
| 97 | + $this->informationMock->expects($this->any()) |
| 98 | + ->method('getPreference') |
| 99 | + ->with($className) |
| 100 | + ->willReturn($className); |
| 101 | + |
| 102 | + $this->informationMock->expects($this->any()) |
| 103 | + ->method('getParameters') |
| 104 | + ->with($className) |
| 105 | + ->willReturn([ |
| 106 | + ['objectManager', 'Magento\Framework\ObjectManagerInterface', null], |
| 107 | + ['routerList', null, null] |
| 108 | + ]); |
| 109 | + |
| 110 | + $this->informationMock->expects($this->once()) |
| 111 | + ->method('getVirtualTypes') |
| 112 | + ->with($className) |
| 113 | + ->willReturn([]); |
| 114 | + |
| 115 | + $this->informationMock->expects($this->any()) |
| 116 | + ->method('getPlugins') |
| 117 | + ->with($className) |
| 118 | + ->willReturn([ |
| 119 | + 'before' => [], |
| 120 | + 'around' => [], |
| 121 | + 'after' => [] |
| 122 | + ]); |
| 123 | + |
| 124 | + $this->areaListMock->expects($this->once()) |
| 125 | + ->method('getCodes') |
| 126 | + ->willReturn(['frontend', 'adminhtml']); |
| 127 | + |
| 128 | + $commandTester = new CommandTester($this->command); |
| 129 | + $commandTester->execute( |
| 130 | + [ |
| 131 | + DiInfoCommand::CLASS_NAME => "$className", |
| 132 | + DiInfoCommand::AREA_CODE => "adminhtml" |
| 133 | + ], |
| 134 | + ); |
| 135 | + |
| 136 | + $this->assertStringContainsString( |
| 137 | + "DI configuration for the class $className in the ADMINHTML area", |
| 138 | + $commandTester->getDisplay() |
| 139 | + ); |
| 140 | + } |
| 141 | +} |
0 commit comments