-
Notifications
You must be signed in to change notification settings - Fork 4
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 #188 from lemberg/issue/173-use-post-install-update
Add functional tests covering install & update managers
- Loading branch information
Showing
31 changed files
with
1,400 additions
and
16 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
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
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
71 changes: 71 additions & 0 deletions
71
tests/Functional/Config/Manager/AbstractConfigManagerTest.php
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,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Tests\Functional\Draft\Environment\Config\Manager; | ||
|
||
use Composer\Json\JsonFile; | ||
use Lemberg\Draft\Environment\App; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
|
||
/** | ||
* Base configuration manager test. | ||
* | ||
* @coversNothing | ||
*/ | ||
abstract class AbstractConfigManagerTest extends TestCase { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $workingDir; | ||
|
||
/** | ||
* @var \Symfony\Component\Filesystem\Filesystem | ||
*/ | ||
protected $fs; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $basePath; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
|
||
$this->workingDir = sys_get_temp_dir() . '/draft-environment'; | ||
|
||
$this->fs = new Filesystem(); | ||
$this->fs->remove($this->workingDir); | ||
$this->fs->mkdir($this->workingDir); | ||
} | ||
|
||
/** | ||
* Asserts that composer.lock exists and contains correct data in the package | ||
* extra section. | ||
*/ | ||
final protected function assertComposerLockContainsPackageExtra(): void { | ||
self::assertFileExists("$this->workingDir/composer.lock"); | ||
|
||
$composer_lock = new JsonFile("$this->workingDir/composer.lock"); | ||
$decoded_composer_lock = $composer_lock->read(); | ||
|
||
$key = array_search(App::PACKAGE_NAME, array_column($decoded_composer_lock['packages-dev'], 'name'), TRUE); | ||
|
||
self::assertTrue($decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['already-installed']); | ||
self::assertSame(3, $decoded_composer_lock['packages-dev'][$key]['extra']['draft-environment']['last-update-weight']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
final protected function tearDown(): void { | ||
$this->fs->remove($this->workingDir); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
} |
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,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Tests\Functional\Draft\Environment\Config\Manager; | ||
|
||
use Lemberg\Draft\Environment\App; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Tests Draft Environment configuration update manager. | ||
* | ||
* @coversNothing | ||
*/ | ||
final class ConfigManagerTest extends AbstractConfigManagerTest { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
// Build path to the test composer.json file based on this class name. | ||
$this->basePath = './tests/fixtures/Functional' . str_replace('\\', DIRECTORY_SEPARATOR, substr(__CLASS__, strlen('Lemberg\Tests\Functional\Draft\Environment'))); | ||
} | ||
|
||
/** | ||
* Tests that package update does set up correct data in the package extra. | ||
* | ||
* @param string $directory | ||
* | ||
* @testWith ["update-before-update-manager"] | ||
* ["update-after-update-manager"] | ||
*/ | ||
public function testComposerUpdate(string $directory): void { | ||
|
||
$this->fs->mirror("$this->basePath/$directory", $this->workingDir, NULL, ['override' => TRUE]); | ||
|
||
// Link package working directory, so tests runs against the proper | ||
// source code. | ||
(new Process([ | ||
'vendor/bin/composer', 'config', | ||
'repositories.test', json_encode([ | ||
'type' => 'path', | ||
'url' => getcwd(), | ||
'options' => [ | ||
'symlink' => FALSE, | ||
], | ||
]), | ||
'--working-dir', $this->workingDir, | ||
])) | ||
->mustRun(); | ||
|
||
// Run composer install. | ||
(new Process([ | ||
'vendor/bin/composer', 'install', | ||
'--prefer-dist', | ||
'--no-interaction', | ||
'--no-suggest', | ||
'--working-dir', $this->workingDir, | ||
])) | ||
->mustRun(); | ||
|
||
// Get the current working branch to test against. | ||
$working_branch = (new Process([ | ||
'git', 'rev-parse', '--abbrev-ref', 'HEAD', | ||
])) | ||
->mustRun() | ||
->getOutput(); | ||
|
||
// Update the package by requiring the latest dev version. | ||
(new Process([ | ||
'vendor/bin/composer', 'require', | ||
'--dev', App::PACKAGE_NAME . ':' . rtrim($working_branch) . '-dev', | ||
'--no-suggest', | ||
'--working-dir', $this->workingDir, | ||
])) | ||
->mustRun(); | ||
|
||
$this->assertComposerLockContainsPackageExtra(); | ||
} | ||
|
||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lemberg\Tests\Functional\Draft\Environment\Config\Manager; | ||
|
||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* Tests Draft Environment configuration install manager. | ||
* | ||
* @coversNothing | ||
*/ | ||
final class InstallManagerTest extends AbstractConfigManagerTest { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
// Build path to the test composer.json file based on this class name. | ||
$this->basePath = './tests/fixtures/Functional' . str_replace('\\', DIRECTORY_SEPARATOR, substr(__CLASS__, strlen('Lemberg\Tests\Functional\Draft\Environment'))); | ||
} | ||
|
||
/** | ||
* Tests that package installation does set up correct data in the package | ||
* extra. | ||
*/ | ||
public function testComposerInstall(): void { | ||
|
||
$this->fs->mirror($this->basePath, $this->workingDir, NULL, ['override' => TRUE]); | ||
|
||
// Link package working directory, so tests runs against the proper | ||
// source code. | ||
(new Process([ | ||
'vendor/bin/composer', 'config', | ||
'repositories.test', json_encode([ | ||
'type' => 'path', | ||
'url' => getcwd(), | ||
'options' => [ | ||
'symlink' => FALSE, | ||
], | ||
]), | ||
'--working-dir', $this->workingDir, | ||
])) | ||
->mustRun(); | ||
|
||
// Run composer install. | ||
(new Process([ | ||
'vendor/bin/composer', 'install', | ||
'--prefer-dist', | ||
'--no-interaction', | ||
'--no-suggest', | ||
'--working-dir', $this->workingDir, | ||
])) | ||
->mustRun(); | ||
|
||
$this->assertComposerLockContainsPackageExtra(); | ||
} | ||
|
||
} |
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
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
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
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
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
Oops, something went wrong.