1
0
Fork 0

Update tests

pull/11842/head
Jordi Boggiano 2024-02-07 22:37:22 +01:00
parent 754f2868fb
commit df8f9f05a3
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 40 additions and 23 deletions

View File

@ -228,7 +228,7 @@ class BaseDependencyCommandTest extends TestCase
* *
* @param array<string, string|bool> $parameters * @param array<string, string|bool> $parameters
*/ */
public function testWhyCommandOutputs(array $parameters, string $expectedOutput): void public function testWhyCommandOutputs(array $parameters, string $expectedOutput, int $expectedStatusCode): void
{ {
$packageToBeInspected = $parameters['package']; $packageToBeInspected = $parameters['package'];
$renderAsTree = $parameters['--tree'] ?? false; $renderAsTree = $parameters['--tree'] ?? false;
@ -294,9 +294,9 @@ class BaseDependencyCommandTest extends TestCase
'--locked' => true '--locked' => true
]); ]);
$appTester->assertCommandIsSuccessful(); self::assertSame($expectedStatusCode, $appTester->getStatusCode());
$this->assertEquals(trim($expectedOutput), trim($appTester->getDisplay(true))); $this->assertEquals(trim($expectedOutput), $this->trimLines($appTester->getDisplay(true)));
} }
/** /**
@ -306,7 +306,8 @@ class BaseDependencyCommandTest extends TestCase
{ {
yield 'there is no installed package depending on the package' => [ yield 'there is no installed package depending on the package' => [
['package' => 'vendor1/package1'], ['package' => 'vendor1/package1'],
'There is no installed package depending on "vendor1/package1"' 'There is no installed package depending on "vendor1/package1"',
1
]; ];
yield 'a nested package dependency' => [ yield 'a nested package dependency' => [
@ -314,7 +315,8 @@ class BaseDependencyCommandTest extends TestCase
<<<OUTPUT <<<OUTPUT
__root__ - requires vendor1/package3 (2.3.0) __root__ - requires vendor1/package3 (2.3.0)
vendor1/package2 2.3.0 requires vendor1/package3 (^1) vendor1/package2 2.3.0 requires vendor1/package3 (^1)
OUTPUT OUTPUT,
0
]; ];
yield 'a nested package dependency (tree mode)' => [ yield 'a nested package dependency (tree mode)' => [
@ -325,7 +327,8 @@ vendor1/package3 2.1.0
`--vendor1/package2 2.3.0 (requires vendor1/package3 ^1) `--vendor1/package2 2.3.0 (requires vendor1/package3 ^1)
|--__root__ (requires vendor1/package2 1.3.0) |--__root__ (requires vendor1/package2 1.3.0)
`--vendor1/package1 1.3.0 (requires vendor1/package2 ^2) `--vendor1/package1 1.3.0 (requires vendor1/package2 ^2)
OUTPUT OUTPUT,
0
]; ];
yield 'a nested package dependency (recursive mode)' => [ yield 'a nested package dependency (recursive mode)' => [
@ -335,12 +338,14 @@ __root__ - requires vendor1/package2 (1.3.0)
vendor1/package1 1.3.0 requires vendor1/package2 (^2) vendor1/package1 1.3.0 requires vendor1/package2 (^2)
__root__ - requires vendor1/package3 (2.3.0) __root__ - requires vendor1/package3 (2.3.0)
vendor1/package2 2.3.0 requires vendor1/package3 (^1) vendor1/package2 2.3.0 requires vendor1/package3 (^1)
OUTPUT OUTPUT,
0
]; ];
yield 'a simple package dev dependency' => [ yield 'a simple package dev dependency' => [
['package' => 'vendor2/package1'], ['package' => 'vendor2/package1'],
'__root__ - requires (for development) vendor2/package1 (2.*)' '__root__ - requires (for development) vendor2/package1 (2.*)',
0
]; ];
} }
@ -354,7 +359,7 @@ OUTPUT
* *
* @param array<string, string> $parameters * @param array<string, string> $parameters
*/ */
public function testWhyNotCommandOutputs(array $parameters, string $expectedOutput): void public function testWhyNotCommandOutputs(array $parameters, string $expectedOutput, int $expectedStatusCode): void
{ {
$packageToBeInspected = $parameters['package']; $packageToBeInspected = $parameters['package'];
$packageVersionToBeInspected = $parameters['version']; $packageVersionToBeInspected = $parameters['version'];
@ -411,8 +416,8 @@ OUTPUT
'version' => $packageVersionToBeInspected 'version' => $packageVersionToBeInspected
]); ]);
$appTester->assertCommandIsSuccessful(); self::assertSame($expectedStatusCode, $appTester->getStatusCode());
$this->assertSame(trim($expectedOutput), trim($appTester->getDisplay(true))); $this->assertSame(trim($expectedOutput), $this->trimLines($appTester->getDisplay(true)));
} }
/** /**
@ -426,7 +431,8 @@ OUTPUT
Package "vendor1/package1" could not be found with constraint "3.*", results below will most likely be incomplete. Package "vendor1/package1" could not be found with constraint "3.*", results below will most likely be incomplete.
__root__ - requires vendor1/package1 (1.*) __root__ - requires vendor1/package1 (1.*)
Not finding what you were looking for? Try calling `composer require "vendor1/package1:3.*" --dry-run` to get another view on the problem. Not finding what you were looking for? Try calling `composer require "vendor1/package1:3.*" --dry-run` to get another view on the problem.
OUTPUT OUTPUT,
1
]; ];
yield 'it could not found the package and there is no installed package with a specific version' => [ yield 'it could not found the package and there is no installed package with a specific version' => [
@ -435,7 +441,8 @@ OUTPUT
Package "vendor1/package1" could not be found with constraint "^1.4", results below will most likely be incomplete. Package "vendor1/package1" could not be found with constraint "^1.4", results below will most likely be incomplete.
There is no installed package depending on "vendor1/package1" in versions not matching ^1.4 There is no installed package depending on "vendor1/package1" in versions not matching ^1.4
Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.4" --dry-run` to get another view on the problem. Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.4" --dry-run` to get another view on the problem.
OUTPUT OUTPUT,
0
]; ];
yield 'there is no installed package depending on the package in versions not matching a specific version' => [ yield 'there is no installed package depending on the package in versions not matching a specific version' => [
@ -443,7 +450,8 @@ OUTPUT
<<<OUTPUT <<<OUTPUT
There is no installed package depending on "vendor1/package1" in versions not matching ^1.3 There is no installed package depending on "vendor1/package1" in versions not matching ^1.3
Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.3" --dry-run` to get another view on the problem. Not finding what you were looking for? Try calling `composer require "vendor1/package1:^1.3" --dry-run` to get another view on the problem.
OUTPUT OUTPUT,
0
]; ];
yield 'an installed package requires an incompatible version of the inspected package' => [ yield 'an installed package requires an incompatible version of the inspected package' => [
@ -451,7 +459,8 @@ OUTPUT
<<<OUTPUT <<<OUTPUT
vendor2/package2 1.0.0 requires vendor2/package3 (1.4.*) vendor2/package2 1.0.0 requires vendor2/package3 (1.4.*)
Not finding what you were looking for? Try calling `composer update "vendor2/package3:1.5.0" --dry-run` to get another view on the problem. Not finding what you were looking for? Try calling `composer update "vendor2/package3:1.5.0" --dry-run` to get another view on the problem.
OUTPUT OUTPUT,
1
]; ];
} }
} }

View File

@ -210,6 +210,14 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
return new ApplicationTester($application); return new ApplicationTester($application);
} }
/**
* Trims the entire string but also the trailing spaces off of every line
*/
protected function trimLines(string $str): string
{
return trim(Preg::replace('{^(.*?) *$}m', '$1', $str));
}
protected static function getVersionParser(): VersionParser protected static function getVersionParser(): VersionParser
{ {
if (!self::$parser) { if (!self::$parser) {