File tree 2 files changed +30
-1
lines changed
src/Symfony/Component/Console 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -39,4 +39,17 @@ protected function failureDescription($other): string
39
39
{
40
40
return 'the command ' .$ this ->toString ();
41
41
}
42
+
43
+ /**
44
+ * {@inheritdoc}
45
+ */
46
+ protected function additionalFailureDescription ($ other ): string
47
+ {
48
+ $ mapping = [
49
+ Command::FAILURE => 'Command failed. ' ,
50
+ Command::INVALID => 'Command was invalid. ' ,
51
+ ];
52
+
53
+ return $ mapping [$ other ] ?? sprintf ('Command returned exit status %d. ' , $ other );
54
+ }
42
55
}
Original file line number Diff line number Diff line change @@ -26,15 +26,31 @@ public function testConstraint()
26
26
$ this ->assertTrue ($ constraint ->evaluate (Command::SUCCESS , '' , true ));
27
27
$ this ->assertFalse ($ constraint ->evaluate (Command::FAILURE , '' , true ));
28
28
$ this ->assertFalse ($ constraint ->evaluate (Command::INVALID , '' , true ));
29
+ }
30
+
31
+ /**
32
+ * @dataProvider providesUnsuccessful
33
+ */
34
+ public function testUnsuccessfulCommand (string $ expectedException , int $ exitCode )
35
+ {
36
+ $ constraint = new CommandIsSuccessful ();
29
37
30
38
try {
31
- $ constraint ->evaluate (Command:: FAILURE );
39
+ $ constraint ->evaluate ($ exitCode );
32
40
} catch (ExpectationFailedException $ e ) {
33
41
$ this ->assertStringContainsString ('Failed asserting that the command is successful. ' , TestFailure::exceptionToString ($ e ));
42
+ $ this ->assertStringContainsString ($ expectedException , TestFailure::exceptionToString ($ e ));
34
43
35
44
return ;
36
45
}
37
46
38
47
$ this ->fail ();
39
48
}
49
+
50
+ public function providesUnsuccessful (): iterable
51
+ {
52
+ yield 'Failed ' => ['Command failed. ' , Command::FAILURE ];
53
+ yield 'Invalid ' => ['Command was invalid. ' , Command::INVALID ];
54
+ yield 'Exit code 3 ' => ['Command returned exit status 3. ' , 3 ];
55
+ }
40
56
}
You can’t perform that action at this time.
0 commit comments