11<?php
22
3- use Assert \Assertion ;
43use Behat \Behat \Context \Context ;
54use Behat \Behat \Context \SnippetAcceptingContext ;
65use Behat \Gherkin \Node \PyStringNode ;
6+ use Behat \Gherkin \Node \TableNode ;
77use Matthias \SymfonyConsoleForm \Tests \AppKernel ;
8- use Matthias \SymfonyConsoleForm \Tests \Helper \ApplicationTester ;
98use Matthias \SymfonyConsoleForm \Tests \Helper \StringUtil ;
9+ use PHPUnit \Framework \Assert ;
1010use Symfony \Bundle \FrameworkBundle \Console \Application ;
11+ use Symfony \Component \Console \Tester \ApplicationTester ;
1112
1213/**
1314 * Defines application features from the specific context.
@@ -37,15 +38,17 @@ public function __construct()
3738
3839 $ kernel = new AppKernel ('test ' , true );
3940 $ this ->application = new Application ($ kernel );
41+ $ this ->application ->setAutoExit (false );
4042 $ this ->tester = new ApplicationTester ($ this ->application );
4143 }
4244
4345 /**
4446 * @Given /^I run the command "([^"]*)" and I provide as input$/
4547 */
46- public function iRunTheCommandAndIProvideAsInput ($ name , PyStringNode $ input )
48+ public function iRunTheCommandAndIProvideAsInput ($ name , TableNode $ input )
4749 {
48- $ this ->runCommandWithInteractiveInput ($ name , $ input );
50+ $ inputs = array_column ($ input ->getHash (), 'Input ' );
51+ $ this ->runCommandWithInteractiveInput ($ name , $ inputs );
4952 }
5053
5154 /**
@@ -61,33 +64,38 @@ public function iRunTheCommandAndIProvideAsInputOneLine($name, $input)
6164 */
6265 public function theOutputShouldBe (PyStringNode $ expectedOutput )
6366 {
64- Assertion:: same (
65- StringUtil::trimLines ($ this -> getOutput () ),
66- StringUtil::trimLines (( string ) $ expectedOutput )
67+ Assert:: assertEquals (
68+ StringUtil::trimLines (( string ) $ expectedOutput ),
69+ StringUtil::trimLines ($ this -> getOutput () )
6770 );
6871 }
6972
70- private function runCommandWithInteractiveInput ($ name , $ input )
73+ private function runCommandWithInteractiveInput ($ name , array $ inputs )
7174 {
72- $ input = str_replace ('[enter] ' , "\n" , $ input );
73- $ this ->tester ->putToInputStream ($ input );
74- $ this ->tester ->run ($ name , array ('interactive ' => true , 'decorated ' => false ));
75+ $ this ->tester ->setInputs ($ inputs );
76+ $ this ->tester ->run (['command ' => $ name ], array ('interactive ' => true , 'decorated ' => false ));
7577 }
7678
7779 /**
7880 * @Then /^the output should contain$/
7981 */
8082 public function theOutputShouldContain (PyStringNode $ expectedOutput )
8183 {
82- Assertion::contains (StringUtil::trimLines ($ this ->getOutput ()), StringUtil::trimLines ((string ) $ expectedOutput ));
84+ Assert::assertStringContainsString (
85+ StringUtil::trimLines ((string ) $ expectedOutput ),
86+ StringUtil::trimLines ($ this ->getOutput ())
87+ );
8388 }
8489
8590 /**
8691 * @Then /^the output should not contain$/
8792 */
8893 public function theOutputShouldNotContain (PyStringNode $ expectedOutput )
8994 {
90- Assertion::false (strpos (StringUtil::trimLines ($ this ->getOutput ()), StringUtil::trimLines ((string ) $ expectedOutput )));
95+ Assert::assertStringNotContainsString (
96+ StringUtil::trimLines ($ this ->getOutput ()),
97+ StringUtil::trimLines ((string ) $ expectedOutput )
98+ );
9199 }
92100
93101 private function getOutput ()
@@ -100,27 +108,34 @@ private function getOutput()
100108 */
101109 public function theCommandHasFinishedSuccessfully ()
102110 {
103- Assertion:: same ( $ this ->tester ->getStatusCode (), 0 );
111+ Assert:: assertEquals ( 0 , $ this ->tester ->getStatusCode ());
104112 }
105113
106114 /**
107115 * @Then /^the command was not successful$/
108116 */
109117 public function theCommandWasNotSuccessful ()
110118 {
111- Assertion:: notSame ( $ this ->tester ->getStatusCode (), 0 );
119+ Assert:: assertNotEquals ( 0 , $ this ->tester ->getStatusCode ());
112120 }
113121
114122 /**
115- * @When /^I run the command "([^"]*)" non\ -interactively$/
123+ * @When /^I run a command non-interactively with parameters $/
116124 */
117- public function iRunTheCommandNonInteractively ($ command )
125+ public function iRunTheCommandNonInteractively (TableNode $ parameters )
118126 {
119- $ this ->runCommandWithNonInteractiveInput ($ command );
127+ $ parameters = $ parameters ->getHash ();
128+
129+ $ input = array_combine (
130+ array_column ($ parameters , 'Parameter ' ),
131+ array_column ($ parameters , 'Value ' )
132+ );
133+
134+ $ this ->runCommandWithNonInteractiveInput ($ input );
120135 }
121136
122- private function runCommandWithNonInteractiveInput ($ name )
137+ private function runCommandWithNonInteractiveInput (array $ input )
123138 {
124- $ this ->tester ->run ($ name , array ('interactive ' => false , 'decorated ' => false ));
139+ $ this ->tester ->run ($ input , array ('interactive ' => false , 'decorated ' => false ));
125140 }
126141}
0 commit comments