|
| 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\Interception; |
| 9 | + |
| 10 | +use Magento\Framework\App\Filesystem\DirectoryList; |
| 11 | +use Magento\Framework\Filesystem\DriverInterface; |
| 12 | +use Magento\TestFramework\Application; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | + |
| 15 | +class PluginListGeneratorMultipleScopesTest extends \PHPUnit\Framework\TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * Generated plugin list configs for frontend, adminhtml, graphql scopes |
| 19 | + */ |
| 20 | + private $cacheIds = [ |
| 21 | + 'primary|global|frontend|plugin-list', |
| 22 | + 'primary|global|adminhtml|plugin-list', |
| 23 | + 'primary|global|graphql|plugin-list' |
| 24 | + ]; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var PluginListGenerator |
| 28 | + */ |
| 29 | + private $model; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var DirectoryList |
| 33 | + */ |
| 34 | + private $directoryList; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var DriverInterface |
| 38 | + */ |
| 39 | + private $file; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var Application |
| 43 | + */ |
| 44 | + private $application; |
| 45 | + |
| 46 | + /** |
| 47 | + * @inheritDoc |
| 48 | + */ |
| 49 | + protected function setUp(): void |
| 50 | + { |
| 51 | + $this->application = Bootstrap::getInstance()->getBootstrap()->getApplication(); |
| 52 | + $this->directoryList = new DirectoryList(BP, $this->getCustomDirs()); |
| 53 | + $this->file = Bootstrap::getObjectManager()->create(DriverInterface::class); |
| 54 | + $reader = Bootstrap::getObjectManager()->create( |
| 55 | + // phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found." |
| 56 | + \Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class |
| 57 | + ); |
| 58 | + $scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class); |
| 59 | + $omConfig = Bootstrap::getObjectManager()->create( |
| 60 | + \Magento\Framework\Interception\ObjectManager\Config\Developer::class |
| 61 | + ); |
| 62 | + $relations = Bootstrap::getObjectManager()->create( |
| 63 | + \Magento\Framework\ObjectManager\Relations\Runtime::class |
| 64 | + ); |
| 65 | + $definitions = Bootstrap::getObjectManager()->create( |
| 66 | + \Magento\Framework\Interception\Definition\Runtime::class |
| 67 | + ); |
| 68 | + $classDefinitions = Bootstrap::getObjectManager()->create( |
| 69 | + \Magento\Framework\ObjectManager\Definition\Runtime::class |
| 70 | + ); |
| 71 | + // phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found." |
| 72 | + $logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class); |
| 73 | + $this->model = new PluginListGenerator( |
| 74 | + $reader, |
| 75 | + $scopeConfig, |
| 76 | + $omConfig, |
| 77 | + $relations, |
| 78 | + $definitions, |
| 79 | + $classDefinitions, |
| 80 | + $logger, |
| 81 | + $this->directoryList, |
| 82 | + ['primary', 'global'] |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Test multiple scopes plugin list configuration generation and load. |
| 88 | + */ |
| 89 | + public function testPluginListMultipleScopesConfigGeneration() |
| 90 | + { |
| 91 | + $scopes = ['frontend', 'adminhtml', 'graphql']; |
| 92 | + $this->model->write($scopes); |
| 93 | + |
| 94 | + foreach ($this->cacheIds as $cacheId) { |
| 95 | + $configData = $this->model->load($cacheId); |
| 96 | + $this->assertNotEmpty($configData[0]); |
| 97 | + $this->assertNotEmpty($configData[1]); |
| 98 | + $this->assertNotEmpty($configData[2]); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Gets customized directory paths |
| 104 | + * |
| 105 | + * @return array |
| 106 | + */ |
| 107 | + private function getCustomDirs() |
| 108 | + { |
| 109 | + $path = DirectoryList::PATH; |
| 110 | + $generated = "{$this->application->getTempDir()}/generated"; |
| 111 | + |
| 112 | + return [ |
| 113 | + DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"], |
| 114 | + ]; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * @inheritDoc |
| 119 | + */ |
| 120 | + protected function tearDown(): void |
| 121 | + { |
| 122 | + foreach ($this->cacheIds as $cacheId) { |
| 123 | + $filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA) |
| 124 | + . '/' . $cacheId . '.' . 'php'; |
| 125 | + |
| 126 | + if (file_exists($filePath)) { |
| 127 | + $this->file->deleteFile($filePath); |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | +} |
0 commit comments