core/scripts/test-site.php | 2 +- .../TestSite/Commands/TestSiteInstallCommand.php | 2 +- .../TestSite/Commands/TestSiteTearDownCommand.php | 4 +-- core/tests/Drupal/TestSite/TestSetupInterface.php | 2 +- .../Tests/Scripts/TestSiteApplicationTest.php | 33 +++++++++++++++------- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/core/scripts/test-site.php b/core/scripts/test-site.php index d3fb826..3e33fab 100644 --- a/core/scripts/test-site.php +++ b/core/scripts/test-site.php @@ -3,7 +3,7 @@ /** * @file - * A command line application to install drupal for tests. + * A command line application to install Drupal for tests. */ use Drupal\TestSite\TestSiteApplication; diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php index e61d264..6f122d8 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -188,7 +188,7 @@ protected function installDrupal() { * Uses the setup file to configure Drupal. * * @param string $class - * The full qualified class name, which should setup Drupal for tests. For + * The fully qualified class name, which should set up Drupal for tests. For * example this class could create content types and fields or install * modules. The class needs to implement TestSetupInterface. * diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php index 6dce953..e2f355b 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php @@ -92,12 +92,12 @@ protected function tearDown(TestDatabase $test_database, $db_url) { } /** - * Deletes all files and directories in the specified filepath recursively. + * Deletes all files and directories in the specified path recursively. * * Note this version has no dependencies on Drupal core to ensure that the * test site can be torn down even if something in the test site is broken. * - * @param $path + * @param string $path * A string containing either an URI or a file or directory path. * @param callable $callback * (optional) Callback function to run on each file prior to deleting it and diff --git a/core/tests/Drupal/TestSite/TestSetupInterface.php b/core/tests/Drupal/TestSite/TestSetupInterface.php index 985f267..06c9717 100644 --- a/core/tests/Drupal/TestSite/TestSetupInterface.php +++ b/core/tests/Drupal/TestSite/TestSetupInterface.php @@ -3,7 +3,7 @@ namespace Drupal\TestSite; /** - * Allows you to setup an environment as part of a test site install. + * Allows setting up an environment as part of a test site install. * * @see \Drupal\TestSite\Commands\TestSiteInstallCommand */ diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php index 9136f61..4c2444e 100644 --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -18,7 +18,7 @@ * @group Setup * * This test uses the Drupal\Core\Database\Database class which has a static. - * Therefore run in an separate process to avoid side effects. + * Therefore run in a separate process to avoid side effects. * * @runTestsInSeparateProcesses * @preserveGlobalState disabled @@ -108,8 +108,8 @@ public function testInstallScript() { // Ensure the test_page_test module got installed. $this->assertContains('Test page | Drupal', (string) $response->getBody()); - // Ensure that there are files and database tables for tear down command to - // clean up. + // Ensure that there are files and database tables for the tear down command + // to clean up. $key = $this->addTestDatabase($db_prefix); $this->assertGreaterThan(0, count(Database::getConnection('default', $key)->schema()->findTables('%'))); $test_database = new TestDatabase($db_prefix); @@ -119,8 +119,8 @@ public function testInstallScript() { // Ensure the lock file exists. $this->assertFileExists($this->getTestLockFile($db_prefix)); - // Install another site so we can ensure tear down only removes one site at - // a time. Use the regular output. + // Install another site so we can ensure the tear down command only removes + // one site at a time. Use the regular output. $command_line = $php_binary_path . ' core/scripts/test-site.php install --setup_class "' . TestSiteInstallTestScript::class . '" --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); // Set the timeout to a value that allows debugging. @@ -138,7 +138,7 @@ public function testInstallScript() { // Ensure the lock file exists for the new install. $this->assertFileExists($this->getTestLockFile($other_db_prefix)); - // Now test the tear down process as well. + // Now test the tear down process as well, but keep the lock. $command_line = $php_binary_path . ' core/scripts/test-site.php tear-down ' . $db_prefix . ' --keep_lock --db_url "' . getenv('SIMPLETEST_DB') . '"'; $process = new Process($command_line, $this->root); // Set the timeout to a value that allows debugging. @@ -157,8 +157,8 @@ public function testInstallScript() { $test_file = $this->root . DIRECTORY_SEPARATOR . $test_database->getTestSitePath() . DIRECTORY_SEPARATOR . '.htkey'; $this->assertFileExists($test_file); - // Tear down the other site installed. Tear down should work if the test - // site is broken. Prove this by removing its settings.php. + // Tear down the other site. Tear down should work if the test site is + // broken. Prove this by removing its settings.php. $test_site_settings = $this->root . DIRECTORY_SEPARATOR . $test_database->getTestSitePath() . DIRECTORY_SEPARATOR . 'settings.php'; $this->assertTrue(unlink($test_site_settings)); $command_line = $php_binary_path . ' core/scripts/test-site.php tear-down ' . $other_db_prefix . ' --db_url "' . getenv('SIMPLETEST_DB') . '"'; @@ -173,10 +173,23 @@ public function testInstallScript() { $this->assertCount(0, Database::getConnection('default', $other_key)->schema()->findTables('%')); $this->assertFileNotExists($test_file); - // The lock for the first site should still exist but the second site is - // clean up during tear down. + // The lock for the first site should still exist but the second site's lock + // is released during tear down. $this->assertFileExists($this->getTestLockFile($db_prefix)); $this->assertFileNotExists($this->getTestLockFile($other_db_prefix)); + + // Release all locks. + $command_line = $php_binary_path . ' core/scripts/test-site.php release-locks'; + $process = new Process($command_line, $this->root); + // Set the timeout to a value that allows debugging. + $process->setTimeout(500); + $process->run(); + $this->assertSame(0, $process->getExitCode()); + $this->assertContains("Successfully released all the test database locks", $process->getOutput()); + + // Both tests sites' locks should no longer exist now. + $this->assertFileNotExists($this->getTestLockFile($db_prefix)); + $this->assertFileNotExists($this->getTestLockFile($other_db_prefix)); } /**