From f29d6c8351d2a592d9248e1a6e525ef7578f6b48 Mon Sep 17 00:00:00 2001 From: Daniel Dimitrov Date: Sat, 10 Dec 2016 13:36:01 +0100 Subject: [PATCH] Work out of the box on Windows... (#90) --- README.md | 12 ++++++++++++ RoboFile.php | 48 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c4aa3ba97a9ef..608f050297067 100644 --- a/README.md +++ b/README.md @@ -154,16 +154,28 @@ $ tests/codeception/vendor/bin/robo run:tests #### You can individual run `feature` using following command. +**_Linux & Mac_** ```bash $ tests/codeception/vendor/bin/robo run:test ``` +**_Windows_** +```cmd +$ tests\codeception\vendor\bin\robo run:test +``` + Or you can manually run them using codecept command. Check the following example: +**_Linux & Mac_** ```bash $ ./tests/codeception/vendor/bin/codecept run tests/codeception/acceptance/users.feature ``` +**_Windows_** +```cmd +$ tests\codeception\vendor\bin\codecept run tests/codeception/acceptance/users.feature +``` + If you want to see steps then you can use `--steps` option of codeception. Check [full codecept command list here](http://codeception.com/docs/reference/Commands#Run)_ **Note**:You can modify the timeout time by setting the value of **TIMEOUT** constant lower for fast machines and higher for slow computers. The constant located in the file `tests/codeception/acceptance/_bootstrap.php` diff --git a/RoboFile.php b/RoboFile.php index 43c4631a4e4ab..c34cca356cd11 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -267,7 +267,7 @@ private function getComposer() */ public function runSelenium() { - if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') + if (!$this->isWindows()) { $this->_exec($this->testsPath . "vendor/bin/selenium-server-standalone >> selenium.log 2>&1 &"); } @@ -276,9 +276,9 @@ public function runSelenium() $this->_exec("START java.exe -jar .\\tests\\codeception\\vendor\\joomla-projects\\selenium-server-standalone\\bin\\selenium-server-standalone.jar"); } - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') + if ($this->isWindows()) { - sleep(10); + sleep(3); } else { @@ -311,9 +311,17 @@ public function runTests($opts = ['use-htaccess' => false, 'env' => 'desktop']) $this->runSelenium(); // Make sure to run the build command to generate AcceptanceTester - $this->_exec('php ' . $this->testsPath . 'vendor/bin/codecept build'); + if($this->isWindows()) + { + $this->_exec('php ' . $this->getWindowsPath($this->testsPath . 'vendor/bin/codecept') . ' build'); + $pathToCodeception = $this->getWindowsPath($this->testsPath . 'vendor/bin/codecept'); + } + else + { + $this->_exec('php ' . $this->testsPath . 'vendor/bin/codecept build'); - $pathToCodeception = $this->testsPath . 'vendor/bin/codecept'; + $pathToCodeception = $this->testsPath . 'vendor/bin/codecept'; + } $this->taskCodecept($pathToCodeception) ->arg('--steps') @@ -407,7 +415,9 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance') $this->runSelenium(); // Make sure to run the build command to generate AcceptanceTester - $this->_exec('php tests/codeception/vendor/bin/codecept build'); + + $path = 'tests/codeception/vendor/bin/codecept'; + $this->_exec('php ' . $this->isWindows() ? $this->getWindowsPath($path) : $path .' build'); if (!$pathToTestFile) { @@ -492,11 +502,35 @@ public function runTest($pathToTestFile = null, $suite = 'acceptance') $pathToTestFile = $pathToTestFile . ':' . $method; } - $this->taskCodecept($this->testsPath . 'vendor/bin/codecept') + $testPathCodecept = $this->testsPath . 'vendor/bin/codecept'; + + $this->taskCodecept($this->isWindows() ? $this->getWindowsPath($testPathCodecept): $testPathCodecept) ->test($pathToTestFile) ->arg('--steps') ->arg('--debug') ->run() ->stopOnFail(); } + + /** + * Check if local OS is Windows + * + * @return bool + */ + private function isWindows() + { + return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; + } + + /** + * Return the correct path for Windows + * + * param string $path - The linux path + * + * @return string + */ + private function getWindowsPath($path) + { + return str_replace('/', DIRECTORY_SEPARATOR, $path); + } }