11<?php
22
3- /**
3+ /*
44 * Pickle
55 *
66 *
3333 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3434 * POSSIBILITY OF SUCH DAMAGE.
3535 */
36+
3637use Behat \Behat \Context \SnippetAcceptingContext ;
3738use Behat \Gherkin \Node \PyStringNode ;
3839use Symfony \Component \Process \PhpExecutableFinder ;
4546 */
4647class FeatureContext implements SnippetAcceptingContext
4748{
48- const PICKLE_BIN = 'bin/pickle ' ;
49+ protected const PICKLE_BIN = 'bin/pickle ' ;
4950
5051 private $ assert ;
52+
5153 private $ php ;
54+
5255 private $ dir ;
56+
5357 private $ workingDir ;
58+
5459 private $ process ;
5560
5661 public function __construct ()
@@ -84,49 +89,40 @@ public function prepare()
8489 $ this ->php = $ php ;
8590 }
8691
87- private function moveToNewPath ($ path )
88- {
89- $ newWorkingDir = $ this ->workingDir .'/ ' . $ path ;
90-
91- if (!file_exists ($ newWorkingDir )) {
92- mkdir ($ newWorkingDir , 0777 , true );
93- }
94-
95- $ this ->workingDir = $ newWorkingDir ;
96- }
97-
9892 /**
9993 * @Given /^I am in the "([^"]*)" path$/
10094 */
10195 public function iAmInThePath ($ path )
10296 {
10397 $ this ->moveToNewPath ($ path );
10498 }
105- /* convert Convert package.xml to new format
106- help Displays help for a command
107- info Display information about a PECL extension
108- install Install a php extension
109- list Lists commands
110- release Package a PECL extension for release
111- validate Validate a PECL extension */
99+
100+ /* convert Convert package.xml to new format
101+ help Displays help for a command
102+ info Display information about a PECL extension
103+ install Install a php extension
104+ list Lists commands
105+ release Package a PECL extension for release
106+ validate Validate a PECL extension */
107+
112108 /**
113109 * @When /^I run "pickle(?: ((?:\"|[^"])*))?"$/
114110 */
115111 public function iRunPickle ($ argumentsString = '' )
116112 {
117- $ argumentsString = strtr ($ argumentsString , array ( '\'' => '" ' ) );
118- $ arguments = explode (' ' ,$ argumentsString );
113+ $ argumentsString = strtr ($ argumentsString , [ '\'' => '" ' ] );
114+ $ arguments = explode (' ' , $ argumentsString );
119115 $ processArguments = [
120- $ this ->php ,
121- __DIR__ . '/../../ ' . static ::PICKLE_BIN ,
122- ];
116+ $ this ->php ,
117+ __DIR__ . '/../../ ' . static ::PICKLE_BIN ,
118+ ];
123119
124120 $ processArguments = array_merge ($ processArguments , $ arguments );
125121 $ processArguments [] = '--no-ansi ' ;
126122 $ this ->process = new Process ($ processArguments );
127123
128124 $ timeout = getenv ('PICKLE_BEHAT_PROCESS_TIMEOUT ' );
129- if (false !== $ timeout ) {
125+ if ($ timeout !== false ) {
130126 $ this ->process ->setTimeout ($ timeout );
131127 }
132128
@@ -148,14 +144,14 @@ public function theOutputShouldContain(PyStringNode $text)
148144 */
149145 public function itShouldFail ($ success )
150146 {
151- if (' fail ' === $ success ) {
152- if (0 === $ this ->getExitCode ()) {
147+ if ($ success === ' fail ' ) {
148+ if ($ this ->getExitCode () === 0 ) {
153149 echo 'Actual output: ' . PHP_EOL . PHP_EOL . $ this ->getOutput ();
154150 }
155151
156152 $ this ->assert ->integer ($ this ->getExitCode ())->isGreaterThan (0 );
157153 } else {
158- if (0 !== $ this ->getExitCode ()) {
154+ if ($ this ->getExitCode () !== 0 ) {
159155 echo 'Actual output: ' . PHP_EOL . PHP_EOL . $ this ->getOutput ();
160156 }
161157
@@ -177,7 +173,7 @@ public function itShouldPassWith($success, PyStringNode $text)
177173 */
178174 public function aFileNamedWith ($ filename , PyStringNode $ content )
179175 {
180- $ content = strtr ((string ) $ content , array ( "''' " => '""" ' ) );
176+ $ content = strtr ((string ) $ content , [ "''' " => '""" ' ] );
181177 $ this ->createFile ($ this ->workingDir . '/ ' . $ filename , $ content );
182178 }
183179
@@ -221,6 +217,36 @@ public function JsonfileShouldContain($path, PyStringNode $text)
221217 $ this ->assert ->object ($ fileContent )->isEqualTo (json_decode ($ text ));
222218 }
223219
220+ /**
221+ * @Then /^"([^"]*)" ((?:\d+\.?)+(?:RC\d*|beta\d*|alpha\d*)?) extension exists$/
222+ */
223+ public function extensionExists ($ name , $ version )
224+ {
225+ $ url = 'https://pecl.php.net/get/ ' . $ name . '/ ' . $ version . '?uncompress=1 ' ;
226+ $ file = $ name . '- ' . $ version . '.tgz ' ;
227+ $ dir = $ this ->workingDir . '/ ' . $ name . '- ' . $ version ;
228+
229+ if (is_dir ($ dir ) === false ) {
230+ mkdir ($ dir , 0777 , true );
231+ }
232+ $ downloadFile = $ dir . '/ ' . $ file ;
233+ file_put_contents ($ downloadFile , file_get_contents ($ url ));
234+ $ p = new PharData ($ downloadFile );
235+ $ phar = $ p ->decompress ('.tar ' );
236+ $ phar ->extractTo ($ dir );
237+ }
238+
239+ private function moveToNewPath ($ path )
240+ {
241+ $ newWorkingDir = $ this ->workingDir . '/ ' . $ path ;
242+
243+ if (!file_exists ($ newWorkingDir )) {
244+ mkdir ($ newWorkingDir , 0777 , true );
245+ }
246+
247+ $ this ->workingDir = $ newWorkingDir ;
248+ }
249+
224250 private function getExitCode ()
225251 {
226252 return $ this ->process ->getExitCode ();
@@ -249,21 +275,19 @@ private function getOutput()
249275 $ output = str_replace (PHP_EOL , "\n" , $ output );
250276 }
251277
252- return trim (preg_replace (" / +$/m " , '' , $ output ));
278+ return trim (preg_replace (' / +$/m ' , '' , $ output ));
253279 }
254280
255281 private function getExpectedOutput (PyStringNode $ expectedText )
256282 {
257- $ text = strtr (
283+ return strtr (
258284 $ expectedText ,
259285 [
260286 '\'\'\'' => '""" ' ,
261287 '%%TMP_DIR%% ' => sys_get_temp_dir (),
262288 '%%TEST_DIR%% ' => realpath ($ this ->dir ),
263289 ]
264290 );
265-
266- return $ text ;
267291 }
268292
269293 private static function clearDirectory ($ path )
@@ -283,23 +307,4 @@ private static function clearDirectory($path)
283307
284308 rmdir ($ path );
285309 }
286-
287- /**
288- * @Then /^"([^"]*)" ((?:\d+\.?)+(?:RC\d*|beta\d*|alpha\d*)?) extension exists$/
289- */
290- public function extensionExists ($ name , $ version )
291- {
292- $ url = 'https://pecl.php.net/get/ ' . $ name . '/ ' . $ version . '?uncompress=1 ' ;
293- $ file = $ name . '- ' . $ version . '.tgz ' ;
294- $ dir = $ this ->workingDir . '/ ' . $ name . '- ' . $ version ;
295-
296- if (is_dir ($ dir ) === false ) {
297- mkdir ($ dir , 0777 , true );
298- }
299- $ downloadFile = $ dir . '/ ' . $ file ;
300- file_put_contents ($ downloadFile , file_get_contents ($ url ));
301- $ p = new PharData ($ downloadFile );
302- $ phar = $ p ->decompress ('.tar ' );
303- $ phar ->extractTo ($ dir );
304- }
305310}
0 commit comments