Skip to content
Extraits de code Groupes Projets

Comparer les révisions

Les modifications sont affichées comme si la révision source était fusionnée avec la révision cible. En savoir plus sur la comparaison des révisions.

Source

Sélectionner le projet cible
No results found

Cible

Sélectionner le projet cible
  • spip-league/composer-installer
1 résultat
Afficher les modifications
Affichage de
avec 126 ajouts et 101 suppressions
...@@ -18,27 +18,30 @@ class Security ...@@ -18,27 +18,30 @@ class Security
public static function copySafetyScreen(Event $event): void public static function copySafetyScreen(Event $event): void
{ {
$search = array_filter( $search = array_filter(
$event->getComposer()->getPackage()->getRequires(), $event->getComposer()
function (Link $link) { ->getPackage()
return $link->getTarget() === 'spip/security'; ->getRequires(),
}, fn(Link $link) => $link->getTarget() === 'spip/security',
); );
if (empty($search)) { if (empty($search)) {
$event->getIO()->warning('spip/security is not installed.'); $event->getIO()
->warning('spip/security is not installed.');
return; return;
} }
$event->getIO()->write('Updating the safety screen ...'); $event->getIO()
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir'); ->write('Updating the safety screen ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir');
try { try {
\copy( \copy($vendorDir . '/spip/security/ecran_securite.php', $vendorDir . '/../config/ecran_securite.php');
$vendorDir . '/spip/security/ecran_securite.php', $event->getIO()
$vendorDir . '/../config/ecran_securite.php', ->write('Done.');
);
$event->getIO()->write('Done.');
} catch (\Throwable $th) { } catch (\Throwable $th) {
$event->getIO()->error($th->getMessage()); $event->getIO()
->error($th->getMessage());
} }
} }
} }
...@@ -7,22 +7,20 @@ use Composer\Package\PackageInterface; ...@@ -7,22 +7,20 @@ use Composer\Package\PackageInterface;
class SpipInstaller extends LibraryInstaller class SpipInstaller extends LibraryInstaller
{ {
/**
* {@inheritDoc}
*/
public function getInstallPath(PackageInterface $package) public function getInstallPath(PackageInterface $package)
{ {
if ('spip-ecrire' === $package->getType()) { if ($package->getType() === 'spip-ecrire') {
return './' . SpipPaths::BACK_OFFICE; return './' . SpipPaths::BACK_OFFICE;
} }
if ('spip-prive' === $package->getType()) { if ($package->getType() === 'spip-prive') {
return './' . SpipPaths::PRIVATE_TEMPLATE; return './' . SpipPaths::PRIVATE_TEMPLATE;
} }
if ('spip-plugin' === $package->getType()) { if ($package->getType() === 'spip-plugin') {
/** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */ /** @var array{spip?:array{extensions?:string[],template?:string,private_template?:string,back_office?:string}} */
$extra = $this->composer->getPackage()->getExtra(); $extra = $this->composer->getPackage()
->getExtra();
$template = $extra['spip']['template'] ?? ''; $template = $extra['spip']['template'] ?? '';
$extensions = $extra['spip']['extensions'] ?? []; $extensions = $extra['spip']['extensions'] ?? [];
$name = $package->getName(); $name = $package->getName();
...@@ -38,10 +36,7 @@ class SpipInstaller extends LibraryInstaller ...@@ -38,10 +36,7 @@ class SpipInstaller extends LibraryInstaller
return './' . SpipPaths::PLUGINS . '/' . $name; return './' . SpipPaths::PLUGINS . '/' . $name;
} }
if (in_array($package->getType(), [ if (in_array($package->getType(), ['spip-lang', 'spip-theme'])) {
'spip-lang',
'spip-theme',
])) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'Unable to install this package as its type is not supported for now.' . 'Unable to install this package as its type is not supported for now.' .
' Wait for a future SPIP version for using it.', ' Wait for a future SPIP version for using it.',
...@@ -51,9 +46,6 @@ class SpipInstaller extends LibraryInstaller ...@@ -51,9 +46,6 @@ class SpipInstaller extends LibraryInstaller
return parent::getInstallPath($package); return parent::getInstallPath($package);
} }
/**
* {@inheritDoc}
*/
public function supports(string $packageType) public function supports(string $packageType)
{ {
return in_array($packageType, [ return in_array($packageType, [
......
...@@ -17,16 +17,13 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface, ...@@ -17,16 +17,13 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function activate(Composer $composer, IOInterface $io) public function activate(Composer $composer, IOInterface $io)
{ {
$installer = new SpipInstaller($io, $composer); $installer = new SpipInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer); $composer->getInstallationManager()
->addInstaller($installer);
} }
public function deactivate(Composer $composer, IOInterface $io) public function deactivate(Composer $composer, IOInterface $io) {}
{
}
public function uninstall(Composer $composer, IOInterface $io) public function uninstall(Composer $composer, IOInterface $io) {}
{
}
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
...@@ -82,7 +79,7 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface, ...@@ -82,7 +79,7 @@ class SpipInstallerPlugin implements PluginInterface, EventSubscriberInterface,
public function getCapabilities() public function getCapabilities()
{ {
return [ return [
'Composer\Plugin\Capability\CommandProvider' => 'SpipLeague\Composer\CommandProvider', \Composer\Plugin\Capability\CommandProvider::class => \SpipLeague\Composer\CommandProvider::class,
]; ];
} }
} }
...@@ -5,24 +5,37 @@ namespace SpipLeague\Composer; ...@@ -5,24 +5,37 @@ namespace SpipLeague\Composer;
class SpipPaths class SpipPaths
{ {
public const CHMOD = 0777; public const CHMOD = 0777;
public const UMASK = 0000; public const UMASK = 0000;
public const PLUGINS = 'plugins'; public const PLUGINS = 'plugins';
public const EXTENSIONS = 'plugins-dist'; public const EXTENSIONS = 'plugins-dist';
public const TEMPLATE = 'squelettes-dist'; public const TEMPLATE = 'squelettes-dist';
public const PRIVATE_TEMPLATE = 'prive'; public const PRIVATE_TEMPLATE = 'prive';
public const BACK_OFFICE = 'ecrire'; public const BACK_OFFICE = 'ecrire';
public const TMP = 'tmp'; public const TMP = 'tmp';
public const ETC = 'config'; public const ETC = 'config';
public const VAR = 'local'; public const VAR = 'local';
public const DOC = 'IMG'; public const DOC = 'IMG';
public const LOCAL_COMPOSER = 'composer.local.json'; public const LOCAL_COMPOSER = 'composer.local.json';
public const LOCAL_PLUGINS_DIST = 'plugins-dist.json'; public const LOCAL_PLUGINS_DIST = 'plugins-dist.json';
public const DIR_CACHE = '%spip.dirs.tmp%/cache'; public const DIR_CACHE = '%spip.dirs.tmp%/cache';
public const DIR_LOG = '%spip.dirs.tmp%/log'; public const DIR_LOG = '%spip.dirs.tmp%/log';
public const DIR_ASSETS_CSS = '%spip.dirs.var%/cache-css'; public const DIR_ASSETS_CSS = '%spip.dirs.var%/cache-css';
public const DIR_ASSETS_JS = '%spip.dirs.var%/cache-js'; public const DIR_ASSETS_JS = '%spip.dirs.var%/cache-js';
public const WHEELS_CACHE = '%spip.dirs.cache%/wheels'; public const WHEELS_CACHE = '%spip.dirs.cache%/wheels';
......
...@@ -17,18 +17,18 @@ use SpipLeague\Composer\Switch\Operation\RemoveSpecification; ...@@ -17,18 +17,18 @@ use SpipLeague\Composer\Switch\Operation\RemoveSpecification;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/ */
class Analyzer class Analyzer
{ {
private Filesystem $filesystem; private Filesystem $filesystem;
private CollectionInterface $distribution; private CollectionInterface $distribution;
private Composer $composer; private Composer $composer;
public function __construct( public function __construct(
CollectionInterface $distribution, CollectionInterface $distribution,
Composer $composer Composer $composer,
) { ) {
$this->distribution = $distribution; $this->distribution = $distribution;
$this->composer = $composer; $this->composer = $composer;
...@@ -42,7 +42,8 @@ class Analyzer ...@@ -42,7 +42,8 @@ class Analyzer
{ {
$extensions = []; $extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */ /** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $this->composer->getPackage()->getExtra(); $extra = $this->composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) { if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions']; $extensions = $extra['spip']['extensions'];
} }
...@@ -75,7 +76,8 @@ class Analyzer ...@@ -75,7 +76,8 @@ class Analyzer
public function back(): \Generator public function back(): \Generator
{ {
$extensions = $this->getExtensions(); $extensions = $this->getExtensions();
$requires = $this->composer->getPackage()->getRequires(); $requires = $this->composer->getPackage()
->getRequires();
$vendorNames = \array_keys($requires); $vendorNames = \array_keys($requires);
$vendorDirs = []; $vendorDirs = [];
......
...@@ -8,6 +8,7 @@ use SpipLeague\Composer\Extensions\CollectionInterface; ...@@ -8,6 +8,7 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
class AddToRequire implements OperationInterface class AddToRequire implements OperationInterface
{ {
private string $vendorName; private string $vendorName;
private string $constraint; private string $constraint;
public function __construct(string $vendorName, string $constraint) public function __construct(string $vendorName, string $constraint)
...@@ -33,8 +34,6 @@ class AddToRequire implements OperationInterface ...@@ -33,8 +34,6 @@ class AddToRequire implements OperationInterface
} }
/** /**
* {@inheritDoc}
*
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
public function mark(CollectionInterface $distribution, Composer $composer): ?self public function mark(CollectionInterface $distribution, Composer $composer): ?self
...@@ -44,7 +43,9 @@ class AddToRequire implements OperationInterface ...@@ -44,7 +43,9 @@ class AddToRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string public function do(CollectionInterface $distribution, Composer $composer): string
{ {
$composer->getConfig()->getConfigSource()->addLink('require', $this->vendorName, $this->constraint); $composer->getConfig()
->getConfigSource()
->addLink('require', $this->vendorName, $this->constraint);
return 'require ' . $this->vendorName . ':' . $this->constraint . ' added.'; return 'require ' . $this->vendorName . ':' . $this->constraint . ' added.';
} }
......
...@@ -34,7 +34,8 @@ class AddToSpipExtraExtensions implements OperationInterface ...@@ -34,7 +34,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{ {
$extensions = []; $extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */ /** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra(); $extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) { if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions']; $extensions = $extra['spip']['extensions'];
} }
...@@ -46,7 +47,8 @@ class AddToSpipExtraExtensions implements OperationInterface ...@@ -46,7 +47,8 @@ class AddToSpipExtraExtensions implements OperationInterface
{ {
$extensions = []; $extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */ /** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra(); $extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) { if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions']; $extensions = $extra['spip']['extensions'];
} }
...@@ -55,7 +57,9 @@ class AddToSpipExtraExtensions implements OperationInterface ...@@ -55,7 +57,9 @@ class AddToSpipExtraExtensions implements OperationInterface
} }
$extensions[] = $this->vendorName; $extensions[] = $this->vendorName;
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', $extensions); $composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', $extensions);
return 'extensions ' . $this->vendorName . ' added'; return 'extensions ' . $this->vendorName . ' added';
} }
......
...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface; ...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <jamees@rezo.net>
*/ */
interface OperationInterface interface OperationInterface
{ {
......
...@@ -8,13 +8,13 @@ use SpipLeague\Composer\Extensions\CollectionInterface; ...@@ -8,13 +8,13 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/ */
class RemoveDirectory implements OperationInterface class RemoveDirectory implements OperationInterface
{ {
private Filesystem $filesystem; private Filesystem $filesystem;
private string $directory; private string $directory;
private bool $ifEmpty; private bool $ifEmpty;
public function __construct(Filesystem $filesystem, string $directory, bool $ifEmpty = false) public function __construct(Filesystem $filesystem, string $directory, bool $ifEmpty = false)
......
...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface; ...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/ */
class RemoveFromRequire implements OperationInterface class RemoveFromRequire implements OperationInterface
{ {
...@@ -42,7 +40,9 @@ class RemoveFromRequire implements OperationInterface ...@@ -42,7 +40,9 @@ class RemoveFromRequire implements OperationInterface
public function do(CollectionInterface $distribution, Composer $composer): string public function do(CollectionInterface $distribution, Composer $composer): string
{ {
$composer->getConfig()->getConfigSource()->removeLink('require', $this->vendorName); $composer->getConfig()
->getConfigSource()
->removeLink('require', $this->vendorName);
return 'require ' . $this->vendorName . ' removed'; return 'require ' . $this->vendorName . ' removed';
} }
......
...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface; ...@@ -7,8 +7,6 @@ use SpipLeague\Composer\Extensions\CollectionInterface;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/ */
class RemoveFromSpipExtraExtensions implements OperationInterface class RemoveFromSpipExtraExtensions implements OperationInterface
{ {
...@@ -39,7 +37,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface ...@@ -39,7 +37,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{ {
$extensions = []; $extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */ /** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra(); $extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) { if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions']; $extensions = $extra['spip']['extensions'];
} }
...@@ -51,7 +50,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface ...@@ -51,7 +50,8 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
{ {
$extensions = []; $extensions = [];
/** @var array{spip?:array{extensions?:mixed}} $extra */ /** @var array{spip?:array{extensions?:mixed}} $extra */
$extra = $composer->getPackage()->getExtra(); $extra = $composer->getPackage()
->getExtra();
if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) { if (isset($extra['spip']['extensions']) && \is_array($extra['spip']['extensions'])) {
$extensions = $extra['spip']['extensions']; $extensions = $extra['spip']['extensions'];
} }
...@@ -59,7 +59,9 @@ class RemoveFromSpipExtraExtensions implements OperationInterface ...@@ -59,7 +59,9 @@ class RemoveFromSpipExtraExtensions implements OperationInterface
return 'nothing to do'; return 'nothing to do';
} }
$composer->getConfig()->getConfigSource()->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName])); $composer->getConfig()
->getConfigSource()
->addProperty('extra.spip.extensions', \array_diff($extensions, [$this->vendorName]));
return 'extensions ' . $this->vendorName . ' removed'; return 'extensions ' . $this->vendorName . ' removed';
} }
......
...@@ -22,7 +22,6 @@ class RemoveSpecification implements OperationInterface ...@@ -22,7 +22,6 @@ class RemoveSpecification implements OperationInterface
return 'RemoveSpecification ' . $this->prefix; return 'RemoveSpecification ' . $this->prefix;
} }
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
......
...@@ -8,15 +8,16 @@ use SpipLeague\Composer\Switch\Operation\OperationInterface; ...@@ -8,15 +8,16 @@ use SpipLeague\Composer\Switch\Operation\OperationInterface;
/** /**
* @since 0.7.0 * @since 0.7.0
*
* @author JamesRezo <james@rezo.net>
*/ */
class Switcher class Switcher
{ {
private CollectionInterface $distribution; private CollectionInterface $distribution;
private Composer $composer; private Composer $composer;
/** @var array<string,OperationInterface[]> */ /**
* @var array<string,OperationInterface[]>
*/
private array $operations = [ private array $operations = [
'distribution' => [], 'distribution' => [],
'extensions' => [], 'extensions' => [],
...@@ -33,7 +34,7 @@ class Switcher ...@@ -33,7 +34,7 @@ class Switcher
public function to(OperationInterface $operation): void public function to(OperationInterface $operation): void
{ {
$operation = $operation->mark($this->distribution, $this->composer); $operation = $operation->mark($this->distribution, $this->composer);
if (!\is_null($operation)) { if ($operation !== null) {
$this->operations[$operation->getType()][] = $operation; $this->operations[$operation->getType()][] = $operation;
} }
} }
......
...@@ -10,16 +10,22 @@ class WheelsClearCache ...@@ -10,16 +10,22 @@ class WheelsClearCache
{ {
public static function clearCache(Event $event): void public static function clearCache(Event $event): void
{ {
$event->getIO()->write('Clearing the Textwheel cache ...'); $event->getIO()
$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir') . '/'; ->write('Clearing the Textwheel cache ...');
$vendorDir = $event->getComposer()
->getConfig()
->get('vendor-dir') . '/';
$fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor()); $fs = new Filesystem($event->getComposer()->getLoop()->getProcessExecutor());
$sffs = new SymfonyFilesystem; $sffs = new SymfonyFilesystem();
$fs->emptyDirectory( $fs->emptyDirectory($vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE));
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE) $sffs->chmod(
$vendorDir . '../' . SpipPaths::interpolate(SpipPaths::WHEELS_CACHE),
SpipPaths::CHMOD,
SpipPaths::UMASK,
); );
$sffs->chmod($vendorDir . '../' .SpipPaths::interpolate(SpipPaths::WHEELS_CACHE), SpipPaths::CHMOD, SpipPaths::UMASK);
$event->getIO()->write('Done.'); $event->getIO()
->write('Done.');
} }
} }
...@@ -44,19 +44,20 @@ class PreferredInstallTest extends TestCase ...@@ -44,19 +44,20 @@ class PreferredInstallTest extends TestCase
], ],
'preferred' => ['spip/*' => 'source'], 'preferred' => ['spip/*' => 'source'],
'requires' => [ 'requires' => [
'mandatory' => new Link('mandatory', 'spip/mandatory', new Constraint('=', '*')), 'mandatory' => new Link('mandatory', 'spip/mandatory', new Constraint('=', '*')),
'template' => new Link('template', 'spip/default-template', new Constraint('=', '*')), 'template' => new Link('template', 'spip/default-template', new Constraint('=', '*')),
'package' => new Link('package', 'spip/package', new Constraint('=', '*')), 'package' => new Link('package', 'spip/package', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')), 'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
'private-template' => new Link('private-template', 'spip/private-template', new Constraint('=', '*')), 'private-template' => new Link('private-template', 'spip/private-template', new Constraint(
'back-office' => new Link('back-office', 'spip/back-office', new Constraint('=', '*')), '=',
'*',
)),
'back-office' => new Link('back-office', 'spip/back-office', new Constraint('=', '*')),
], ],
'extra' => [ 'extra' => [
'spip' => [ 'spip' => [
'template' => 'spip/default-template', 'template' => 'spip/default-template',
'extensions' => [ 'extensions' => ['spip/mandatory'],
'spip/mandatory',
],
'private_template' => 'spip/private-template', 'private_template' => 'spip/private-template',
'back_office' => 'spip/back-office', 'back_office' => 'spip/back-office',
], ],
...@@ -75,16 +76,14 @@ class PreferredInstallTest extends TestCase ...@@ -75,16 +76,14 @@ class PreferredInstallTest extends TestCase
], ],
'preferred' => ['one/*' => 'source', 'two/*' => 'source'], 'preferred' => ['one/*' => 'source', 'two/*' => 'source'],
'requires' => [ 'requires' => [
'mandatory1' => new Link('mandatory', 'one/mandatory1', new Constraint('=', '*')), 'mandatory1' => new Link('mandatory', 'one/mandatory1', new Constraint('=', '*')),
'template2' => new Link('template', 'two/template2', new Constraint('=', '*')), 'template2' => new Link('template', 'two/template2', new Constraint('=', '*')),
'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')), 'other-package' => new Link('other-package', 'other/package', new Constraint('=', '*')),
], ],
'extra' => [ 'extra' => [
'spip' => [ 'spip' => [
'template' => 'two/template2', 'template' => 'two/template2',
'extensions' => [ 'extensions' => ['one/mandatory1'],
'one/mandatory1',
],
], ],
], ],
], ],
......
...@@ -19,7 +19,9 @@ use SpipLeague\Test\Composer\Fixtures\SpecificationStub; ...@@ -19,7 +19,9 @@ use SpipLeague\Test\Composer\Fixtures\SpecificationStub;
class CollectionTest extends TestCase class CollectionTest extends TestCase
{ {
private SpecificationStub $validStub; private SpecificationStub $validStub;
private Collection $testCollection; private Collection $testCollection;
private RemoteUrls $changer; private RemoteUrls $changer;
protected function setUp(): void protected function setUp(): void
...@@ -42,7 +44,6 @@ class CollectionTest extends TestCase ...@@ -42,7 +44,6 @@ class CollectionTest extends TestCase
// An exception is thrown // An exception is thrown
} }
public function testInvalidSpecificationByArrayAccess() public function testInvalidSpecificationByArrayAccess()
{ {
// Given // Given
...@@ -140,7 +141,10 @@ class CollectionTest extends TestCase ...@@ -140,7 +141,10 @@ class CollectionTest extends TestCase
$actual = \json_encode($this->testCollection); $actual = \json_encode($this->testCollection);
// Then // Then
$this->assertSame('{"valid":{"path":"path","source":"source"},"test":{"path":"path","source":"source"}}', $actual); $this->assertSame(
'{"valid":{"path":"path","source":"source"},"test":{"path":"path","source":"source"}}',
$actual,
);
} }
public static function dataFromJsonFile() public static function dataFromJsonFile()
...@@ -186,7 +190,7 @@ class CollectionTest extends TestCase ...@@ -186,7 +190,7 @@ class CollectionTest extends TestCase
$this->expectExceptionMessageMatches(',Fixtures/malformed.json" malformed,'); $this->expectExceptionMessageMatches(',Fixtures/malformed.json" malformed,');
// When // When
Collection::fromJsonFile($this->changer, __DIR__ . '/../Fixtures/malformed.json'); Collection::fromJsonFile($this->changer, __DIR__ . '/../Fixtures/malformed.json');
// Then // Then
// An exception is thrown // An exception is thrown
......
...@@ -3,12 +3,9 @@ ...@@ -3,12 +3,9 @@
namespace SpipLeague\Test\Composer\Extensions; namespace SpipLeague\Test\Composer\Extensions;
use Composer\Composer; use Composer\Composer;
use Composer\Config;
use Composer\Factory as ComposerFactory; use Composer\Factory as ComposerFactory;
use Composer\IO\NullIO; use Composer\IO\NullIO;
use Composer\Package\Link;
use Composer\Package\RootPackage; use Composer\Package\RootPackage;
use Composer\Semver\Constraint\Constraint;
use Composer\Util\Platform; use Composer\Util\Platform;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProvider;
...@@ -16,7 +13,6 @@ use PHPUnit\Framework\TestCase; ...@@ -16,7 +13,6 @@ use PHPUnit\Framework\TestCase;
use SpipLeague\Composer\Extensions\InvalidSpecificationException; use SpipLeague\Composer\Extensions\InvalidSpecificationException;
use SpipLeague\Composer\Extensions\Specification; use SpipLeague\Composer\Extensions\Specification;
use SpipLeague\Composer\SpipPaths; use SpipLeague\Composer\SpipPaths;
use SpipLeague\Test\Composer\Fixtures\DummyConfigSource;
use SpipLeague\Test\Composer\Fixtures\RemoteUrlsStub; use SpipLeague\Test\Composer\Fixtures\RemoteUrlsStub;
#[CoversClass(Specification::class)] #[CoversClass(Specification::class)]
...@@ -95,7 +91,7 @@ class SpecificationTest extends TestCase ...@@ -95,7 +91,7 @@ class SpecificationTest extends TestCase
if ($changer) { if ($changer) {
$specification->setChanger(new RemoteUrlsStub( $specification->setChanger(new RemoteUrlsStub(
'git@github.com:vendor/prefix.git', 'git@github.com:vendor/prefix.git',
'https://github.com/vendor/prefix.git' 'https://github.com/vendor/prefix.git',
)); ));
} }
...@@ -202,7 +198,7 @@ class SpecificationTest extends TestCase ...@@ -202,7 +198,7 @@ class SpecificationTest extends TestCase
{ {
// Given // Given
Platform::putEnv('COMPOSER', 'tests/Fixtures/create-from-composer/composer.json'); Platform::putEnv('COMPOSER', 'tests/Fixtures/create-from-composer/composer.json');
$composer = ComposerFactory::create(new NullIO); $composer = ComposerFactory::create(new NullIO());
// When // When
$actual = Specification::createFromComposer($composer, 'test/prefix'); $actual = Specification::createFromComposer($composer, 'test/prefix');
......
...@@ -10,10 +10,14 @@ class CollectionMock implements CollectionInterface ...@@ -10,10 +10,14 @@ class CollectionMock implements CollectionInterface
{ {
protected int $position = 0; protected int $position = 0;
/** @var string[] */ /**
* @var string[]
*/
protected array $keys = []; protected array $keys = [];
/** @var array<string,SpecificationInterface> */ /**
* @var array<string,SpecificationInterface>
*/
protected array $collection = []; protected array $collection = [];
private string $file; private string $file;
...@@ -70,7 +74,7 @@ class CollectionMock implements CollectionInterface ...@@ -70,7 +74,7 @@ class CollectionMock implements CollectionInterface
public function offsetGet(mixed $offset): mixed public function offsetGet(mixed $offset): mixed
{ {
return isset($this->collection[$offset]) ? $this->collection[$offset] : null; return $this->collection[$offset] ?? null;
} }
public function offsetSet(mixed $offset, mixed $value): void public function offsetSet(mixed $offset, mixed $value): void
...@@ -79,7 +83,7 @@ class CollectionMock implements CollectionInterface ...@@ -79,7 +83,7 @@ class CollectionMock implements CollectionInterface
throw new InvalidSpecificationException('A collection must only contain valid specifications.', 3); throw new InvalidSpecificationException('A collection must only contain valid specifications.', 3);
} }
if (is_null($offset) || !\is_string($offset)) { if ($offset === null || !\is_string($offset)) {
$offset = $value->getPrefix(); $offset = $value->getPrefix();
} }
......
...@@ -8,10 +8,14 @@ use SpipLeague\Composer\Git\RemoteUrlsInterface; ...@@ -8,10 +8,14 @@ use SpipLeague\Composer\Git\RemoteUrlsInterface;
class RemoteUrlsStub implements RemoteUrlsInterface class RemoteUrlsStub implements RemoteUrlsInterface
{ {
/** @var string[] */ /**
* @var string[]
*/
private array $ssh = []; private array $ssh = [];
/** @var string[] */ /**
* @var string[]
*/
private array $https = []; private array $https = [];
public function __construct(string ...$urls) public function __construct(string ...$urls)
......
...@@ -22,7 +22,7 @@ class SpecificationMock implements SpecificationInterface ...@@ -22,7 +22,7 @@ class SpecificationMock implements SpecificationInterface
string $prefix = 'prefix', string $prefix = 'prefix',
string $vendorName = 'vendor/prefix', string $vendorName = 'vendor/prefix',
string $constraint = '1.0', string $constraint = '1.0',
string $path = 'path' string $path = 'path',
) { ) {
$this->prefix = $prefix; $this->prefix = $prefix;
$this->vendorName = $vendorName; $this->vendorName = $vendorName;
......