/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/internal/Magento/Framework/Composer/Test/Unit/DependencyCheckerTest.php
132 строки
5 KB
Manish Ranjan
PHPUnit 12: Fix CollectionTest complex interface mocks
12 янв 2026, 11:13
12 янв 2026, 11:13
644c197
Код
Авторство
О чём код?
<?php /** * Copyright 2015 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Framework\Composer\Test\Unit; use Composer\Console\Application; use Composer\Console\ApplicationFactory; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Composer\DependencyChecker; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class DependencyCheckerTest extends TestCase { /** * @var ApplicationFactory|MockObject */ private ApplicationFactory $composerFactory; /** * @var Application|MockObject */ private Application $composerApp; protected function setUp(): void { $this->composerFactory = $this->getMockBuilder(ApplicationFactory::class) ->onlyMethods(['create']) ->disableOriginalConstructor() ->getMock(); $this->composerApp = $this->getMockBuilder(Application::class) ->onlyMethods(['setAutoExit', 'resetComposer', 'run','__destruct']) ->getMock(); $this->composerFactory->method('create')->willReturn($this->composerApp); parent::setUp(); } /** * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testCheckDependencies(): void { $directoryList = $this->createMock(DirectoryList::class); $directoryList->expects($this->exactly(2))->method('getRoot'); $this->composerApp->expects($this->once())->method('setAutoExit')->with(false); $callCount = 0; $this->composerApp ->method('run') ->willReturnCallback( function ($input, $buffer) use (&$callCount) { $callCount++; if ($callCount === 1) { $output = 'magento/package-b requires magento/package-a (1.0)' . PHP_EOL . 'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL . 'magento/package-c requires magento/package-a (1.0)' . PHP_EOL; } else { $output = 'magento/package-c requires magento/package-b (1.0)' . PHP_EOL . 'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL . 'magento/package-d requires magento/package-b (1.0)' . PHP_EOL; } $buffer->writeln($output); return 1; } ); $dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList); $expected = [ 'magento/package-a' => ['magento/package-b', 'magento/package-c'], 'magento/package-b' => ['magento/package-c', 'magento/package-d'], ]; $this->assertEquals( $expected, $dependencyChecker->checkDependencies(['magento/package-a', 'magento/package-b']) ); } /** * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testCheckDependenciesExcludeSelf(): void { $directoryList = $this->createMock(DirectoryList::class); $directoryList->expects($this->exactly(3))->method('getRoot'); $this->composerApp->expects($this->once())->method('setAutoExit')->with(false); $callCount = 0; $this->composerApp ->method('run') ->willReturnCallback( function ($input, $buffer) use (&$callCount) { $callCount++; if ($callCount === 1) { $output = 'magento/package-b requires magento/package-a (1.0)' . PHP_EOL . 'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL . 'magento/package-c requires magento/package-a (1.0)' . PHP_EOL; } elseif ($callCount === 2) { $output = 'magento/package-c requires magento/package-b (1.0)' . PHP_EOL . 'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL . 'magento/package-d requires magento/package-b (1.0)' . PHP_EOL; } else { $output = 'magento/package-d requires magento/package-c (1.0)' . PHP_EOL . 'magento/project-community-edition requires magento/package-a (1.0)' . PHP_EOL; } $buffer->writeln($output); return 1; } ); $dependencyChecker = new DependencyChecker($this->composerFactory, $directoryList); $expected = [ 'magento/package-a' => [], 'magento/package-b' => ['magento/package-d'], 'magento/package-c' => ['magento/package-d'] ]; $this->assertEquals( $expected, $dependencyChecker->checkDependencies( ['magento/package-a', 'magento/package-b', 'magento/package-c'], true ) ); } }