diff --git a/core/tests/Drupal/Tests/Core/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Core/Scripts/TestSiteApplicationTest.php index 1f7977f4a3..8019953a82 100644 --- a/core/tests/Drupal/Tests/Core/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Core/Scripts/TestSiteApplicationTest.php @@ -39,53 +39,6 @@ protected function setUp() { $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); } - /** - * @coversNothing - */ - public function testInstallWithNonExistingFile() { - $php_binary_finder = new PhpExecutableFinder(); - $php_binary_path = $php_binary_finder->find(); - - $command_line = $php_binary_path . ' core/scripts/test-site.php install --setup-file "this-class-does-not-exist" --db-url "' . getenv('SIMPLETEST_DB') . '"'; - $process = new Process($command_line, $this->root); - $process->run(); - - $this->assertContains('The file this-class-does-not-exist does not exist.', $process->getErrorOutput()); - $this->assertSame(1, $process->getExitCode()); - } - - /** - * @coversNothing - */ - public function testInstallWithFileWithNoClass() { - $php_binary_finder = new PhpExecutableFinder(); - $php_binary_path = $php_binary_finder->find(); - - $command_line = $php_binary_path . ' core/scripts/test-site.php install --setup-file core/tests/fixtures/empty_file.php.module --db-url "' . getenv('SIMPLETEST_DB') . '"'; - $process = new Process($command_line, $this->root); - $process->run(); - - $this->assertContains('The file core/tests/fixtures/empty_file.php.module does not contain a class', $process->getErrorOutput()); - $this->assertSame(1, $process->getExitCode()); - } - - /** - * @coversNothing - */ - public function testInstallWithNonSetupClass() { - $php_binary_finder = new PhpExecutableFinder(); - $php_binary_path = $php_binary_finder->find(); - - // Use __FILE__ to test absolute paths. - $command_line = $php_binary_path . ' core/scripts/test-site.php install --setup-file "' . __FILE__ . '" --db-url "' . getenv('SIMPLETEST_DB') . '"'; - $process = new Process($command_line, $this->root, ['COLUMNS' => PHP_INT_MAX]); - $process->run(); - - $this->assertContains('The class Drupal\Tests\Core\Scripts\TestSiteApplicationTest contained in', $process->getErrorOutput()); - $this->assertContains('needs to implement \Drupal\TestSite\TestSetupInterface', $process->getErrorOutput()); - $this->assertSame(1, $process->getExitCode()); - } - /** * @coversNothing */ diff --git a/core/tests/Drupal/Tests/Core/Scripts/TestSiteInstallCommandTest.php b/core/tests/Drupal/Tests/Core/Scripts/TestSiteInstallCommandTest.php new file mode 100644 index 0000000000..15a9c3a3fe --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Scripts/TestSiteInstallCommandTest.php @@ -0,0 +1,52 @@ + ' ['The file this-class-does-not-exist does not exist.', 'this-class-does-not-exist'], + 'no-class' => ['The file core/tests/fixtures/empty_file.php.module does not contain a class', 'core/tests/fixtures/empty_file.php.module'], + 'non-setup-class' => ["The class $class contained in $file needs to implement \\$interface", $file], + ]; + } + + /** + * @covers ::getSetupClass + * @dataProvider provideSetupFile + */ + public function testSetupFile($expected, $setup_file) { + $app = new TestSiteApplication(); + + $command = $app->find('install'); + $tester = new CommandTester($command); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage($expected); + + $tester->execute([ + 'command' => $command->getName(), + '--setup-file' => $setup_file, + ]); + } + +}