-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source; | ||
|
||
class ModuleSource | ||
{ | ||
/** var string */ | ||
private $name; | ||
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.8)
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.4.4)
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.3.4)
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.6)
Check failure on line 8 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (latest)
|
||
|
||
/** var string */ | ||
private $newVersion; | ||
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.8)
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.4.4)
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.3.4)
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.2.5)
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (1.7.6)
Check failure on line 11 in classes/UpgradeTools/Module/Source/ModuleSource.php GitHub Actions / PHPStan (latest)
|
||
|
||
/** var string */ | ||
private $path; | ||
|
||
/** var bool */ | ||
private $unzipable; | ||
|
||
public function __construct(string $name, string $newVersion, string $path, bool $unzipable) | ||
{ | ||
$this->name = $name; | ||
$this->newVersion = $newVersion; | ||
$this->path = $path; | ||
$this->unzipable = $unzipable; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getNewVersion(): string | ||
{ | ||
return $this->newVersion; | ||
} | ||
|
||
public function getPath(): string | ||
{ | ||
return $this->path; | ||
} | ||
|
||
public function isUnzipable(): bool | ||
{ | ||
return $this->unzipable; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'newVersion' => $this->newVersion, | ||
'path' => $this->path, | ||
'unzipable' => $this->unzipable, | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\ModuleDownloaderContext; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\Provider\ModuleSourceProviderInterface; | ||
|
||
class ModuleSourceList | ||
{ | ||
/** @var ModuleSourceProviderInterface[] */ | ||
private $providers; | ||
|
||
/** | ||
* @param ModuleSourceProviderInterface[] $sourceProviders | ||
*/ | ||
public function __construct(array $sourceProviders) | ||
{ | ||
$this->providers = $sourceProviders; | ||
} | ||
|
||
/** | ||
* @return ModuleSource[] | ||
*/ | ||
public function setSourcesIn(ModuleDownloaderContext $moduleContext): void | ||
{ | ||
$updateSources = []; | ||
foreach ($this->providers as $provider) { | ||
$updateSources = array_merge( | ||
$updateSources, | ||
$provider->getUpdatesOfModule( | ||
$moduleContext->getModuleName(), | ||
$moduleContext->getReferenceVersion() | ||
)); | ||
} | ||
$moduleContext->setUpdateSources($this->orderSources($updateSources)); | ||
} | ||
|
||
/** | ||
* @param ModuleSource[] | ||
* | ||
* @return ModuleSource[] | ||
*/ | ||
private function orderSources(array $sources): array | ||
{ | ||
return $sources; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\Provider; | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSource; | ||
|
||
interface ModuleSourceProviderInterface | ||
{ | ||
/** @return ModuleSource[] */ | ||
public function getUpdatesOfModule(string $moduleName, string $currentVersion): array; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
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; | ||
|
||
class ModuleSourceListTest extends TestCase | ||
{ | ||
public static function setUpBeforeClass() | ||
{ | ||
require_once __DIR__ . '/Provider/ModuleSourceProviderMock.php'; | ||
} | ||
|
||
public function testUpdateSourcesAreSet() | ||
{ | ||
$dummyProvider1 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('Module1', '3.0.0', __DIR__, false), | ||
]); | ||
$dummyProvider2 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('Module1', '2.0.0', __DIR__.'.zip', true), | ||
]); | ||
$moduleSourceList = new ModuleSourceList([$dummyProvider1, $dummyProvider2]); | ||
|
||
$moduleContext = new ModuleDownloaderContext('Module1', '1.0.0'); | ||
|
||
$moduleSourceList->setSourcesIn($moduleContext); | ||
|
||
$results = $moduleContext->getUpdateSources(); | ||
|
||
$this->assertSame(2, count($results)); | ||
$this->assertEquals(['name' => 'Module1', 'newVersion' => '3.0.0', 'path' => __DIR__, 'unzipable' => false], $results[0]->toArray()); | ||
$this->assertEquals(['name' => 'Module1', 'newVersion' => '2.0.0', 'path' => __DIR__.'.zip', 'unzipable' => true], $results[1]->toArray()); | ||
} | ||
|
||
public function testUpdateSourcesAreOrderedByVersion() | ||
{ | ||
$dummyProvider1 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('Module1', '2.0.0', __DIR__ . '/1', false), | ||
new ModuleSource('Module1', '4.0.0', __DIR__ . '/2', false), | ||
]); | ||
$dummyProvider2 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('Module1', '3.0.0', __DIR__.'.zip', true), | ||
]); | ||
$moduleSourceList = new ModuleSourceList([$dummyProvider1, $dummyProvider2]); | ||
|
||
$moduleContext = new ModuleDownloaderContext('Module1', '1.0.0'); | ||
|
||
$moduleSourceList->setSourcesIn($moduleContext); | ||
|
||
$results = $moduleContext->getUpdateSources(); | ||
|
||
$this->assertSame(3, count($results)); | ||
$this->assertEquals(['name' => 'Module1', 'newVersion' => '4.0.0', 'path' => __DIR__ .'/2', 'unzipable' => false], $results[0]->toArray()); | ||
$this->assertEquals(['name' => 'Module1', 'newVersion' => '3.0.0', 'path' => __DIR__.'.zip', 'unzipable' => true], $results[1]->toArray()); | ||
$this->assertEquals(['name' => 'Module1', 'newVersion' => '2.0.0', 'path' => __DIR__.'/1', 'unzipable' => false], $results[2]->toArray()); | ||
} | ||
|
||
public function testUpdateSourcesAreOrderedByProviderPriority() | ||
{ | ||
// TODO | ||
} | ||
|
||
public function testUpdateSourcesAreFilteredIfNewVersionIsLower() | ||
{ | ||
// TODO | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSource; | ||
|
||
class ModuleSourceTest extends TestCase | ||
{ | ||
public function testClassIsProperlyCreated() | ||
{ | ||
$moduleName = 'TheModule'; | ||
$newVersion = '9.8.7'; | ||
$path = '/somewhere/only/we/know.zip'; | ||
$unzipable = true; | ||
|
||
$source = new ModuleSource($moduleName, $newVersion, $path, $unzipable); | ||
|
||
$this->assertSame('TheModule', $source->getName()); | ||
$this->assertSame('9.8.7', $source->getNewVersion()); | ||
$this->assertSame('/somewhere/only/we/know.zip', $source->getPath()); | ||
$this->assertSame(true, $source->isUnzipable()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\Provider\ModuleSourceProviderInterface; | ||
|
||
class ModuleSourceProviderMock implements ModuleSourceProviderInterface | ||
{ | ||
private $sources; | ||
|
||
/** @inheritdoc */ | ||
public function getUpdatesOfModule(string $moduleName, string $currentVersion): array | ||
{ | ||
return $this->sources; | ||
} | ||
|
||
/** @return ModuleSources[] */ | ||
public function setSources($sources): self | ||
{ | ||
$this->sources = $sources; | ||
return $this; | ||
} | ||
} |