Skip to content

Commit

Permalink
GREATLY improved functional tests to run internally instead of exec
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed May 16, 2016
1 parent b4b8e10 commit 7e12fc1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<testsuite name="Functional Test Suite">
<directory>./tests/functional/</directory>
</testsuite>
<testsuite name="Readme Unit Test Suite">
<directory>.hidev/vendor/hiqdev/hidev-readme/tests/unit/</directory>
</testsuite>
<testsuite name="Readme Functional Test Suite">
<directory>.hidev/vendor/hiqdev/hidev-readme/tests/functional/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
Expand Down
6 changes: 5 additions & 1 deletion tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
*/

error_reporting(-1);
error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

require __DIR__ . '/../src/config/bootstrap.php';

foreach (require __DIR__ . '/../.hidev/vendor/hiqdev/aliases.php' as $alias => $path) {
Yii::setAlias($alias, $path);
}
10 changes: 7 additions & 3 deletions tests/functional/InitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function tearDown()
*/
public function testMinimal()
{
$this->tester->hidev('init the-vendor/my-new-package --nick=sol "--author=Author Name" --email=author@email.com');
$this->tester->hidev(['init', 'the-vendor/my-new-package', '--nick=sol', '--author=Author Name', '--email=author@email.com']);
$this->tester->assertFiles(__DIR__ . '/minimal', ['.hidev/config.yml']);
}

Expand All @@ -42,7 +42,7 @@ public function testMinimal()
*/
public function testPlugins()
{
$this->tester->hidev('init hiqdev/my-new-package --nick=sol "--author=Author Name" --email=author@email.com');
$this->tester->hidev(['init', 'hiqdev/my-new-package', '--nick=sol', '--author=Author Name', '--email=author@email.com']);
$this->tester->assertFiles(__DIR__ . '/plugins', ['.hidev/config.yml']);
}

Expand All @@ -51,7 +51,11 @@ public function testPlugins()
*/
public function testOptions()
{
$this->tester->hidev('init the-vendor/new-package --nick=sol "--namespace=thevendor\\other\\newpackage" "--headline=New Package" "--title=The new library package" --type=library --keywords=new,package,of,the,vendor --license=MIT "--description=The project longer description" --year=2014 --novendor --norequire');
$this->tester->hidev([
'init', 'the-vendor/new-package', '--nick=sol', '--namespace=thevendor\\other\\newpackage', '--headline=New Package',
'--title=The new library package', '--type=library', '--keywords=new,package,of,the,vendor', '--license=MIT',
'--description=The project longer description', '--year=2014', '--novendor', '--norequire'
]);
$this->tester->assertFiles(__DIR__ . '/options', ['.hidev/config.yml']);
}
}
34 changes: 30 additions & 4 deletions tests/functional/Tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace hidev\tests\functional;

use hidev\base\Application;
use Yii;

class Tester
Expand All @@ -21,6 +22,8 @@ class Tester

public $clean = true;

protected $_app;

public function __construct($test)
{
static $no = 0;
Expand Down Expand Up @@ -58,17 +61,40 @@ public function __destruct()
}
}

public function hidev($params)
/**
* Run hidev.
* @param string $request
*/
public function hidev($request)
{
#$command = Yii::getAlias('@hidev/../bin/hidev') . ' ' . $params;
#exec($command);
$this->getApp()->runRequest($request);
}

public function setAlias($alias, $path)
{
Yii::setAlias($alias, $path);
}

public function getApp()
{
$command = Yii::getAlias('@hidev/../bin/hidev') . ' ' . $params;
exec($command);
if (!$this->_app) {
$this->_app = Application::create(require Yii::getAlias('@hidev/config/base.php'));
Yii::getLogger()->setSpamLevel('quiet');
}

return $this->_app;
}

public function config($content)
public function config($content, array $subs = null)
{
if ($content[0] === '/' && file_exists($content)) {
$content = file_get_contents($content);
}
if (!empty($subs)) {
$content = strtr($content, $subs);
}
static::mkdir('.hidev');
$this->writeFile('.hidev/config.yml', $content);
}
Expand Down

0 comments on commit 7e12fc1

Please sign in to comment.