Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move phpunit tests (#295) #313

Merged
merged 14 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"symfony/console": "~2"
},
"autoload": {
"psr-4": {"Acquia\\Blt\\": "src/"}
"psr-4": {
"Acquia\\Blt\\": "src/",
"Drupal\\Tests\\PHPUnit\\": "tests/phpunit/src/"
}
},
"bin": [
"bin/blt",
Expand Down
4 changes: 2 additions & 2 deletions template/drush.wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ class DrushTest extends TestBase {

/**
* Tests that correct drush configuration is loaded.
*
* @group drush
*/
public function testDrushConfig() {

// We must define the absolute path of the binary because child shell
// processes in PHP to not inherit $PATH setting from environment.
$drush_bin = $this->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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea to return this as json.


// Test that drush can be run from the following directories.
$dirs = array(
Expand All @@ -29,9 +33,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']);
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ abstract class TestBase extends \PHPUnit_Framework_TestCase {
public function __construct($name = NULL, array $data = array(), $data_name = '') {

parent::__construct($name, $data, $data_name);
$this->projectDirectory = dirname(dirname(dirname(__DIR__)));
$directory = realpath(dirname(__FILE__) . '/../../../');
Copy link
Contributor

@grasmash grasmash Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely failing because of how the tests are called. They are intended to be called from the child blt-project, but they are being called from the parent blt here:
https://github.com/acquia/blt/blob/8.x/.travis.yml#L90

We'll want to tag these tests with a group like @blt-project. Then, we can run test in two sets:

- cd ../blt-project
- phpunit tests/phpunit --group blt-project
- cd ../blt 
- phpunit tests/phpunit --exclude-group blt-project

The blt-project tests can then rely on a $this->project directory variable that refers to ../../../../../../ given that the actual TestBase will live in vendor/acquia/blt/tests/phpunit/src.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused here - the tests themselves all now live in vendor/acquia/blt/phpunit/src. Running phpunit tests/phpunit from the blt-project directory does not find the tests that live in blt.

$this->projectDirectory = dirname($directory) . '/blt-project';
$this->drupalRoot = $this->projectDirectory . '/docroot';
$this->config = Yaml::parse(file_get_contents("{$this->projectDirectory}/project.yml"));
if (file_exists("{$this->projectDirectory}/project.local.yml")) {
Expand Down