Skip to content

Commit

Permalink
Added ability to specify project root in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed May 25, 2024
1 parent 362f22b commit 7547083
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/phpunit/Dirs.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function __construct() {
/**
* Initialize locations.
*/
public function initLocations(?callable $cb = NULL): void {
$this->root = $this->fileFindDir('composer.json', dirname(__FILE__) . '/../..');
public function initLocations(?callable $cb = NULL, string $root = NULL): void {
$this->root = $root ?: $this->fileFindDir('composer.json', dirname(__FILE__) . '/../..');
$this->fixtures = $this->root . '/tests/phpunit/Fixtures';

$this->build = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'customizer-' . microtime(TRUE);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/CustomizerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function setUp(): void {
$dirs->fs->copy($dirs->root . DIRECTORY_SEPARATOR . static::$composerJsonFile, $dirs->repo . '/composer.json');
// Copy the configuration file.
$dirs->fs->copy($dirs->root . DIRECTORY_SEPARATOR . CustomizeCommand::CONFIG_FILE, $dirs->repo . DIRECTORY_SEPARATOR . CustomizeCommand::CONFIG_FILE);
});
}, (string) getcwd());

// Projects using this project through a plugin need to have this
// repository added to their composer.json to be able to download it
Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/Traits/DirsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ trait DirsTrait {
*
* @param callable|null $cb
* Callback to run after initialization.
* @param string|null $root
* The root directory.
*/
protected function dirsInit(?callable $cb = NULL): void {
protected function dirsInit(?callable $cb = NULL, string $root = NULL): void {
$this->dirs = new Dirs();
$this->dirs->initLocations($cb);
$this->dirs->initLocations($cb, $root);
}

/**
Expand Down

0 comments on commit 7547083

Please sign in to comment.