Skip to content

Commit

Permalink
Rename ModuleSourceList as ModuleSourceAggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
Quetzacoalt91 committed Aug 28, 2024
1 parent 8d401aa commit 84eea40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -32,7 +32,10 @@ public function setSourcesIn(ModuleDownloaderContext $moduleContext): void
$moduleContext->getReferenceVersion()
));
}
$moduleContext->setUpdateSources($this->orderSources($updateSources));

$moduleContext->setUpdateSources(
$this->orderSources($updateSources)
);
}

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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());
}
}

0 comments on commit 84eea40

Please sign in to comment.