From 12692d64c91ad5f098613781aa6cf47c49d122ea Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Tue, 10 Jul 2018 22:57:54 +0200 Subject: [PATCH] added a abstract installation manger and moved some files to common (#24) | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - --- .travis.yml | 3 +- .../Installer/AbstractInstallationManager.php | 318 ++++++++++++++++++ .../Installer/InstallationManager.php | 2 +- .../Installer/Installer.php | 2 +- .../Traits/GetGenericPropertyReaderTrait.php | 2 +- src/Discovery/Discovery.php | 2 +- .../Installer/QuestionInstallationManager.php | 289 +--------------- src/Discovery/OperationsResolver.php | 1 + .../Installer/InstallationManagerTest.php | 4 +- .../Installer/InstallerTest.php | 4 +- tests/Common/PackageTest.php | 24 +- tests/Common/PathTest.php | 6 +- .../Traits/ExpandTargetDirTraitTest.php | 2 +- .../Common/Traits/PhpFileMarkerTraitTest.php | 6 +- tests/Discovery/ClassFinderTest.php | 12 +- .../ComposerScriptsConfiguratorTest.php | 4 +- .../CopyFromPackageConfiguratorTest.php | 16 +- .../Configurator/EnvConfiguratorTest.php | 14 +- .../GitignoreConfiguratorTest.php | 14 +- tests/Discovery/ConfiguratorTest.php | 10 +- tests/Discovery/DiscoveryTest.php | 16 +- .../Installer/ConfiguratorInstallerTest.php | 2 +- .../QuestionInstallationManagerTest.php | 22 +- tests/Discovery/LockTest.php | 14 +- tests/Discovery/OperationsResolverTest.php | 24 +- tests/Discovery/PackageConfiguratorTest.php | 2 +- .../Prefetcher/ParallelDownloaderTest.php | 8 +- tests/Discovery/QuestionFactoryTest.php | 14 +- 28 files changed, 444 insertions(+), 393 deletions(-) create mode 100644 src/Common/Installer/AbstractInstallationManager.php rename src/{Discovery => Common}/Installer/InstallationManager.php (95%) rename src/{Discovery => Common}/Installer/Installer.php (98%) rename src/{Discovery => Common}/Traits/GetGenericPropertyReaderTrait.php (92%) rename tests/{Discovery => Common}/Installer/InstallationManagerTest.php (95%) rename tests/{Discovery => Common}/Installer/InstallerTest.php (97%) diff --git a/.travis.yml b/.travis.yml index c6ba0b7b..27cb2dbf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,8 +58,7 @@ jobs: - bash <(curl -s https://codecov.io/bash) - stage: Subsplit - # Regex for semver - if: (branch = master OR tag =~ /\bv(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?\b/i) + if: (branch = master OR tag IS present) php: 7.2 before_install: - echo "skip" diff --git a/src/Common/Installer/AbstractInstallationManager.php b/src/Common/Installer/AbstractInstallationManager.php new file mode 100644 index 00000000..86155333 --- /dev/null +++ b/src/Common/Installer/AbstractInstallationManager.php @@ -0,0 +1,318 @@ +composer = $composer; + $this->io = $io; + $this->input = $input; + $this->jsonFile = new JsonFile(Factory::getComposerFile()); + + $this->rootPackage = $this->composer->getPackage(); + $this->stability = $this->rootPackage->getMinimumStability() ?: 'stable'; + + $pool = new Pool($this->stability); + $pool->addRepository( + new CompositeRepository(\array_merge([new PlatformRepository()], RepositoryFactory::defaultRepos($io))) + ); + + $this->versionSelector = new VersionSelector($pool); + $this->localRepository = $this->composer->getRepositoryManager()->getLocalRepository(); + + foreach ($this->localRepository->getPackages() as $package) { + $this->installedPackages[\mb_strtolower($package->getName())] = \ltrim($package->getPrettyVersion(), 'v'); + } + } + + /** + * Install extra dependencies. + * + * @param \Narrowspark\Discovery\Common\Contract\Package $package + * @param array $dependencies + * + * @throws \Narrowspark\Discovery\Exception\RuntimeException + * @throws \Narrowspark\Discovery\Exception\InvalidArgumentException + * @throws \Exception + * + * @return \Narrowspark\Discovery\Common\Contract\Package[] + */ + abstract public function install(PackageContract $package, array $dependencies): array; + + /** + * Uninstall extra dependencies. + * + * @param \Narrowspark\Discovery\Common\Contract\Package $package + * @param array $dependencies + * + * @throws \Exception + * + * @return \Narrowspark\Discovery\Common\Contract\Package[] + */ + abstract public function uninstall(PackageContract $package, array $dependencies): array; + + /** + * @codeCoverageIgnore + * + * Get configured installer instance. + * + * @return \Composer\Installer + */ + protected function getInstaller(): BaseInstaller + { + return Installer::create($this->io, $this->composer, $this->input); + } + + /** + * Try to find the best version fot the package. + * + * @param string $name + * + * @throws \Narrowspark\Discovery\Exception\InvalidArgumentException + * + * @return string + */ + protected function findVersion(string $name): string + { + // find the latest version allowed in this pool + $package = $this->versionSelector->findBestCandidate($name, null, null, 'stable'); + + if ($package === false) { + throw new InvalidArgumentException(\sprintf( + 'Could not find package %s at any version for your minimum-stability (%s).' + . ' Check the package spelling or your minimum-stability.', + $name, + $this->stability + )); + } + + return $this->versionSelector->findRecommendedRequireVersion($package); + } + + /** + * Update the root composer.json require. + * + * @param array $packages + * @param int $type + * + * @return \Composer\Package\RootPackageInterface + */ + protected function updateRootComposerJson(array $packages, int $type): RootPackageInterface + { + $this->io->writeError('Updating root package'); + + $requires = $this->rootPackage->getRequires(); + + if ($type === self::ADD) { + foreach ($packages as $packageName => $version) { + $requires[$packageName] = new Link( + '__root__', + $packageName, + (new VersionParser())->parseConstraints($version), + 'requires', + $version + ); + } + } elseif ($type === self::REMOVE) { + foreach ($packages as $packageName => $version) { + unset($requires[$packageName]); + } + } + + $this->rootPackage->setRequires($requires); + + return $this->rootPackage; + } + + /** + * Manipulate root composer.json with the new packages and dump it. + * + * @param array $packages + * @param int $type + * + * @throws \Exception happens in the JsonFile class + * + * @return void + */ + protected function updateComposerJson(array $packages, int $type): void + { + $this->io->writeError('Updating composer.json'); + + if ($type === self::ADD) { + $jsonManipulator = new JsonManipulator(\file_get_contents($this->jsonFile->getPath())); + + foreach ($packages as $name => $version) { + $sortPackages = $this->composer->getConfig()->get('sort-packages') ?? false; + + $jsonManipulator->addLink('require', $name, $version, $sortPackages); + } + + \file_put_contents($this->jsonFile->getPath(), $jsonManipulator->getContents()); + } elseif ($type === self::REMOVE) { + $jsonFileContent = $this->jsonFile->read(); + + foreach ($packages as $packageName => $version) { + unset($jsonFileContent['require'][$packageName]); + } + + $this->jsonFile->write($jsonFileContent); + } + } + + /** + * Install selected packages. + * + * @param \Composer\Package\RootPackageInterface $rootPackage + * @param array $whitelistPackages + * + * @throws \Exception + * + * @return int + */ + protected function runInstaller(RootPackageInterface $rootPackage, array $whitelistPackages): int + { + $this->io->writeError('Running an update to install dependent packages'); + + $this->composer->setPackage($rootPackage); + + $installer = $this->getInstaller(); + $installer->setUpdateWhitelist($whitelistPackages); + + return $installer->run(); + } + + /** + * Adds a modified installation manager to composer. + * + * @param \Composer\Installer\InstallationManager $oldInstallManager + * + * @return void + */ + protected function addDiscoveryInstallationManagerToComposer(BaseInstallationManager $oldInstallManager): void + { + $reader = $this->getGenericPropertyReader(); + $installers = (array) $reader($oldInstallManager, 'installers'); + + $narrowsparkInstaller = new InstallationManager(); + + foreach ($installers as $installer) { + $narrowsparkInstaller->addInstaller($installer); + } + + $this->composer->setInstallationManager($narrowsparkInstaller); + } + + /** + * Get merged root requires and dev-requires. + * + * @return \Composer\Package\Link[] + */ + protected function getRootRequires(): array + { + return \array_merge($this->rootPackage->getRequires(), $this->rootPackage->getDevRequires()); + } +} diff --git a/src/Discovery/Installer/InstallationManager.php b/src/Common/Installer/InstallationManager.php similarity index 95% rename from src/Discovery/Installer/InstallationManager.php rename to src/Common/Installer/InstallationManager.php index 0bee9f9d..48aff8a3 100644 --- a/src/Discovery/Installer/InstallationManager.php +++ b/src/Common/Installer/InstallationManager.php @@ -1,6 +1,6 @@ composer = $composer; - $this->io = $io; - $this->input = $input; - $this->operationsResolver = $operationsResolver; - $this->jsonFile = new JsonFile(Factory::getComposerFile()); - - $this->rootPackage = $this->composer->getPackage(); - $this->stability = $this->rootPackage->getMinimumStability() ?: 'stable'; - - $pool = new Pool($this->stability); - $pool->addRepository( - new CompositeRepository(\array_merge([new PlatformRepository()], RepositoryFactory::defaultRepos($io))) - ); - - $this->versionSelector = new VersionSelector($pool); - $this->localRepository = $this->composer->getRepositoryManager()->getLocalRepository(); + parent::__construct($composer, $io, $input); - foreach ($this->localRepository->getPackages() as $package) { - $this->installedPackages[\mb_strtolower($package->getName())] = \ltrim($package->getPrettyVersion(), 'v'); - } + $this->operationsResolver = $operationsResolver; } /** @@ -239,16 +133,6 @@ public function install(PackageContract $package, array $dependencies): array return $this->operationsResolver->resolve($operations); } - /** - * Returns selected packages from questions. - * - * @return array - */ - public function getPackagesToInstall(): array - { - return $this->packagesToInstall; - } - /** * Uninstall extra dependencies. * @@ -301,15 +185,13 @@ public function uninstall(PackageContract $package, array $dependencies): array } /** - * @codeCoverageIgnore - * - * Get configured installer instance. + * Returns selected packages from questions. * - * @return \Composer\Installer + * @return array */ - protected function getInstaller(): BaseInstaller + public function getPackagesToInstall(): array { - return Installer::create($this->io, $this->composer, $this->input); + return $this->packagesToInstall; } /** @@ -361,153 +243,4 @@ function ($input) use ($packageNames) { return $package; } - - /** - * Try to find the best version fot the package. - * - * @param string $name - * - * @throws \Narrowspark\Discovery\Exception\InvalidArgumentException - * - * @return string - */ - private function findVersion(string $name): string - { - // find the latest version allowed in this pool - $package = $this->versionSelector->findBestCandidate($name, null, null, 'stable'); - - if ($package === false) { - throw new InvalidArgumentException(\sprintf( - 'Could not find package %s at any version for your minimum-stability (%s).' - . ' Check the package spelling or your minimum-stability.', - $name, - $this->stability - )); - } - - return $this->versionSelector->findRecommendedRequireVersion($package); - } - - /** - * Update the root composer.json require. - * - * @param array $packages - * @param int $type - * - * @return \Composer\Package\RootPackageInterface - */ - private function updateRootComposerJson(array $packages, int $type): RootPackageInterface - { - $this->io->writeError('Updating root package'); - - $requires = $this->rootPackage->getRequires(); - - if ($type === self::ADD) { - foreach ($packages as $packageName => $version) { - $requires[$packageName] = new Link( - '__root__', - $packageName, - (new VersionParser())->parseConstraints($version), - 'requires', - $version - ); - } - } elseif ($type === self::REMOVE) { - foreach ($packages as $packageName => $version) { - unset($requires[$packageName]); - } - } - - $this->rootPackage->setRequires($requires); - - return $this->rootPackage; - } - - /** - * Manipulate root composer.json with the new packages and dump it. - * - * @param array $packages - * @param int $type - * - * @throws \Exception happens in the JsonFile class - * - * @return void - */ - private function updateComposerJson(array $packages, int $type): void - { - $this->io->writeError('Updating composer.json'); - - if ($type === self::ADD) { - $jsonManipulator = new JsonManipulator(\file_get_contents($this->jsonFile->getPath())); - - foreach ($packages as $name => $version) { - $sortPackages = $this->composer->getConfig()->get('sort-packages') ?? false; - - $jsonManipulator->addLink('require', $name, $version, $sortPackages); - } - - \file_put_contents($this->jsonFile->getPath(), $jsonManipulator->getContents()); - } elseif ($type === self::REMOVE) { - $jsonFileContent = $this->jsonFile->read(); - - foreach ($packages as $packageName => $version) { - unset($jsonFileContent['require'][$packageName]); - } - - $this->jsonFile->write($jsonFileContent); - } - } - - /** - * Install selected packages. - * - * @param \Composer\Package\RootPackageInterface $rootPackage - * @param array $whitelistPackages - * - * @throws \Exception - * - * @return int - */ - private function runInstaller(RootPackageInterface $rootPackage, array $whitelistPackages): int - { - $this->io->writeError('Running an update to install dependent packages'); - - $this->composer->setPackage($rootPackage); - - $installer = $this->getInstaller(); - $installer->setUpdateWhitelist($whitelistPackages); - - return $installer->run(); - } - - /** - * Adds a modified installation manager to composer. - * - * @param \Composer\Installer\InstallationManager $oldInstallManager - * - * @return void - */ - private function addDiscoveryInstallationManagerToComposer(BaseInstallationManager $oldInstallManager): void - { - $reader = $this->getGenericPropertyReader(); - $installers = (array) $reader($oldInstallManager, 'installers'); - - $narrowsparkInstaller = new InstallationManager(); - - foreach ($installers as $installer) { - $narrowsparkInstaller->addInstaller($installer); - } - - $this->composer->setInstallationManager($narrowsparkInstaller); - } - - /** - * Get merged root requires and dev-requires. - * - * @return \Composer\Package\Link[] - */ - private function getRootRequires(): array - { - return \array_merge($this->rootPackage->getRequires(), $this->rootPackage->getDevRequires()); - } } diff --git a/src/Discovery/OperationsResolver.php b/src/Discovery/OperationsResolver.php index dcf387d2..5fb547b6 100644 --- a/src/Discovery/OperationsResolver.php +++ b/src/Discovery/OperationsResolver.php @@ -44,6 +44,7 @@ public function __construct(Lock $lock, string $vendorDir) /** * Set the parent package name. + * This is used for the "extra-dependency-of" key. * * @param string $name * diff --git a/tests/Discovery/Installer/InstallationManagerTest.php b/tests/Common/Installer/InstallationManagerTest.php similarity index 95% rename from tests/Discovery/Installer/InstallationManagerTest.php rename to tests/Common/Installer/InstallationManagerTest.php index 8a0c5e43..a6b14080 100644 --- a/tests/Discovery/Installer/InstallationManagerTest.php +++ b/tests/Common/Installer/InstallationManagerTest.php @@ -9,7 +9,7 @@ use Composer\Installer\InstallerInterface; use Composer\Package\Package; use Composer\Repository\InstalledRepositoryInterface; -use Narrowspark\Discovery\Installer\InstallationManager; +use Narrowspark\Discovery\Common\Installer\InstallationManager; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; /** @@ -63,7 +63,7 @@ public function testExecuteWithGetOperations(): void $manager->execute($installedRepoMock, $installOperationMock); $manager->execute($installedRepoMock, $aliasOperationMock); - $this->assertCount(3, $manager->getOperations()); + static::assertCount(3, $manager->getOperations()); } /** diff --git a/tests/Discovery/Installer/InstallerTest.php b/tests/Common/Installer/InstallerTest.php similarity index 97% rename from tests/Discovery/Installer/InstallerTest.php rename to tests/Common/Installer/InstallerTest.php index db356eb6..0a1977ce 100644 --- a/tests/Discovery/Installer/InstallerTest.php +++ b/tests/Common/Installer/InstallerTest.php @@ -10,7 +10,7 @@ use Composer\Package\Locker; use Composer\Package\RootPackageInterface; use Composer\Repository\RepositoryManager; -use Narrowspark\Discovery\Installer\Installer; +use Narrowspark\Discovery\Common\Installer\Installer; use Narrowspark\Discovery\Test\Traits\ArrangeComposerClasses; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; @@ -66,7 +66,7 @@ public function testCreateWithConfigSettings(): void $installer = Installer::create($this->ioMock, $this->composerMock, $this->inputMock); - $this->assertInstanceOf(BaseInstaller::class, $installer); + static::assertInstanceOf(BaseInstaller::class, $installer); } /** diff --git a/tests/Common/PackageTest.php b/tests/Common/PackageTest.php index 411ec11d..e2053d13 100644 --- a/tests/Common/PackageTest.php +++ b/tests/Common/PackageTest.php @@ -43,17 +43,17 @@ protected function setUp(): void public function testGetName(): void { - $this->assertSame('test', $this->package->getName()); + static::assertSame('test', $this->package->getName()); } public function testGetVersion(): void { - $this->assertSame('1', $this->package->getVersion()); + static::assertSame('1', $this->package->getVersion()); } public function testGetPackagePath(): void { - $this->assertSame( + static::assertSame( \str_replace('\\', '/', __DIR__ . '/test/'), $this->package->getPackagePath() ); @@ -63,45 +63,45 @@ public function testGetConfiguratorOptions(): void { $options = $this->package->getConfiguratorOptions('copy'); - $this->assertEquals(['from' => 'to'], $options); + static::assertEquals(['from' => 'to'], $options); $options = $this->package->getConfiguratorOptions('test'); - $this->assertEquals([], $options); + static::assertEquals([], $options); } public function testGetOptions(): void { - $this->assertEquals($this->config, $this->package->getOptions()); + static::assertEquals($this->config, $this->package->getOptions()); } public function testGetUrl(): void { - $this->assertSame($this->config['url'], $this->package->getUrl()); + static::assertSame($this->config['url'], $this->package->getUrl()); } public function testGetOperation(): void { - $this->assertSame($this->config['operation'], $this->package->getOperation()); + static::assertSame($this->config['operation'], $this->package->getOperation()); } public function testGetType(): void { - $this->assertSame($this->config['type'], $this->package->getType()); + static::assertSame($this->config['type'], $this->package->getType()); } public function testIsExtraDependency(): void { - $this->assertTrue($this->package->isExtraDependency()); + static::assertTrue($this->package->isExtraDependency()); } public function testGetRequire(): void { - $this->assertSame([], $this->package->getRequires()); + static::assertSame([], $this->package->getRequires()); } public function testGetOption(): void { - $this->assertSame('foo/bar', $this->package->getOption('extra-dependency-of')); + static::assertSame('foo/bar', $this->package->getOption('extra-dependency-of')); } } diff --git a/tests/Common/PathTest.php b/tests/Common/PathTest.php index 5f9e3c81..5901ed6a 100644 --- a/tests/Common/PathTest.php +++ b/tests/Common/PathTest.php @@ -27,12 +27,12 @@ protected function setUp(): void public function testGetWorkingDir(): void { - $this->assertSame(__DIR__, $this->path->getWorkingDir()); + static::assertSame(__DIR__, $this->path->getWorkingDir()); } public function testRelativize(): void { - $this->assertSame( + static::assertSame( './', $this->path->relativize(__DIR__) ); @@ -40,7 +40,7 @@ public function testRelativize(): void public function testConcatenateOnWindows(): void { - $this->assertEquals( + static::assertEquals( 'c:\\my-project/src/kernel.php', $this->path->concatenate(['c:\\my-project', 'src/', 'kernel.php']) ); diff --git a/tests/Common/Traits/ExpandTargetDirTraitTest.php b/tests/Common/Traits/ExpandTargetDirTraitTest.php index e2d69fc2..c665f56f 100644 --- a/tests/Common/Traits/ExpandTargetDirTraitTest.php +++ b/tests/Common/Traits/ExpandTargetDirTraitTest.php @@ -14,6 +14,6 @@ final class ExpandTargetDirTraitTest extends TestCase public function testItCanIdentifyVarsInTargetDir(): void { - $this->assertSame('bar', self::expandTargetDir(['foo' => 'bar/'], '%foo%')); + static::assertSame('bar', self::expandTargetDir(['foo' => 'bar/'], '%foo%')); } } diff --git a/tests/Common/Traits/PhpFileMarkerTraitTest.php b/tests/Common/Traits/PhpFileMarkerTraitTest.php index 6ca8641d..4aea49e3 100644 --- a/tests/Common/Traits/PhpFileMarkerTraitTest.php +++ b/tests/Common/Traits/PhpFileMarkerTraitTest.php @@ -35,14 +35,14 @@ public function testIsFileMarked(): void { \file_put_contents($this->path, " marked **/ 'test' /** < marked **/\n];\n"); - $this->assertFalse($this->isFileMarked('test', $this->path)); - $this->assertTrue($this->isFileMarked('marked', $this->path)); + static::assertFalse($this->isFileMarked('test', $this->path)); + static::assertTrue($this->isFileMarked('marked', $this->path)); } public function testMarkData(): void { \file_put_contents($this->path, $this->markData('test', '$arr = [];', 4)); - $this->assertTrue($this->isFileMarked('test', $this->path)); + static::assertTrue($this->isFileMarked('test', $this->path)); } } diff --git a/tests/Discovery/ClassFinderTest.php b/tests/Discovery/ClassFinderTest.php index 17781f08..f90a8e18 100644 --- a/tests/Discovery/ClassFinderTest.php +++ b/tests/Discovery/ClassFinderTest.php @@ -19,11 +19,11 @@ public function testItFindsAllClassesInDirectoryWithGivenNamespace(): void { $classes = ClassFinder::find(__DIR__ . '/Fixtures/Finder'); - $this->assertContains(DummyClass::class, $classes); - $this->assertContains(DummyClassTwo::class, $classes); - $this->assertContains(DummyClassNested::class, $classes); - $this->assertContains(FooTrait::class, $classes); - $this->assertContains(AbstractClass::class, $classes); + static::assertContains(DummyClass::class, $classes); + static::assertContains(DummyClassTwo::class, $classes); + static::assertContains(DummyClassNested::class, $classes); + static::assertContains(FooTrait::class, $classes); + static::assertContains(AbstractClass::class, $classes); } public function testWithEmptyFolder(): void @@ -36,7 +36,7 @@ public function testWithEmptyFolder(): void $classes = ClassFinder::find($dir); - $this->assertSame([], $classes); + static::assertSame([], $classes); \unlink($filePath); \rmdir($dir); diff --git a/tests/Discovery/Configurator/ComposerScriptsConfiguratorTest.php b/tests/Discovery/Configurator/ComposerScriptsConfiguratorTest.php index 9fc8f767..6ad83a95 100644 --- a/tests/Discovery/Configurator/ComposerScriptsConfiguratorTest.php +++ b/tests/Discovery/Configurator/ComposerScriptsConfiguratorTest.php @@ -7,9 +7,9 @@ use Composer\Json\JsonFile; use Composer\Json\JsonManipulator; use Narrowspark\Discovery\Common\Contract\Package as PackageContract; +use Narrowspark\Discovery\Common\Traits\GetGenericPropertyReaderTrait; use Narrowspark\Discovery\Configurator\ComposerScriptsConfigurator; use Narrowspark\Discovery\Test\Fixtures\ComposerJsonFactory; -use Narrowspark\Discovery\Traits\GetGenericPropertyReaderTrait; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; /** @@ -70,7 +70,7 @@ protected function setUp(): void public function testGetName(): void { - $this->assertSame('composer-scripts', ComposerScriptsConfigurator::getName()); + static::assertSame('composer-scripts', ComposerScriptsConfigurator::getName()); } public function testConfigure(): void diff --git a/tests/Discovery/Configurator/CopyFromPackageConfiguratorTest.php b/tests/Discovery/Configurator/CopyFromPackageConfiguratorTest.php index 7d7a8875..4b3fc636 100644 --- a/tests/Discovery/Configurator/CopyFromPackageConfiguratorTest.php +++ b/tests/Discovery/Configurator/CopyFromPackageConfiguratorTest.php @@ -45,7 +45,7 @@ protected function setUp(): void public function testGetName(): void { - $this->assertSame('copy', CopyFromPackageConfigurator::getName()); + static::assertSame('copy', CopyFromPackageConfigurator::getName()); } public function testCopyFileFromPackage(): void @@ -77,7 +77,7 @@ public function testCopyFileFromPackage(): void $filePath = \sys_get_temp_dir() . '/' . $toFileName; - $this->assertFileExists($filePath); + static::assertFileExists($filePath); \unlink($filePath); } @@ -112,8 +112,8 @@ public function testCopyADirWithFileFromPackage(): void $dirPath = \sys_get_temp_dir() . '/css'; $filePath = $dirPath . '/style.css'; - $this->assertDirectoryExists($dirPath); - $this->assertFileExists($filePath); + static::assertDirectoryExists($dirPath); + static::assertFileExists($filePath); \unlink($filePath); \rmdir($dirPath); @@ -149,7 +149,7 @@ public function testTryCopyAFileThatIsNotFoundFromPackage(): void $filePath = \sys_get_temp_dir() . '/' . $toFileName; - $this->assertFileNotExists($filePath); + static::assertFileNotExists($filePath); } public function testUnconfigureAFileFromPackage(): void @@ -227,7 +227,7 @@ public function testUnconfigureADirWithFileFromPackage(): void $dirPath = \sys_get_temp_dir() . '/css'; - $this->assertDirectoryExists($dirPath); + static::assertDirectoryExists($dirPath); \rmdir($dirPath); } @@ -280,7 +280,7 @@ public function testUnconfigureWithAIOException(): void \unlink($dirPath . '/style.css'); - $this->assertDirectoryExists($dirPath); + static::assertDirectoryExists($dirPath); \rmdir($dirPath); } @@ -314,7 +314,7 @@ public function testCopyFileFromPackageWithConfig(): void $filePath = \sys_get_temp_dir() . '/test/' . $toFileName; - $this->assertFileExists($filePath); + static::assertFileExists($filePath); \unlink($filePath); \rmdir(\sys_get_temp_dir() . '/test/'); diff --git a/tests/Discovery/Configurator/EnvConfiguratorTest.php b/tests/Discovery/Configurator/EnvConfiguratorTest.php index b61a235c..154debd1 100644 --- a/tests/Discovery/Configurator/EnvConfiguratorTest.php +++ b/tests/Discovery/Configurator/EnvConfiguratorTest.php @@ -69,7 +69,7 @@ protected function tearDown(): void public function testGetName(): void { - $this->assertSame('env', EnvConfigurator::getName()); + static::assertSame('env', EnvConfigurator::getName()); } public function testConfigure(): void @@ -118,8 +118,8 @@ public function testConfigure(): void // Skip on second call $this->configurator->configure($package); - $this->assertStringEqualsFile($this->envDistPath, $envContents); - $this->assertStringEqualsFile($this->envPath, $envContents); + static::assertStringEqualsFile($this->envDistPath, $envContents); + static::assertStringEqualsFile($this->envPath, $envContents); } public function testUnconfigure(): void @@ -158,8 +158,8 @@ public function testUnconfigure(): void ###< env2 ### EOF; - $this->assertStringEqualsFile($this->envDistPath, $envContents); - $this->assertStringEqualsFile($this->envPath, $envContents); + static::assertStringEqualsFile($this->envDistPath, $envContents); + static::assertStringEqualsFile($this->envPath, $envContents); $package = new Package( 'env2', @@ -175,13 +175,13 @@ public function testUnconfigure(): void $this->configurator->unconfigure($package); - $this->assertStringEqualsFile( + static::assertStringEqualsFile( $this->envDistPath, <<<'EOF' EOF ); - $this->assertStringEqualsFile( + static::assertStringEqualsFile( $this->envPath, <<<'EOF' diff --git a/tests/Discovery/Configurator/GitignoreConfiguratorTest.php b/tests/Discovery/Configurator/GitignoreConfiguratorTest.php index 0f2e4d98..2c989d1f 100644 --- a/tests/Discovery/Configurator/GitignoreConfiguratorTest.php +++ b/tests/Discovery/Configurator/GitignoreConfiguratorTest.php @@ -62,7 +62,7 @@ protected function tearDown(): void public function testGetName(): void { - $this->assertSame('gitignore', GitIgnoreConfigurator::getName()); + static::assertSame('gitignore', GitIgnoreConfigurator::getName()); } public function testConfigureAndUnconfigure(): void @@ -113,24 +113,24 @@ public function testConfigureAndUnconfigure(): void $this->configurator->configure($package); - $this->assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n"); + static::assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n"); $this->configurator->configure($package2); - $this->assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n\n" . $gitignoreContents2 . "\n"); + static::assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n\n" . $gitignoreContents2 . "\n"); $this->configurator->configure($package); $this->configurator->configure($package2); - $this->assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n\n" . $gitignoreContents2 . "\n"); + static::assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n\n" . $gitignoreContents2 . "\n"); $this->configurator->unconfigure($package); - $this->assertStringEqualsFile($this->gitignorePath, $gitignoreContents2 . "\n"); + static::assertStringEqualsFile($this->gitignorePath, $gitignoreContents2 . "\n"); $this->configurator->unconfigure($package2); - $this->assertStringEqualsFile($this->gitignorePath, ''); + static::assertStringEqualsFile($this->gitignorePath, ''); } public function testUnconfigureWithNotFoundPackage(): void @@ -175,6 +175,6 @@ public function testUnconfigureWithNotFoundPackage(): void /public/css/ ###< FooBundle ### EOF; - $this->assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n"); + static::assertStringEqualsFile($this->gitignorePath, "\n" . $gitignoreContents1 . "\n"); } } diff --git a/tests/Discovery/ConfiguratorTest.php b/tests/Discovery/ConfiguratorTest.php index 68448f0a..68e8b0a0 100644 --- a/tests/Discovery/ConfiguratorTest.php +++ b/tests/Discovery/ConfiguratorTest.php @@ -49,12 +49,12 @@ public function testAdd(): void $property = $ref->getProperty('configurators'); $property->setAccessible(true); - $this->assertArrayNotHasKey('mock-configurator', $property->getValue($this->configurator)); + static::assertArrayNotHasKey('mock-configurator', $property->getValue($this->configurator)); $mockConfigurator = $this->getMockForAbstractClass(ConfiguratorContract::class, [$this->composer, $this->nullIo, []]); $this->configurator->add('mock-configurator', \get_class($mockConfigurator)); - $this->assertArrayHasKey('mock-configurator', $property->getValue($this->configurator)); + static::assertArrayHasKey('mock-configurator', $property->getValue($this->configurator)); } public function testAddWithExistingConfiguratorName(): void @@ -80,7 +80,7 @@ public function testConfigureWithCopy(): void { [$filePath, $package] = $this->arrangeCopyConfiguratorTest(); - $this->assertFileExists($filePath); + static::assertFileExists($filePath); \unlink($filePath); } @@ -89,11 +89,11 @@ public function testUnconfigureWithCopy(): void { [$filePath, $package] = $this->arrangeCopyConfiguratorTest(); - $this->assertFileExists($filePath); + static::assertFileExists($filePath); $this->configurator->unconfigure($package); - $this->assertFileNotExists($filePath); + static::assertFileNotExists($filePath); } /** diff --git a/tests/Discovery/DiscoveryTest.php b/tests/Discovery/DiscoveryTest.php index a1952794..a85f9759 100644 --- a/tests/Discovery/DiscoveryTest.php +++ b/tests/Discovery/DiscoveryTest.php @@ -18,12 +18,12 @@ use Composer\Plugin\PluginManager; use Composer\Repository\RepositoryManager; use Composer\Repository\WritableRepositoryInterface; +use Narrowspark\Discovery\Common\Traits\GetGenericPropertyReaderTrait; use Narrowspark\Discovery\Configurator; use Narrowspark\Discovery\Discovery; use Narrowspark\Discovery\Installer\ConfiguratorInstaller; use Narrowspark\Discovery\Lock; use Narrowspark\Discovery\Test\Traits\ArrangeComposerClasses; -use Narrowspark\Discovery\Traits\GetGenericPropertyReaderTrait; use Narrowspark\TestingHelper\Phpunit\MockeryTestCase; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Filesystem\Filesystem; @@ -71,20 +71,20 @@ protected function tearDown(): void public function testGetDiscoveryLockFile(): void { - $this->assertSame('./discovery.lock', Discovery::getDiscoveryLockFile()); + static::assertSame('./discovery.lock', Discovery::getDiscoveryLockFile()); } public function testGetComposerJsonFileAndManipulator(): void { [$json, $manipulator] = Discovery::getComposerJsonFileAndManipulator(); - $this->assertInstanceOf(JsonFile::class, $json); - $this->assertInstanceOf(JsonManipulator::class, $manipulator); + static::assertInstanceOf(JsonFile::class, $json); + static::assertInstanceOf(JsonManipulator::class, $manipulator); } public function testGetSubscribedEvents(): void { - $this->assertCount(13, Discovery::getSubscribedEvents()); + static::assertCount(13, Discovery::getSubscribedEvents()); } public function testActivate(): void @@ -160,10 +160,10 @@ public function testActivate(): void $this->discovery->activate($this->composerMock, $this->ioMock); - $this->assertInstanceOf(Lock::class, $this->discovery->getLock()); - $this->assertInstanceOf(Configurator::class, $this->discovery->getConfigurator()); + static::assertInstanceOf(Lock::class, $this->discovery->getLock()); + static::assertInstanceOf(Configurator::class, $this->discovery->getConfigurator()); - $this->assertSame( + static::assertSame( [ 'This file locks the discovery information of your project to a known state', 'This file is @generated automatically', diff --git a/tests/Discovery/Installer/ConfiguratorInstallerTest.php b/tests/Discovery/Installer/ConfiguratorInstallerTest.php index cd84fdad..a4fb11b4 100644 --- a/tests/Discovery/Installer/ConfiguratorInstallerTest.php +++ b/tests/Discovery/Installer/ConfiguratorInstallerTest.php @@ -96,7 +96,7 @@ protected function setUp(): void public function testSupports(): void { - $this->assertTrue($this->configuratorInstaller->supports('discovery-configurator')); + static::assertTrue($this->configuratorInstaller->supports('discovery-configurator')); } public function testInstallWithEmptyPsr4(): void diff --git a/tests/Discovery/Installer/QuestionInstallationManagerTest.php b/tests/Discovery/Installer/QuestionInstallationManagerTest.php index 2ec934ec..94939c51 100644 --- a/tests/Discovery/Installer/QuestionInstallationManagerTest.php +++ b/tests/Discovery/Installer/QuestionInstallationManagerTest.php @@ -14,8 +14,8 @@ use Composer\Repository\WritableRepositoryInterface; use Composer\Semver\VersionParser; use Mockery\MockInterface; +use Narrowspark\Discovery\Common\Installer\InstallationManager; use Narrowspark\Discovery\Common\Package; -use Narrowspark\Discovery\Installer\InstallationManager; use Narrowspark\Discovery\OperationsResolver; use Narrowspark\Discovery\Test\Fixtures\ComposerJsonFactory; use Narrowspark\Discovery\Test\Fixtures\MockedQuestionInstallationManager; @@ -125,7 +125,7 @@ public function testInstallOnDisabledInteractive(): void $jsonData['extra']['discovery']['extra-dependency'] ); - $this->assertCount(0, $packages); + static::assertCount(0, $packages); } public function testInstallWithEmptyDependencies(): void @@ -145,7 +145,7 @@ public function testInstallWithEmptyDependencies(): void [] ); - $this->assertCount(0, $packages); + static::assertCount(0, $packages); } public function testInstallWithAEmptyQuestion(): void @@ -281,7 +281,7 @@ public function testInstallWithPackageNameAndVersionWithStablePackageVersions(): ); $this->assertPackagesInstall($packages, 'dev-master'); - $this->assertCount(1, $questionInstallationManager->getPackagesToInstall()); + static::assertCount(1, $questionInstallationManager->getPackagesToInstall()); } public function testInstallSkipPackageInstallIfPackageIsInRootPackage(): void @@ -360,8 +360,8 @@ public function testInstallSkipPackageInstallIfPackageIsInRootPackage(): void $jsonData['extra']['discovery']['extra-dependency'] ); - $this->assertCount(0, $packages); - $this->assertCount(0, $questionInstallationManager->getPackagesToInstall()); + static::assertCount(0, $packages); + static::assertCount(0, $questionInstallationManager->getPackagesToInstall()); } public function testInstallWithPackageNameVersionAndDevStability(): void @@ -566,7 +566,7 @@ public function testInstallCanAddQuestionPackageToRootComposerJson(): void $package->getConfiguratorOptions('extra-dependency') ); - $this->assertCount(1, $packages); + static::assertCount(1, $packages); } public function testUninstall(): void @@ -689,8 +689,8 @@ public function testUninstall(): void $packages = $questionInstallationManager->uninstall($package, ['viserio/view' => 'dev-master']); $jsonData = ComposerJsonFactory::jsonFileToArray($this->composerJsonWithRequiresPath); - $this->assertArrayHasKey('viserio/bus', $jsonData['require']); - $this->assertCount(2, $packages); + static::assertArrayHasKey('viserio/bus', $jsonData['require']); + static::assertCount(2, $packages); } /** @@ -842,8 +842,8 @@ private function assertPackagesInstall(array $packages, string $version): void { $jsonData = $jsonData = ComposerJsonFactory::jsonFileToArray($this->manipulatedComposerPath); - $this->assertSame(['viserio/routing' => $version], $jsonData['require']); - $this->assertCount(1, $packages); + static::assertSame(['viserio/routing' => $version], $jsonData['require']); + static::assertCount(1, $packages); } /** diff --git a/tests/Discovery/LockTest.php b/tests/Discovery/LockTest.php index 6c7952d1..daad59ba 100644 --- a/tests/Discovery/LockTest.php +++ b/tests/Discovery/LockTest.php @@ -36,7 +36,7 @@ public function testAdd(): void { $this->lock->add('test', ['version' => '1']); - $this->assertTrue($this->lock->has('test')); + static::assertTrue($this->lock->has('test')); } public function testRemove(): void @@ -45,19 +45,19 @@ public function testRemove(): void $this->lock->remove('testRemove'); - $this->assertFalse($this->lock->has('testRemove')); + static::assertFalse($this->lock->has('testRemove')); } public function testWriteAndRead(): void { $this->lock->write(); - $this->assertCount(0, $this->lock->read()); + static::assertCount(0, $this->lock->read()); $this->lock->add('tests', ['version' => '3']); $this->lock->write(); - $this->assertCount(1, $this->lock->read()); + static::assertCount(1, $this->lock->read()); } public function testGet(): void @@ -70,8 +70,8 @@ public function testGet(): void $this->lock->add('hash', $execptedHash); - $this->assertSame($execptedArray, $this->lock->get('test')); - $this->assertSame($execptedHash, $this->lock->get('hash')); - $this->assertNull($this->lock->get('test2')); + static::assertSame($execptedArray, $this->lock->get('test')); + static::assertSame($execptedHash, $this->lock->get('hash')); + static::assertNull($this->lock->get('test2')); } } diff --git a/tests/Discovery/OperationsResolverTest.php b/tests/Discovery/OperationsResolverTest.php index a9368b31..d4eeb1b9 100644 --- a/tests/Discovery/OperationsResolverTest.php +++ b/tests/Discovery/OperationsResolverTest.php @@ -138,21 +138,21 @@ public function testResolve(): void $package = $packages['install']; - $this->assertSame('install', $package->getName()); - $this->assertSame('1', $package->getVersion()); - $this->assertSame('library', $package->getType()); - $this->assertSame('example.local', $package->getUrl()); - $this->assertSame('install', $package->getOperation()); - $this->assertTrue($package->isExtraDependency()); + static::assertSame('install', $package->getName()); + static::assertSame('1', $package->getVersion()); + static::assertSame('library', $package->getType()); + static::assertSame('example.local', $package->getUrl()); + static::assertSame('install', $package->getOperation()); + static::assertTrue($package->isExtraDependency()); $package = $packages['uninstall']; - $this->assertSame('uninstall', $package->getName()); - $this->assertSame('1.0-dev', $package->getVersion()); - $this->assertSame('provider', $package->getType()); - $this->assertSame('example.local', $package->getUrl()); - $this->assertSame('uninstall', $package->getOperation()); - $this->assertSame(['foo/bar'], $package->getRequires()); + static::assertSame('uninstall', $package->getName()); + static::assertSame('1.0-dev', $package->getVersion()); + static::assertSame('provider', $package->getType()); + static::assertSame('example.local', $package->getUrl()); + static::assertSame('uninstall', $package->getOperation()); + static::assertSame(['foo/bar'], $package->getRequires()); } /** diff --git a/tests/Discovery/PackageConfiguratorTest.php b/tests/Discovery/PackageConfiguratorTest.php index ad335509..7523952e 100644 --- a/tests/Discovery/PackageConfiguratorTest.php +++ b/tests/Discovery/PackageConfiguratorTest.php @@ -47,7 +47,7 @@ public function testAddConfigurators(): void $property = $ref->getProperty('configurators'); $property->setAccessible(true); - $this->assertArrayHasKey('mock', $property->getValue($configurator)); + static::assertArrayHasKey('mock', $property->getValue($configurator)); } public function testAddWithoutConfiguratorContractClass(): void diff --git a/tests/Discovery/Prefetcher/ParallelDownloaderTest.php b/tests/Discovery/Prefetcher/ParallelDownloaderTest.php index d0d66561..bccbadd1 100644 --- a/tests/Discovery/Prefetcher/ParallelDownloaderTest.php +++ b/tests/Discovery/Prefetcher/ParallelDownloaderTest.php @@ -42,14 +42,14 @@ public function testOptions(): void $options = $this->parallelDownloader->getOptions(); // reset to default after call - $this->assertCount(1, $this->parallelDownloader->getOptions()); + static::assertCount(1, $this->parallelDownloader->getOptions()); - $this->assertArrayHasKey('ssl', $options); - $this->assertCount(2, $options); + static::assertArrayHasKey('ssl', $options); + static::assertCount(2, $options); } public function testGetLastHeaders(): void { - $this->assertNull($this->parallelDownloader->getLastHeaders()); + static::assertNull($this->parallelDownloader->getLastHeaders()); } } diff --git a/tests/Discovery/QuestionFactoryTest.php b/tests/Discovery/QuestionFactoryTest.php index ecc690ed..2ac66aca 100644 --- a/tests/Discovery/QuestionFactoryTest.php +++ b/tests/Discovery/QuestionFactoryTest.php @@ -12,7 +12,7 @@ final class QuestionFactoryTest extends TestCase { public function testGetPackageQuestion(): void { - $this->assertSame( + static::assertSame( ' Review the package from www.example.com. Do you want to execute this package? [y] Yes @@ -26,11 +26,11 @@ public function testGetPackageQuestion(): void public function testValidatePackageQuestionAnswer(): void { - $this->assertSame('n', QuestionFactory::validatePackageQuestionAnswer(null)); - $this->assertSame('n', QuestionFactory::validatePackageQuestionAnswer('n')); - $this->assertSame('y', QuestionFactory::validatePackageQuestionAnswer('y')); - $this->assertSame('a', QuestionFactory::validatePackageQuestionAnswer('a')); - $this->assertSame('p', QuestionFactory::validatePackageQuestionAnswer('p')); + static::assertSame('n', QuestionFactory::validatePackageQuestionAnswer(null)); + static::assertSame('n', QuestionFactory::validatePackageQuestionAnswer('n')); + static::assertSame('y', QuestionFactory::validatePackageQuestionAnswer('y')); + static::assertSame('a', QuestionFactory::validatePackageQuestionAnswer('a')); + static::assertSame('p', QuestionFactory::validatePackageQuestionAnswer('p')); } public function testValidatePackageQuestionAnswerThrowException(): void @@ -38,6 +38,6 @@ public function testValidatePackageQuestionAnswerThrowException(): void $this->expectException(\Narrowspark\Discovery\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid choice'); - $this->assertSame('n', QuestionFactory::validatePackageQuestionAnswer('0')); + static::assertSame('n', QuestionFactory::validatePackageQuestionAnswer('0')); } }