Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/Extensions/Shopware/Plugin/Services/DependencyManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function manageShopware6Dependencies(string $pathToPlugin): void
}

// Temporary remove shopware dependencies
foreach (\array_keys($shopwareDependencies) as $dependencyName) {
foreach ($this->getTheRightRemovingOrder(\array_keys($shopwareDependencies)) as $dependencyName) {
$this->processExecutor->execute(\sprintf('composer remove %s --update-no-dev', $dependencyName), $pathToPlugin);
}

Expand All @@ -82,4 +82,20 @@ private function manageShopware6Dependencies(string $pathToPlugin): void
$this->processExecutor->execute(\sprintf('composer require %s:"%s" --no-update', $dependencyName, $version), $pathToPlugin);
}
}

private function getTheRightRemovingOrder(array $dependencies): array
{
usort($dependencies, function (string $a, string $b): int {
switch ('shopware/core') {
case $a:
return 1;
case $b:
return -1;
default:
return 0;
}
});

return $dependencies;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* (c) shopware AG <info@shopware.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shopware\Plugin\Struct\Plugin;
use ShopwareCli\Extensions\Shopware\Plugin\Services\DependencyManager;
use ShopwareCli\Services\ProcessExecutor;

class DependencyManagerTest extends TestCase
{
/**
* @var ProcessExecutor&MockObject
*/
private $processExecutor;

private $dependencyManager;

public function setUp(): void
{
$this->processExecutor = $this->createMock(ProcessExecutor::class);
$this->dependencyManager = new DependencyManager($this->processExecutor);
}

public function testManageDependenciesWithExternalDependenciesWillRemuveShopwareDependenciesInRightOrder(): void
{
$plugin = new Plugin();
$plugin->isShopware6 = true;
$callNumber = 0;

$this->processExecutor
->method('execute')
->with(static::callback(function ($command) use (&$callNumber) {
if ($callNumber == 2) {
self::assertEquals('composer remove shopware/core --update-no-dev', $command, 'Removing shopware/core should be the last command in removing the packages commands list');
}
++$callNumber;

return true;
}));
$this->dependencyManager->manageDependencies($plugin, __DIR__ . '/../../../../_fixtures/DependencyManager/RemoveShopwareDependencyOrder');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "shopware/test",
"description": "The Shopware Test",
"type": "shopware-platform-plugin",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.1",
"shopware/core": "~6.5.0",
"shopware/storefront": "~6.5.0",
"shopware/administration": "~6.5.0",
"nikic/fast-route": "^1.0",
"phpoffice/phpspreadsheet": "^1.14"
}
}