From 7e12fc15b756a7cd7a48453622724e8ffda47bcd Mon Sep 17 00:00:00 2001 From: Andrii Vasyliev Date: Mon, 16 May 2016 15:23:18 +0000 Subject: [PATCH] GREATLY improved functional tests to run internally instead of exec --- phpunit.xml.dist | 6 ++++++ tests/_bootstrap.php | 6 +++++- tests/functional/InitTest.php | 10 +++++++--- tests/functional/Tester.php | 34 ++++++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b44fffa..f0b242f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -7,6 +7,12 @@ ./tests/functional/ + + .hidev/vendor/hiqdev/hidev-readme/tests/unit/ + + + .hidev/vendor/hiqdev/hidev-readme/tests/functional/ + diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 44b013b..410124e 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -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); +} diff --git a/tests/functional/InitTest.php b/tests/functional/InitTest.php index 0359b4d..568f2c8 100644 --- a/tests/functional/InitTest.php +++ b/tests/functional/InitTest.php @@ -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']); } @@ -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']); } @@ -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']); } } diff --git a/tests/functional/Tester.php b/tests/functional/Tester.php index 6399fc5..531b074 100644 --- a/tests/functional/Tester.php +++ b/tests/functional/Tester.php @@ -11,6 +11,7 @@ namespace hidev\tests\functional; +use hidev\base\Application; use Yii; class Tester @@ -21,6 +22,8 @@ class Tester public $clean = true; + protected $_app; + public function __construct($test) { static $no = 0; @@ -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); }