Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb74d1dd

Browse files
committed
Implement TestTrait::assertCommandIsSuccessful() helper
1 parente1b352e commitb74d1dd

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

‎src/Symfony/Component/Console/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.4
5+
---
6+
7+
* Add`TesterTrait::assertCommandIsSuccessful()` to test command
8+
49
5.3
510
---
611

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Console\Tester\Constraint;
13+
14+
usePHPUnit\Framework\Constraint\Constraint;
15+
useSymfony\Component\Console\Command\Command;
16+
17+
finalclass CommandIsSuccessfulextends Constraint
18+
{
19+
/**
20+
* {@inheritdoc}
21+
*/
22+
publicfunctiontoString():string
23+
{
24+
return'is successful';
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protectedfunctionmatches($other):bool
31+
{
32+
return Command::SUCCESS ===$other;
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protectedfunctionfailureDescription($other):string
39+
{
40+
return'the command'.$this->toString();
41+
}
42+
}

‎src/Symfony/Component/Console/Tester/TesterTrait.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111

1212
namespaceSymfony\Component\Console\Tester;
1313

14+
usePHPUnit\Framework\Assert;
1415
useSymfony\Component\Console\Input\InputInterface;
1516
useSymfony\Component\Console\Output\ConsoleOutput;
1617
useSymfony\Component\Console\Output\OutputInterface;
1718
useSymfony\Component\Console\Output\StreamOutput;
19+
useSymfony\Component\Console\Tester\Constraint\CommandIsSuccessful;
1820

1921
/**
2022
* @author Amrouche Hamza <hamza.simperfit@gmail.com>
@@ -110,6 +112,11 @@ public function getStatusCode()
110112
return$this->statusCode;
111113
}
112114

115+
publicfunctionassertCommandIsSuccessful(string$message =''):void
116+
{
117+
Assert::assertThat($this->statusCode,newCommandIsSuccessful(),$message);
118+
}
119+
113120
/**
114121
* Sets the user inputs.
115122
*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Console\Tests\Tester\Constraint;
13+
14+
usePHPUnit\Framework\ExpectationFailedException;
15+
usePHPUnit\Framework\TestCase;
16+
usePHPUnit\Framework\TestFailure;
17+
useSymfony\Component\Console\Command\Command;
18+
useSymfony\Component\Console\Tester\Constraint\CommandIsSuccessful;
19+
20+
finalclass CommandIsSuccessfulTestextends TestCase
21+
{
22+
publicfunctiontestConstraint()
23+
{
24+
$constraint =newCommandIsSuccessful();
25+
26+
$this->assertTrue($constraint->evaluate(Command::SUCCESS,'',true));
27+
$this->assertFalse($constraint->evaluate(Command::FAILURE,'',true));
28+
$this->assertFalse($constraint->evaluate(Command::INVALID,'',true));
29+
30+
try {
31+
$constraint->evaluate(Command::FAILURE);
32+
}catch (ExpectationFailedException$e) {
33+
$this->assertStringContainsString('Failed asserting that the command is successful.', TestFailure::exceptionToString($e));
34+
35+
return;
36+
}
37+
38+
$this->fail();
39+
}
40+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp