diff --git a/.travis.yml b/.travis.yml index 7f1219dbf..b1ff6fc6b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -87,7 +87,7 @@ script: # Switch back to 'blt' directory. - cd ../blt # Run 'blt' phpunit tests, excluding deploy-push tests. - - phpunit tests/phpunit --exclude-group deploy-push + - phpunit tests/phpunit --group blt --exclude-group deploy-push deploy: provider: script diff --git a/composer.json b/composer.json index e2303829e..644d96d8f 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,10 @@ "symfony/console": "~2" }, "autoload": { - "psr-4": {"Acquia\\Blt\\": "src/"} + "psr-4": { + "Acquia\\Blt\\": "src/", + "Acquia\\Blt\\Tests\\": "tests/phpunit/src/" + } }, "bin": [ "bin/blt", diff --git a/phing/tasks/tests.xml b/phing/tasks/tests.xml index 01131321e..c05f44b18 100644 --- a/phing/tasks/tests.xml +++ b/phing/tasks/tests.xml @@ -88,6 +88,7 @@ + diff --git a/template/drush.wrapper b/template/drush.wrapper index 113b38334..727d29c17 100755 --- a/template/drush.wrapper +++ b/template/drush.wrapper @@ -45,7 +45,7 @@ fi DOCROOT=$(${DIR}/vendor/bin/blt echo-property -Dproperty.name=drush.root -S -e) if [ -z "$DOCROOT" ]; then - vendor/bin/drush.launcher --alias-path=${DIR}/drush/site-aliases "$@" + vendor/bin/drush.launcher --config=${DIR}/drush/drushrc.php --alias-path=${DIR}/drush/site-aliases "$@" else - vendor/bin/drush.launcher --alias-path=${DIR}/drush/site-aliases "$@" -r $DOCROOT + vendor/bin/drush.launcher --config=${DIR}/drush/drushrc.php --alias-path=${DIR}/drush/site-aliases "$@" -r $DOCROOT fi diff --git a/template/tests/phpunit/src/TestBase.php b/template/tests/phpunit/src/TestBase.php deleted file mode 100644 index a0da3cabe..000000000 --- a/template/tests/phpunit/src/TestBase.php +++ /dev/null @@ -1,32 +0,0 @@ -projectDirectory = dirname(dirname(dirname(__DIR__))); - $this->drupalRoot = $this->projectDirectory . '/docroot'; - $this->config = Yaml::parse(file_get_contents("{$this->projectDirectory}/project.yml")); - if (file_exists("{$this->projectDirectory}/project.local.yml")) { - $this->config = array_replace_recursive($this->config, Yaml::parse(file_get_contents("{$this->projectDirectory}/project.local.yml"))); - } - } - -} diff --git a/tests/phpunit/BltTest.php b/tests/phpunit/Blt/BltTest.php similarity index 67% rename from tests/phpunit/BltTest.php rename to tests/phpunit/Blt/BltTest.php index a74e753da..acf7e7d8b 100644 --- a/tests/phpunit/BltTest.php +++ b/tests/phpunit/Blt/BltTest.php @@ -1,8 +1,8 @@ projectDirectory = realpath(dirname(__FILE__) . '/../../'); - $this->newProjectDir = dirname($this->projectDirectory) . '/blt-project'; - $this->config = Yaml::parse(file_get_contents("{$this->newProjectDir}/project.yml")); - } +class BltTest extends BltTestBase { /** * Tests Phing pt:create target. + * + * @group blt */ public function testBltCreate() { diff --git a/tests/phpunit/DeployTest.php b/tests/phpunit/Blt/DeployTest.php similarity index 87% rename from tests/phpunit/DeployTest.php rename to tests/phpunit/Blt/DeployTest.php index d0bd801d3..7a81da404 100644 --- a/tests/phpunit/DeployTest.php +++ b/tests/phpunit/Blt/DeployTest.php @@ -1,24 +1,21 @@ projectDirectory = realpath(dirname(__FILE__) . '/../../'); - $this->newProjectDir = dirname($this->projectDirectory) . '/blt-project'; - $this->config = Yaml::parse(file_get_contents("{$this->newProjectDir}/project.yml")); + public function setUp() { + parent::setUp(); $this->deploy_dir = $this->newProjectDir . '/deploy'; } @@ -26,6 +23,7 @@ public function __construct() { * Tests Phing deploy:build:all target. * * @group deploy + * @group blt */ public function testBltDeployBuild() { @@ -63,6 +61,7 @@ public function testBltDeployBuild() { * * @group deploy * @group deploy-push + * @group blt */ public function testBltDeployPush() { diff --git a/tests/phpunit/DrupalVmTest.php b/tests/phpunit/Blt/DrupalVmTest.php similarity index 65% rename from tests/phpunit/DrupalVmTest.php rename to tests/phpunit/Blt/DrupalVmTest.php index fd3e40df4..1b6cc9a39 100644 --- a/tests/phpunit/DrupalVmTest.php +++ b/tests/phpunit/Blt/DrupalVmTest.php @@ -1,27 +1,20 @@ projectDirectory = realpath(dirname(__FILE__) . '/../../'); - $this->newProjectDir = dirname($this->projectDirectory) . '/blt-project'; - $this->config = Yaml::parse(file_get_contents("{$this->newProjectDir}/project.yml")); - } +class DrupalVmTest extends BltTestBase { /** * Tests Phing vm:init target. + * + * @group blt */ public function testVmInit() { $this->assertFileExists($this->newProjectDir . '/Vagrantfile'); diff --git a/template/tests/phpunit/Bolt/BehatTest.php b/tests/phpunit/BltProject/BehatTest.php similarity index 75% rename from template/tests/phpunit/Bolt/BehatTest.php rename to tests/phpunit/BltProject/BehatTest.php index 488951cd7..52f2742af 100644 --- a/template/tests/phpunit/Bolt/BehatTest.php +++ b/tests/phpunit/BltProject/BehatTest.php @@ -1,16 +1,20 @@ projectDirectory . '/vendor/bin/drush'; - $command = "$drush_bin status"; + // Use --format=json output so we don't have to deal with output line + // wrapping when running the tests. + $command = "$drush_bin status --format=json"; // Test that drush can be run from the following directories. $dirs = array( @@ -29,9 +35,10 @@ public function testDrushConfig() { foreach ($dirs as $dir) { chdir($dir); print "Executing \"$command\" in $dir \n"; - // If it contains the local URI, we know it is correctly loading - // drushrc.php. - $this->assertContains($this->config['project']['local']['hostname'], shell_exec($command)); + $json_output = shell_exec($command); + $drush_output = json_decode($json_output, TRUE); + // Check for the path to drushrc.php that is included in the project. + $this->assertContains($this->projectDirectory . '/drush/drushrc.php', $drush_output['drush-conf']); } } diff --git a/template/tests/phpunit/Bolt/GitTest.php b/tests/phpunit/BltProject/GitTest.php similarity index 91% rename from template/tests/phpunit/Bolt/GitTest.php rename to tests/phpunit/BltProject/GitTest.php index fd5c53fc3..d2dd281f8 100644 --- a/template/tests/phpunit/Bolt/GitTest.php +++ b/tests/phpunit/BltProject/GitTest.php @@ -1,16 +1,20 @@ assertFileExists($this->projectDirectory . '/.git'); @@ -29,6 +33,8 @@ public function testGitConfig() { * The PHPUnit message to be output for this datapoint. * * @dataProvider providerTestGitHookCommitMsg + * + * @group blt-project */ public function testGitHookCommitMsg($is_valid, $commit_message, $message = NULL) { $this->assertCommitMessageValidity($is_valid, $commit_message, $message); @@ -38,7 +44,7 @@ public function testGitHookCommitMsg($is_valid, $commit_message, $message = NULL * Data provider. */ public function providerTestGitHookCommitMsg() { - $prefix = $this->config['project']['prefix']; + $prefix = isset($this->config['project']) ? $this->config['project']['prefix'] : ''; return array( array(FALSE, "This is a bad commit.", 'Missing prefix and ticket number.'), array(FALSE, "123: This is a bad commit.", 'Missing project prefix.'), @@ -57,6 +63,8 @@ public function providerTestGitHookCommitMsg() { * Tests operation of scripts/git-hooks/pre-commit. * * Should assert that code validation via phpcs is functioning. + * + * @group blt-project */ public function testGitPreCommitHook() { // Commits must be executed inside of new project directory. diff --git a/template/tests/phpunit/Bolt/SettingsTest.php b/tests/phpunit/BltProject/SettingsTest.php similarity index 85% rename from template/tests/phpunit/Bolt/SettingsTest.php rename to tests/phpunit/BltProject/SettingsTest.php index db8401335..3e62be8b6 100644 --- a/template/tests/phpunit/Bolt/SettingsTest.php +++ b/tests/phpunit/BltProject/SettingsTest.php @@ -1,13 +1,15 @@ projectDirectory = dirname(dirname(dirname(dirname(dirname(dirname((__DIR__))))))); + } + else { + $this->projectDirectory = getcwd(); + } + + $this->drupalRoot = $this->projectDirectory . '/docroot'; + if (file_exists("{$this->projectDirectory}/project.yml")) { + $this->config = Yaml::parse(file_get_contents("{$this->projectDirectory}/project.yml")); + } + if (file_exists("{$this->projectDirectory}/project.local.yml")) { + $this->config = array_replace_recursive($this->config, Yaml::parse(file_get_contents("{$this->projectDirectory}/project.local.yml"))); + } + } + +} diff --git a/tests/phpunit/src/BltTestBase.php b/tests/phpunit/src/BltTestBase.php new file mode 100644 index 000000000..4806c2d67 --- /dev/null +++ b/tests/phpunit/src/BltTestBase.php @@ -0,0 +1,29 @@ +bltDirectory = realpath(dirname(__FILE__) . '/../../'); + $this->newProjectDir = dirname(dirname($this->bltDirectory)) . '/blt-project'; + $this->config = Yaml::parse(file_get_contents("{$this->newProjectDir}/project.yml")); + + } + +}