-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
276 additions
and
43 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
142 changes: 142 additions & 0 deletions
142
tests/Console/Command/Composer/ComposerCheckVersionTest.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,142 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console\Command\Composer; | ||
|
||
use Exception; | ||
use Fidry\Console\ExitCode; | ||
use Fidry\Console\Test\CommandTester; | ||
use Fidry\Console\Test\OutputAssertions; | ||
use KevinGH\Box\Composer\IncompatibleComposerVersion; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Path; | ||
use function Safe\chdir; | ||
use function Safe\getcwd; | ||
|
||
/** | ||
* @covers \KevinGH\Box\Console\Command\Composer\ComposerCheckVersion | ||
* | ||
* @internal | ||
*/ | ||
class ComposerCheckVersionTest extends TestCase | ||
{ | ||
private CommandTester $commandTester; | ||
private string $cwd; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->commandTester = CommandTester::fromConsoleCommand(new ComposerCheckVersion()); | ||
|
||
$this->cwd = getcwd(); | ||
chdir(__DIR__); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
chdir($this->cwd); | ||
} | ||
|
||
/** | ||
* @dataProvider compatibleComposerExecutableProvider | ||
*/ | ||
public function test_it_succeeds_the_check_when_the_composer_version_is_compatible( | ||
array $input, | ||
array $options, | ||
string $expectedOutput, | ||
int $expectedStatusCode, | ||
): void { | ||
$input['command'] = 'composer:check-version'; | ||
|
||
$this->commandTester->execute($input, $options); | ||
|
||
OutputAssertions::assertSameOutput( | ||
$expectedOutput, | ||
$expectedStatusCode, | ||
$this->commandTester, | ||
); | ||
} | ||
|
||
public static function compatibleComposerExecutableProvider(): iterable | ||
{ | ||
$compatibleComposerPath = Path::normalize(__DIR__.'/compatible-composer.phar'); | ||
|
||
yield 'normal verbosity' => [ | ||
[ | ||
'--composer-bin' => 'compatible-composer.phar', | ||
], | ||
[], | ||
<<<OUTPUT | ||
[info] '{$compatibleComposerPath}' '--version' '--no-ansi' | ||
[info] Version detected: 2.6.3 (Box requires ^2.2.0) | ||
OUTPUT, | ||
ExitCode::SUCCESS, | ||
]; | ||
|
||
yield 'quiet verbosity' => [ | ||
[ | ||
'--composer-bin' => 'compatible-composer.phar', | ||
], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
'', | ||
ExitCode::SUCCESS, | ||
]; | ||
|
||
yield 'no custom composer' => [ | ||
[], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
'', | ||
ExitCode::SUCCESS, | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider incompatibleComposerExecutableProvider | ||
*/ | ||
public function test_it_fails_the_check_when_the_composer_version_is_incompatible( | ||
array $input, | ||
array $options, | ||
Exception $expected, | ||
): void { | ||
$input['command'] = 'composer:check-version'; | ||
|
||
$this->expectExceptionObject($expected); | ||
|
||
$this->commandTester->execute($input, $options); | ||
} | ||
|
||
public static function incompatibleComposerExecutableProvider(): iterable | ||
{ | ||
yield 'normal verbosity' => [ | ||
[ | ||
'--composer-bin' => 'incompatible-composer.phar', | ||
], | ||
[], | ||
new IncompatibleComposerVersion( | ||
'The Composer version "2.0.14" does not satisfy the constraint "^2.2.0".', | ||
), | ||
]; | ||
|
||
yield 'quiet verbosity' => [ | ||
[ | ||
'--composer-bin' => 'incompatible-composer.phar', | ||
], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
new IncompatibleComposerVersion( | ||
'The Composer version "2.0.14" does not satisfy the constraint "^2.2.0".', | ||
), | ||
]; | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
tests/Console/Command/Composer/ComposerVendorDirTest.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,113 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console\Command\Composer; | ||
|
||
use Fidry\Console\ExitCode; | ||
use Fidry\Console\Test\CommandTester; | ||
use Fidry\Console\Test\OutputAssertions; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Filesystem\Path; | ||
use function Safe\chdir; | ||
use function Safe\getcwd; | ||
|
||
/** | ||
* @covers \KevinGH\Box\Console\Command\Composer\ComposerVendorDir | ||
* | ||
* @internal | ||
*/ | ||
class ComposerVendorDirTest extends TestCase | ||
{ | ||
private CommandTester $commandTester; | ||
private string $cwd; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->commandTester = CommandTester::fromConsoleCommand(new ComposerVendorDir()); | ||
|
||
$this->cwd = getcwd(); | ||
chdir(__DIR__); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
chdir($this->cwd); | ||
} | ||
|
||
/** | ||
* @dataProvider composerExecutableProvider | ||
*/ | ||
public function test_it_retrieves_the_vendor_bin_directory_path( | ||
array $input, | ||
array $options, | ||
string $expectedOutput, | ||
int $expectedStatusCode, | ||
): void { | ||
$input['command'] = 'composer:vendor-dir'; | ||
|
||
$this->commandTester->execute($input, $options); | ||
|
||
OutputAssertions::assertSameOutput( | ||
$expectedOutput, | ||
$expectedStatusCode, | ||
$this->commandTester, | ||
); | ||
} | ||
|
||
public static function composerExecutableProvider(): iterable | ||
{ | ||
$compatibleComposerPath = Path::normalize(__DIR__.'/compatible-composer.phar'); | ||
$incompatibleComposerPath = Path::normalize(__DIR__.'/incompatible-composer.phar'); | ||
|
||
yield 'normal verbosity' => [ | ||
[ | ||
'--composer-bin' => 'compatible-composer.phar', | ||
], | ||
[], | ||
<<<OUTPUT | ||
[info] '{$compatibleComposerPath}' 'config' 'vendor-dir' '--no-ansi' | ||
vendor | ||
OUTPUT, | ||
ExitCode::SUCCESS, | ||
]; | ||
|
||
yield 'quiet verbosity' => [ | ||
[ | ||
'--composer-bin' => 'compatible-composer.phar', | ||
], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
'', | ||
ExitCode::SUCCESS, | ||
]; | ||
|
||
yield 'no custom composer' => [ | ||
[], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
'', | ||
ExitCode::SUCCESS, | ||
]; | ||
|
||
yield 'incompatible composer executable; quiet verbosity' => [ | ||
[ | ||
'--composer-bin' => 'incompatible-composer.phar', | ||
], | ||
['verbosity' => OutputInterface::VERBOSITY_QUIET], | ||
// The output would be too unstable to test in normal verbosity | ||
'', | ||
ExitCode::SUCCESS, | ||
]; | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"$schema": "../../../../res/schema.json", | ||
|
||
"composerBin": "./composer.phar" | ||
} |
Binary file not shown.
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 @@ | ||
{} |
Binary file not shown.