aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/plugin/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/tests/plugin/fixtures')
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json6
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json17
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php113
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php28
-rw-r--r--crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json32
5 files changed, 196 insertions, 0 deletions
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json
new file mode 100644
index 00000000..4fe63968
--- /dev/null
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/packages/asset-a/composer.json
@@ -0,0 +1,6 @@
+{
+ "name": "shirabe-test/asset-a",
+ "version": "1.0.0",
+ "type": "shirabe-asset",
+ "description": "Fixture package installed by the plugin-provided installer."
+}
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json
new file mode 100644
index 00000000..8275f2c0
--- /dev/null
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/composer.json
@@ -0,0 +1,17 @@
+{
+ "name": "shirabe-test/asset-installer",
+ "version": "1.0.0",
+ "type": "composer-plugin",
+ "description": "Fixture plugin registering a custom installer through InstallationManager::addInstaller.",
+ "autoload": {
+ "psr-4": {
+ "ShirabeTest\\AssetInstaller\\": "src/"
+ }
+ },
+ "require": {
+ "composer-plugin-api": "^2.0"
+ },
+ "extra": {
+ "class": "ShirabeTest\\AssetInstaller\\Plugin"
+ }
+}
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php
new file mode 100644
index 00000000..a80eb678
--- /dev/null
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/AssetInstaller.php
@@ -0,0 +1,113 @@
+<?php
+
+namespace ShirabeTest\AssetInstaller;
+
+use Composer\Composer;
+use Composer\Installer\InstallerInterface;
+use Composer\IO\IOInterface;
+use Composer\Package\PackageInterface;
+use Composer\Repository\InstalledRepositoryInterface;
+use React\Promise\PromiseInterface;
+
+/**
+ * Installs `shirabe-asset` packages by writing a manifest of what the installer observed,
+ * without going through the download manager. Every call also appends a trace line, so the
+ * order and arguments of the installer contract are comparable between implementations.
+ */
+class AssetInstaller implements InstallerInterface
+{
+ /** @var IOInterface */
+ private $io;
+
+ /** @var Composer */
+ private $composer;
+
+ public function __construct(IOInterface $io, Composer $composer)
+ {
+ $this->io = $io;
+ $this->composer = $composer;
+ }
+
+ public function supports(string $packageType): bool
+ {
+ $this->trace('supports ' . $packageType);
+
+ return $packageType === 'shirabe-asset';
+ }
+
+ public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package): bool
+ {
+ $this->trace('isInstalled ' . $package->getPrettyName());
+
+ return is_file($this->getInstallPath($package) . '/asset.txt');
+ }
+
+ public function download(PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface
+ {
+ $this->trace('download ' . $package->getPrettyName() . ' prev=' . $this->name($prevPackage));
+
+ return null;
+ }
+
+ public function prepare(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface
+ {
+ $this->trace('prepare ' . $type . ' ' . $package->getPrettyName() . ' prev=' . $this->name($prevPackage));
+
+ return null;
+ }
+
+ public function install(InstalledRepositoryInterface $repo, PackageInterface $package): ?PromiseInterface
+ {
+ $path = $this->getInstallPath($package);
+ $this->trace('install ' . $package->getPrettyName() . ' -> ' . $path);
+ @mkdir($path, 0777, true);
+ file_put_contents($path . '/asset.txt', implode("\n", [
+ 'name=' . $package->getPrettyName(),
+ 'version=' . $package->getPrettyVersion(),
+ 'type=' . $package->getType(),
+ 'root=' . $this->composer->getPackage()->getName(),
+ ]) . "\n");
+ $this->io->write('asset-installer: installed ' . $package->getPrettyName());
+
+ return null;
+ }
+
+ public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target): ?PromiseInterface
+ {
+ $this->trace('update ' . $initial->getPrettyName() . ' -> ' . $target->getPrettyName());
+
+ return $this->install($repo, $target);
+ }
+
+ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package): ?PromiseInterface
+ {
+ $path = $this->getInstallPath($package);
+ $this->trace('uninstall ' . $package->getPrettyName());
+ @unlink($path . '/asset.txt');
+ @rmdir($path);
+
+ return null;
+ }
+
+ public function cleanup(string $type, PackageInterface $package, ?PackageInterface $prevPackage = null): ?PromiseInterface
+ {
+ $this->trace('cleanup ' . $type . ' ' . $package->getPrettyName());
+
+ return null;
+ }
+
+ public function getInstallPath(PackageInterface $package): string
+ {
+ return 'assets/' . $package->getPrettyName();
+ }
+
+ private function name(?PackageInterface $package): string
+ {
+ return $package === null ? 'null' : $package->getPrettyName();
+ }
+
+ private function trace(string $line): void
+ {
+ file_put_contents('installer-trace.txt', $line . "\n", FILE_APPEND);
+ }
+}
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php
new file mode 100644
index 00000000..24a1d295
--- /dev/null
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/plugin/src/Plugin.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace ShirabeTest\AssetInstaller;
+
+use Composer\Composer;
+use Composer\IO\IOInterface;
+use Composer\Plugin\PluginInterface;
+
+class Plugin implements PluginInterface
+{
+ /** @var AssetInstaller */
+ private $installer;
+
+ public function activate(Composer $composer, IOInterface $io): void
+ {
+ $this->installer = new AssetInstaller($io, $composer);
+ $composer->getInstallationManager()->addInstaller($this->installer);
+ }
+
+ public function deactivate(Composer $composer, IOInterface $io): void
+ {
+ $composer->getInstallationManager()->removeInstaller($this->installer);
+ }
+
+ public function uninstall(Composer $composer, IOInterface $io): void
+ {
+ }
+}
diff --git a/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json b/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json
new file mode 100644
index 00000000..64c1bb32
--- /dev/null
+++ b/crates/shirabe/tests/plugin/fixtures/e2e-installer/project/composer.json
@@ -0,0 +1,32 @@
+{
+ "name": "shirabe/e2e-installer",
+ "description": "E2E fixture project: install a custom package type through a plugin-provided installer.",
+ "repositories": [
+ {
+ "type": "path",
+ "url": "../plugin",
+ "options": {
+ "symlink": false
+ }
+ },
+ {
+ "type": "path",
+ "url": "../packages/*",
+ "options": {
+ "symlink": false
+ }
+ },
+ {
+ "packagist.org": false
+ }
+ ],
+ "require": {
+ "shirabe-test/asset-installer": "1.0.0",
+ "shirabe-test/asset-a": "1.0.0"
+ },
+ "config": {
+ "allow-plugins": {
+ "shirabe-test/asset-installer": true
+ }
+ }
+}