* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Test\Command; use Composer\Test\TestCase; use Generator; class HomeCommandTest extends TestCase { /** * @dataProvider useCaseProvider * @param array $composerJson * @param array $command * @param array $urls */ public function testHomeCommandWithShowFlag( array $composerJson, array $command, string $expected, array $urls = [] ): void { $this->initTempComposer($composerJson); $packages = [ 'vendor/package' => self::getPackage('vendor/package', '1.2.3'), ]; $devPackages = [ 'vendor/devpackage' => self::getPackage('vendor/devpackage', '2.3.4'), ]; if (count($urls) !== 0) { foreach ($urls as $pkg => $url) { if (isset($packages[$pkg])) { $packages[$pkg]->setHomepage($url); } if (isset($devPackages[$pkg])) { $devPackages[$pkg]->setHomepage($url); } } } $this->createInstalledJson($packages, $devPackages); $appTester = $this->getApplicationTester(); $appTester->run(array_merge(['command' => 'home', '--show' => true], $command)); self::assertSame(trim($expected), trim($appTester->getDisplay(true))); } public static function useCaseProvider(): Generator { yield 'Invalid or missing repository URL' => [ [ 'repositories' => [ 'packages' => [ 'type' => 'package', 'package' => [ ['name' => 'vendor/package', 'description' => 'generic description', 'version' => '1.0.0'], ] ] ], 'require' => [ 'vendor/package' => '^1.0' ] ], ['packages' => ['vendor/package']], <<Invalid or missing repository URL for vendor/package OUTPUT ]; yield 'No Packages Provided' => [ ['repositories' => []], [], <<Invalid or missing repository URL for __root__ OUTPUT ]; yield 'Package not found' => [ ['repositories' => []], ['packages' => ['vendor/anotherpackage']], <<Package vendor/anotherpackage not found Invalid or missing repository URL for vendor/anotherpackage OUTPUT ]; yield 'A valid package URL' => [ ['repositories' => []], ['packages' => ['vendor/package']], << 'https://example.org'], ]; yield 'A valid dev package URL' => [ ['repositories' => []], ['packages' => ['vendor/devpackage']], << 'https://example.org/dev'], ]; } }