listCommand = new CommandTester(Container::testFactory()->get(RepositoryListCommand::class)); $this->addCommand = new CommandTester(Container::testFactory()->get(RepositoryAddCommand::class)); $this->removeCommand = new CommandTester(Container::testFactory()->get(RepositoryRemoveCommand::class)); $this->addCommand->execute([ 'type' => 'composer', 'url' => self::PACKAGIST_ORG_URL, ]); $this->removeCommand->execute(['url' => self::EXAMPLE_PATH_REPOSITORY_URL]); $this->removeCommand->execute(['url' => self::EXAMPLE_VCS_REPOSITORY_URL]); $this->removeCommand->execute(['url' => self::EXAMPLE_VCS_REPOSITORY_URL . '.git']); } public function testPathRepositoriesCanBeManaged(): void { $this->assertRepositoryListDisplayed(['Packagist']); $this->addCommand->execute([ 'type' => 'path', 'url' => self::EXAMPLE_PATH_REPOSITORY_URL, ]); $this->assertRepositoryListDisplayed( [ 'Path Repository (' . self::EXAMPLE_PATH_REPOSITORY_URL . ')', 'Packagist', ], ); $this->removeCommand->execute(['url' => self::EXAMPLE_PATH_REPOSITORY_URL]); $this->assertRepositoryListDisplayed(['Packagist']); } public function testPathRepositoriesWithTrailingSlashesCanBeManaged(): void { $this->assertRepositoryListDisplayed(['Packagist']); $this->addCommand->execute([ 'type' => 'path', 'url' => self::EXAMPLE_PATH_REPOSITORY_URL . '/', ]); $this->assertRepositoryListDisplayed( [ 'Path Repository (' . self::EXAMPLE_PATH_REPOSITORY_URL . ')', 'Packagist', ], ); $this->removeCommand->execute(['url' => self::EXAMPLE_PATH_REPOSITORY_URL . '/']); $this->assertRepositoryListDisplayed(['Packagist']); } public function testVcsRepositoriesCanBeManaged(): void { $this->assertRepositoryListDisplayed(['Packagist']); $this->addCommand->execute([ 'type' => 'vcs', 'url' => self::EXAMPLE_VCS_REPOSITORY_URL, ]); $this->assertRepositoryListDisplayed( [ 'VCS Repository (' . self::EXAMPLE_VCS_REPOSITORY_URL . '.git)', 'Packagist', ], ); $this->removeCommand->execute(['url' => self::EXAMPLE_VCS_REPOSITORY_URL]); $this->assertRepositoryListDisplayed(['Packagist']); } public function testPackagistOrgCanBeManaged(): void { $this->assertRepositoryListDisplayed(['Packagist']); $this->removeCommand->execute(['url' => self::PACKAGIST_ORG_URL]); $this->assertRepositoryListDisplayed([]); $this->addCommand->execute([ 'type' => 'composer', 'url' => self::PACKAGIST_ORG_URL, ]); $this->assertRepositoryListDisplayed(['Packagist']); } /** @param list $expectedRepositories */ private function assertRepositoryListDisplayed(array $expectedRepositories): void { $this->listCommand->execute([]); $this->listCommand->assertCommandIsSuccessful(); $outputString = $this->listCommand->getDisplay(); self::assertEquals( $expectedRepositories, array_values(array_map( static fn ($line) => substr($line, 4), array_filter( explode(PHP_EOL, $outputString), static fn ($line): bool => str_starts_with($line, ' - '), ), )), ); } }