Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Console] Add missing assertCommandIsFaulty assertion
- Loading branch information
1 parent
d308e2c
commit 1fa8c2f
Showing
4 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
7.1 | ||
--- | ||
|
||
* Add `assertCommandIsFaulty` assertion | ||
|
||
6.4 | ||
--- | ||
|
||
|
40 changes: 40 additions & 0 deletions
40
src/Symfony/Component/Console/Tester/Constraint/CommandIsFaulty.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,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Tester\Constraint; | ||
|
||
use PHPUnit\Framework\Constraint\Constraint; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
final class CommandIsFaulty extends Constraint | ||
{ | ||
public function toString(): string | ||
{ | ||
return 'is faulty'; | ||
} | ||
|
||
protected function matches($other): bool | ||
{ | ||
return Command::FAILURE === $other || Command::INVALID === $other; | ||
} | ||
|
||
protected function failureDescription($other): string | ||
{ | ||
return 'the command '.$this->toString(); | ||
} | ||
|
||
protected function additionalFailureDescription($other): string | ||
{ | ||
return Command::SUCCESS === $other | ||
? 'Command was successful.' | ||
: sprintf('Command returned exit status %d.', $other); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/Console/Tests/Tester/Constraint/CommandIsFaultyTest.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,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Console\Tests\Tester\Constraint; | ||
|
||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Tester\Constraint\CommandIsFaulty; | ||
|
||
final class CommandIsFaultyTest extends TestCase | ||
{ | ||
public function testConstraint() | ||
{ | ||
$constraint = new CommandIsFaulty(); | ||
|
||
$this->assertFalse($constraint->evaluate(Command::SUCCESS, returnResult: true)); | ||
$this->assertTrue($constraint->evaluate(Command::FAILURE, returnResult: true)); | ||
$this->assertTrue($constraint->evaluate(Command::INVALID, returnResult: true)); | ||
} | ||
|
||
public function testSuccessfulCommand() | ||
{ | ||
$constraint = new CommandIsFaulty(); | ||
|
||
try { | ||
$constraint->evaluate(Command::SUCCESS); | ||
} catch (ExpectationFailedException $e) { | ||
$this->assertStringContainsString('Failed asserting that the command is faulty.', $e->getMessage()); | ||
|
||
return; | ||
} | ||
|
||
$this->fail(); | ||
} | ||
} |