Skip to content

Commit

Permalink
Work out of the box on Windows... (joomla#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
compojoom authored and javigomez committed Dec 10, 2016
1 parent 5cbecd9 commit f29d6c8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
48 changes: 41 additions & 7 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 &");
}
Expand All @@ -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
{
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

0 comments on commit f29d6c8

Please sign in to comment.