-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from derhasi/tests
Added additional test for fixtures
- Loading branch information
Showing
3 changed files
with
182 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
|
||
namespace derhasi\Composer\Tests; | ||
|
||
use derhasi\tempdirectory\TempDirectory; | ||
|
||
/** | ||
* Tests for some examples. | ||
*/ | ||
class FixturesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $composerBin; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $fixturesRoot; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $projectRoot; | ||
|
||
/** | ||
* Set up test. | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->projectRoot = realpath(__DIR__.'/..'); | ||
$this->composerBin = realpath(__DIR__.'/../vendor/bin/composer'); | ||
$this->fixturesRoot = realpath(__DIR__.'/fixtures'); | ||
} | ||
|
||
/** | ||
* Test provided fixtures. | ||
* | ||
* @param string $folder | ||
* Name of the folder of the fixture | ||
* @param array $commands | ||
* Array of composer commands to process | ||
* @param array $files | ||
* Array of files to check for existance | ||
* | ||
* @dataProvider fixturesProvider | ||
*/ | ||
public function testFixtures($folder, $commands = array(), $files = array()) | ||
{ | ||
$workingDirectory = new TempDirectory(__METHOD__.$folder); | ||
|
||
chdir($workingDirectory->getRoot()); | ||
copy($this->fixturesRoot.'/example/composer.json', $workingDirectory->getRoot().'/composer.json'); | ||
|
||
// Add this project as local development repository sow we work with | ||
// the latest code. | ||
$this->composer('config', 'repositories.dev', 'path', $this->projectRoot); | ||
|
||
$this->composer('install'); | ||
|
||
// Run additional composer commands. | ||
foreach ($commands as $command) { | ||
call_user_func_array(array($this, 'composer'), $command); | ||
} | ||
|
||
// Check for file existance. | ||
foreach ($files as $file) { | ||
$this->assertFileExists($file); | ||
} | ||
|
||
unset($workingDirectory); | ||
} | ||
|
||
/** | ||
* Provides fixtures test data. | ||
* | ||
* @return array | ||
*/ | ||
public function fixturesProvider() | ||
{ | ||
return array( | ||
array( | ||
'example', | ||
// Update drupal/drupal to the newest release | ||
array( | ||
array('update', 'drupal/drupal'), | ||
), | ||
array( 'web/index.php', 'web/sites/all/modules/contrib/views/views.module'), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Run composer command. | ||
* | ||
* @param string $command | ||
* @param string $arg,... Optional arguments | ||
* | ||
* @return string[] | ||
* Array of output lines by the composer command. | ||
*/ | ||
protected function composer($command) | ||
{ | ||
$exec = $this->composerBin; | ||
$exec .= ' '.escapeshellcmd($command); | ||
$args = func_get_args(); | ||
array_shift($args); | ||
foreach ($args as $arg) { | ||
if (strlen($arg) > 0) { | ||
$exec .= ' '.escapeshellarg($arg); | ||
} | ||
} | ||
|
||
$output = array(); | ||
$returnCode = null; | ||
exec("$exec 2>&1", $output, $returnCode); | ||
|
||
if ($returnCode) { | ||
throw new \Exception(sprintf('Composer command "%s" failed:\n%s"', $exec, implode("\n", $output))); | ||
} | ||
|
||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "https://packages.drupal.org/7" | ||
} | ||
], | ||
"require": { | ||
"composer/installers": "^1.2", | ||
"derhasi/composer-preserve-paths": "@dev", | ||
"drupal/views": "3.*", | ||
"drupal/drupal": "7.52" | ||
}, | ||
"config": { | ||
"vendor-dir": "vendor" | ||
}, | ||
"extra": { | ||
"installer-paths": { | ||
"web/": ["type:drupal-core"], | ||
"web/sites/all/modules/contrib/{$name}/": ["type:drupal-module"], | ||
"web/sites/all/themes/contrib/{$name}/": ["type:drupal-theme"], | ||
"web/sites/all/libraries/{$name}/": ["type:drupal-library"], | ||
"web/sites/all/drush/{$name}/": ["type:drupal-drush"], | ||
"web/profiles/{$name}/": ["type:drupal-profile"] | ||
}, | ||
"preserve-paths": [ | ||
"web/sites/all/modules/contrib", | ||
"web/sites/all/themes/contrib", | ||
"web/sites/all/libraries", | ||
"web/sites/all/drush", | ||
"web/sites/default/settings.php", | ||
"web/sites/default/files" | ||
] | ||
} | ||
} |