diff --git a/classes/UpgradeTools/Module/Source/ModuleSourceList.php b/classes/UpgradeTools/Module/Source/ModuleSourceAggregate.php similarity index 84% rename from classes/UpgradeTools/Module/Source/ModuleSourceList.php rename to classes/UpgradeTools/Module/Source/ModuleSourceAggregate.php index 1e8a4d375e..471a4b88b6 100644 --- a/classes/UpgradeTools/Module/Source/ModuleSourceList.php +++ b/classes/UpgradeTools/Module/Source/ModuleSourceAggregate.php @@ -5,13 +5,13 @@ use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\ModuleDownloaderContext; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\Provider\ModuleSourceProviderInterface; -class ModuleSourceList +class ModuleSourceAggregate { /** @var ModuleSourceProviderInterface[] */ private $providers; /** - * @param ModuleSourceProviderInterface[] $sourceProviders + * @param ModuleSourceProviderInterface[] $sourceProviders Ordered by priority (first provider has top priority) */ public function __construct(array $sourceProviders) { @@ -32,7 +32,10 @@ public function setSourcesIn(ModuleDownloaderContext $moduleContext): void $moduleContext->getReferenceVersion() )); } - $moduleContext->setUpdateSources($this->orderSources($updateSources)); + + $moduleContext->setUpdateSources( + $this->orderSources($updateSources) + ); } /** @@ -44,8 +47,6 @@ private function orderSources(array $sources): array { usort($sources, function (ModuleSource $source1, ModuleSource $source2) { return version_compare($source2->getNewVersion(), $source1->getNewVersion()); - - // TODO: Add provider priority check when versions are the same }); return $sources; diff --git a/tests/unit/UpgradeTools/Module/Source/ModuleSourceListTest.php b/tests/unit/UpgradeTools/Module/Source/ModuleSourceAggregateTest.php similarity index 65% rename from tests/unit/UpgradeTools/Module/Source/ModuleSourceListTest.php rename to tests/unit/UpgradeTools/Module/Source/ModuleSourceAggregateTest.php index 07afe1fe90..2cd23d374b 100644 --- a/tests/unit/UpgradeTools/Module/Source/ModuleSourceListTest.php +++ b/tests/unit/UpgradeTools/Module/Source/ModuleSourceAggregateTest.php @@ -27,9 +27,9 @@ use PHPUnit\Framework\TestCase; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\ModuleDownloaderContext; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSource; -use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSourceList; +use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSourceAggregate; -class ModuleSourceListTest extends TestCase +class ModuleSourceAggregateTest extends TestCase { public static function setUpBeforeClass() { @@ -44,7 +44,7 @@ public function testUpdateSourcesAreSet() $dummyProvider2 = (new ModuleSourceProviderMock())->setSources([ new ModuleSource('Module1', '2.0.0', __DIR__ . '.zip', true), ]); - $moduleSourceList = new ModuleSourceList([$dummyProvider1, $dummyProvider2]); + $moduleSourceList = new ModuleSourceAggregate([$dummyProvider1, $dummyProvider2]); $moduleContext = new ModuleDownloaderContext('Module1', '1.0.0'); @@ -66,7 +66,7 @@ public function testUpdateSourcesAreOrderedByVersion() $dummyProvider2 = (new ModuleSourceProviderMock())->setSources([ new ModuleSource('Module1', '3.0.0', __DIR__ . '.zip', true), ]); - $moduleSourceList = new ModuleSourceList([$dummyProvider1, $dummyProvider2]); + $moduleSourceList = new ModuleSourceAggregate([$dummyProvider1, $dummyProvider2]); $moduleContext = new ModuleDownloaderContext('Module1', '1.0.0'); @@ -82,11 +82,28 @@ public function testUpdateSourcesAreOrderedByVersion() public function testUpdateSourcesAreOrderedByProviderPriority() { - // TODO - } + $dummyProvider1 = (new ModuleSourceProviderMock())->setSources([ + new ModuleSource('Module1', '2.0.0', __DIR__ . '/1/2.0.0', false), + new ModuleSource('Module1', '4.0.0', __DIR__ . '/1/4.0.0', false), + ]); + $dummyProvider2 = (new ModuleSourceProviderMock())->setSources([ + new ModuleSource('Module1', '3.0.0', __DIR__ . '/2/3.0.0', false), + new ModuleSource('Module1', '4.0.0', __DIR__ . '/2/4.0.0', false), + new ModuleSource('Module1', '2.0.0', __DIR__ . '/2/2.0.0', false), + ]); + $moduleSourceList = new ModuleSourceAggregate([$dummyProvider1, $dummyProvider2]); - public function testUpdateSourcesAreFilteredIfNewVersionIsLower() - { - // TODO: Will be done in unit tests of providers + $moduleContext = new ModuleDownloaderContext('Module1', '1.0.0'); + + $moduleSourceList->setSourcesIn($moduleContext); + + $results = $moduleContext->getUpdateSources(); + + $this->assertSame(5, count($results)); + $this->assertEquals(['name' => 'Module1', 'newVersion' => '4.0.0', 'path' => __DIR__ . '/1/4.0.0', 'unzipable' => false], $results[0]->toArray()); + $this->assertEquals(['name' => 'Module1', 'newVersion' => '4.0.0', 'path' => __DIR__ . '/2/4.0.0', 'unzipable' => false], $results[1]->toArray()); + $this->assertEquals(['name' => 'Module1', 'newVersion' => '3.0.0', 'path' => __DIR__ . '/2/3.0.0', 'unzipable' => false], $results[2]->toArray()); + $this->assertEquals(['name' => 'Module1', 'newVersion' => '2.0.0', 'path' => __DIR__ . '/1/2.0.0', 'unzipable' => false], $results[3]->toArray()); + $this->assertEquals(['name' => 'Module1', 'newVersion' => '2.0.0', 'path' => __DIR__ . '/2/2.0.0', 'unzipable' => false], $results[4]->toArray()); } }