diff --git a/composer.json b/composer.json index a21128b..607accb 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,6 @@ "yiisoft/yii2-debug": "*", "yiisoft/yii2-gii": "*" }, - "suggest": { - "codeception/codeception": "Codeception, 2.0.* is currently works well with Yii.", - "codeception/specify": "BDD style code blocks for PHPUnit and Codeception", - "codeception/verify": "BDD Assertions for PHPUnit and Codeception" - }, "scripts": { "post-create-project-cmd": [ "yii\\composer\\Installer::setPermission", diff --git a/tests/README.md b/tests/README.md index e1aed9a..1c4b50b 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,32 +1,50 @@ -This folder contains various tests for the basic application. -These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/). +This directory contains various tests for the basic application. + +Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/). After creating the basic application, follow these steps to prepare for the tests: -1. Install additional composer packages: +1. Install Codeception if it's not yet installed: - ``` - php composer.phar require --dev "codeception/codeception: 2.0.*" "codeception/specify: *" "codeception/verify: *" - ``` -2. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so - that it points to the correct entry script URL. -3. Go to the application base directory and build the test suites: +``` +composer global require "codeception/codeception=2.0.*" +composer global require "codeception/specify=*" +composer global require "codeception/verify=*" +``` - ``` - vendor/bin/codecept build - ``` +If you've never used Composer for global packages run `composer global status`. It should output: -Now you can run the tests with the following commands: +``` +Changed current directory to +``` + +Then add `/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command +line globally. + +2. Build the test suites: + +``` +codecept build +``` + +3. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in +webserver. In the `web` directory execute the following: + +``` +php -S localhost:8080 +``` + +4. Now you can run the tests with the following commands: ``` # run all available tests -vendor/bin/codecept run +codecept run # run acceptance tests -vendor/bin/codecept run acceptance +codecept run acceptance # run functional tests -vendor/bin/codecept run functional +codecept run functional # run unit tests -vendor/bin/codecept run unit +codecept run unit ``` Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for diff --git a/tests/acceptance/_console.php b/tests/acceptance/_console.php deleted file mode 100644 index 03cdd1f..0000000 --- a/tests/acceptance/_console.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', - ], - ], - ] -); diff --git a/tests/acceptance/yii b/tests/acceptance/yii deleted file mode 100644 index e587ba4..0000000 --- a/tests/acceptance/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/codeception.yml b/tests/codeception.yml similarity index 62% rename from codeception.yml rename to tests/codeception.yml index 496ebd9..6495252 100644 --- a/codeception.yml +++ b/tests/codeception.yml @@ -1,9 +1,9 @@ actor: Tester paths: - tests: tests - log: tests/_log - data: tests/_data - helpers: tests/_helpers + tests: codeception + log: codeception/_log + data: codeception/_data + helpers: codeception/_helpers settings: bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite @@ -16,4 +16,4 @@ modules: dsn: '' user: '' password: '' - dump: tests/_data/dump.sql + dump: codeception/_data/dump.sql diff --git a/tests/.gitignore b/tests/codeception/.gitignore similarity index 100% rename from tests/.gitignore rename to tests/codeception/.gitignore diff --git a/tests/_bootstrap.php b/tests/codeception/_bootstrap.php similarity index 65% rename from tests/_bootstrap.php rename to tests/codeception/_bootstrap.php index 4890b3e..ecd76de 100644 --- a/tests/_bootstrap.php +++ b/tests/codeception/_bootstrap.php @@ -2,22 +2,22 @@ // the entry script URL (without host info) for functional and acceptance tests // PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL -defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/basic/web/index-test.php'); +defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/index-test.php'); // the entry script file path for functional and acceptance tests -defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php'); +defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index-test.php'); defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'test'); -require_once(__DIR__ . '/../vendor/autoload.php'); +require_once(__DIR__ . '/../../vendor/autoload.php'); -require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); +require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); // set correct script paths $_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; $_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; $_SERVER['SERVER_NAME'] = 'localhost'; -Yii::setAlias('@tests', __DIR__); +Yii::setAlias('@codeception', __DIR__); diff --git a/tests/_config.php b/tests/codeception/_config.php similarity index 100% rename from tests/_config.php rename to tests/codeception/_config.php diff --git a/tests/_data/dump.sql b/tests/codeception/_data/dump.sql similarity index 100% rename from tests/_data/dump.sql rename to tests/codeception/_data/dump.sql diff --git a/tests/_log/.gitignore b/tests/codeception/_log/.gitignore similarity index 100% rename from tests/_log/.gitignore rename to tests/codeception/_log/.gitignore diff --git a/tests/_pages/AboutPage.php b/tests/codeception/_pages/AboutPage.php similarity index 78% rename from tests/_pages/AboutPage.php rename to tests/codeception/_pages/AboutPage.php index 77acdb8..727cd38 100644 --- a/tests/_pages/AboutPage.php +++ b/tests/codeception/_pages/AboutPage.php @@ -1,6 +1,6 @@ wantTo('ensure that about works'); diff --git a/tests/acceptance/ContactCept.php b/tests/codeception/acceptance/ContactCept.php similarity index 97% rename from tests/acceptance/ContactCept.php rename to tests/codeception/acceptance/ContactCept.php index e76ac9b..50aa69a 100644 --- a/tests/acceptance/ContactCept.php +++ b/tests/codeception/acceptance/ContactCept.php @@ -1,6 +1,6 @@ wantTo('ensure that contact works'); diff --git a/tests/acceptance/HomeCept.php b/tests/codeception/acceptance/HomeCept.php similarity index 100% rename from tests/acceptance/HomeCept.php rename to tests/codeception/acceptance/HomeCept.php diff --git a/tests/acceptance/LoginCept.php b/tests/codeception/acceptance/LoginCept.php similarity index 95% rename from tests/acceptance/LoginCept.php rename to tests/codeception/acceptance/LoginCept.php index c7c9ae3..ff093b3 100644 --- a/tests/acceptance/LoginCept.php +++ b/tests/codeception/acceptance/LoginCept.php @@ -1,6 +1,6 @@ wantTo('ensure that login works'); diff --git a/tests/acceptance/_bootstrap.php b/tests/codeception/acceptance/_bootstrap.php similarity index 100% rename from tests/acceptance/_bootstrap.php rename to tests/codeception/acceptance/_bootstrap.php diff --git a/tests/acceptance/_config.php b/tests/codeception/acceptance/_config.php similarity index 83% rename from tests/acceptance/_config.php rename to tests/codeception/acceptance/_config.php index 857a804..d620a7d 100644 --- a/tests/acceptance/_config.php +++ b/tests/codeception/acceptance/_config.php @@ -1,7 +1,7 @@ [ diff --git a/tests/_console_bootstrap.php b/tests/codeception/bin/_console_bootstrap.php similarity index 62% rename from tests/_console_bootstrap.php rename to tests/codeception/bin/_console_bootstrap.php index 81287f3..eff8b40 100644 --- a/tests/_console_bootstrap.php +++ b/tests/codeception/bin/_console_bootstrap.php @@ -8,5 +8,7 @@ defined('YII_ENV') or define('YII_ENV', 'test'); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); -require(__DIR__ . '/../vendor/autoload.php'); -require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); +defined('ROOT_DIR') or define('ROOT_DIR', dirname(dirname(dirname(__DIR__)))); + +require(ROOT_DIR . '/vendor/autoload.php'); +require(ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php'); diff --git a/tests/codeception/bin/yii_acceptance b/tests/codeception/bin/yii_acceptance new file mode 100644 index 0000000..a02d9da --- /dev/null +++ b/tests/codeception/bin/yii_acceptance @@ -0,0 +1,27 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/tests/unit/yii.bat b/tests/codeception/bin/yii_acceptance.bat similarity index 91% rename from tests/unit/yii.bat rename to tests/codeception/bin/yii_acceptance.bat index 5e21e2e..389f893 100644 --- a/tests/unit/yii.bat +++ b/tests/codeception/bin/yii_acceptance.bat @@ -15,6 +15,6 @@ set YII_PATH=%~dp0 if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe -"%PHP_COMMAND%" "%YII_PATH%yii" %* +"%PHP_COMMAND%" "%YII_PATH%yii_acceptance" %* @endlocal diff --git a/tests/codeception/bin/yii_functional b/tests/codeception/bin/yii_functional new file mode 100644 index 0000000..44051e2 --- /dev/null +++ b/tests/codeception/bin/yii_functional @@ -0,0 +1,27 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/tests/acceptance/yii.bat b/tests/codeception/bin/yii_functional.bat similarity index 91% rename from tests/acceptance/yii.bat rename to tests/codeception/bin/yii_functional.bat index 5e21e2e..98fae88 100644 --- a/tests/acceptance/yii.bat +++ b/tests/codeception/bin/yii_functional.bat @@ -15,6 +15,6 @@ set YII_PATH=%~dp0 if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe -"%PHP_COMMAND%" "%YII_PATH%yii" %* +"%PHP_COMMAND%" "%YII_PATH%yii_functional" %* @endlocal diff --git a/tests/codeception/bin/yii_unit b/tests/codeception/bin/yii_unit new file mode 100644 index 0000000..e9b7999 --- /dev/null +++ b/tests/codeception/bin/yii_unit @@ -0,0 +1,27 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit', + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/tests/functional/yii.bat b/tests/codeception/bin/yii_unit.bat similarity index 92% rename from tests/functional/yii.bat rename to tests/codeception/bin/yii_unit.bat index 5e21e2e..511e61d 100644 --- a/tests/functional/yii.bat +++ b/tests/codeception/bin/yii_unit.bat @@ -15,6 +15,6 @@ set YII_PATH=%~dp0 if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe -"%PHP_COMMAND%" "%YII_PATH%yii" %* +"%PHP_COMMAND%" "%YII_PATH%yii_unit" %* @endlocal diff --git a/tests/functional.suite.yml b/tests/codeception/functional.suite.yml similarity index 85% rename from tests/functional.suite.yml rename to tests/codeception/functional.suite.yml index 916ef1a..3b50081 100644 --- a/tests/functional.suite.yml +++ b/tests/codeception/functional.suite.yml @@ -13,4 +13,4 @@ modules: - Yii2 config: Yii2: - configFile: 'tests/functional/_config.php' + configFile: 'codeception/functional/_config.php' diff --git a/tests/functional/AboutCept.php b/tests/codeception/functional/AboutCept.php similarity index 78% rename from tests/functional/AboutCept.php rename to tests/codeception/functional/AboutCept.php index 1875c2e..6312061 100644 --- a/tests/functional/AboutCept.php +++ b/tests/codeception/functional/AboutCept.php @@ -1,6 +1,6 @@ wantTo('ensure that about works'); diff --git a/tests/functional/ContactCept.php b/tests/codeception/functional/ContactCept.php similarity index 97% rename from tests/functional/ContactCept.php rename to tests/codeception/functional/ContactCept.php index 49d7735..f13b51c 100644 --- a/tests/functional/ContactCept.php +++ b/tests/codeception/functional/ContactCept.php @@ -1,6 +1,6 @@ wantTo('ensure that contact works'); diff --git a/tests/functional/HomeCept.php b/tests/codeception/functional/HomeCept.php similarity index 100% rename from tests/functional/HomeCept.php rename to tests/codeception/functional/HomeCept.php diff --git a/tests/functional/LoginCept.php b/tests/codeception/functional/LoginCept.php similarity index 95% rename from tests/functional/LoginCept.php rename to tests/codeception/functional/LoginCept.php index e5285cd..77189b8 100644 --- a/tests/functional/LoginCept.php +++ b/tests/codeception/functional/LoginCept.php @@ -1,6 +1,6 @@ wantTo('ensure that login works'); diff --git a/tests/functional/_bootstrap.php b/tests/codeception/functional/_bootstrap.php similarity index 100% rename from tests/functional/_bootstrap.php rename to tests/codeception/functional/_bootstrap.php diff --git a/tests/functional/_config.php b/tests/codeception/functional/_config.php similarity index 87% rename from tests/functional/_config.php rename to tests/codeception/functional/_config.php index 512e802..3d50fdb 100644 --- a/tests/functional/_config.php +++ b/tests/codeception/functional/_config.php @@ -5,7 +5,7 @@ $_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; $_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; return yii\helpers\ArrayHelper::merge( - require(__DIR__ . '/../../config/web.php'), + require(__DIR__ . '/../../../config/web.php'), require(__DIR__ . '/../_config.php'), [ 'components' => [ diff --git a/tests/unit.suite.yml b/tests/codeception/unit.suite.yml similarity index 100% rename from tests/unit.suite.yml rename to tests/codeception/unit.suite.yml diff --git a/tests/unit/_bootstrap.php b/tests/codeception/unit/_bootstrap.php similarity index 100% rename from tests/unit/_bootstrap.php rename to tests/codeception/unit/_bootstrap.php diff --git a/tests/unit/_config.php b/tests/codeception/unit/_config.php similarity index 83% rename from tests/unit/_config.php rename to tests/codeception/unit/_config.php index 2559ef3..36b0114 100644 --- a/tests/unit/_config.php +++ b/tests/codeception/unit/_config.php @@ -1,7 +1,7 @@ [ diff --git a/tests/unit/fixtures/.gitkeep b/tests/codeception/unit/fixtures/.gitkeep similarity index 100% rename from tests/unit/fixtures/.gitkeep rename to tests/codeception/unit/fixtures/.gitkeep diff --git a/tests/unit/fixtures/data/.gitkeep b/tests/codeception/unit/fixtures/data/.gitkeep similarity index 100% rename from tests/unit/fixtures/data/.gitkeep rename to tests/codeception/unit/fixtures/data/.gitkeep diff --git a/tests/unit/models/ContactFormTest.php b/tests/codeception/unit/models/ContactFormTest.php similarity index 98% rename from tests/unit/models/ContactFormTest.php rename to tests/codeception/unit/models/ContactFormTest.php index 6e69cec..8adda18 100644 --- a/tests/unit/models/ContactFormTest.php +++ b/tests/codeception/unit/models/ContactFormTest.php @@ -1,6 +1,6 @@ [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', - ], - ], - ] -); diff --git a/tests/functional/yii b/tests/functional/yii deleted file mode 100644 index e587ba4..0000000 --- a/tests/functional/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/tests/unit/_console.php b/tests/unit/_console.php deleted file mode 100644 index 04272a3..0000000 --- a/tests/unit/_console.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit', - ], - ], - ] -); diff --git a/tests/unit/yii b/tests/unit/yii deleted file mode 100644 index e587ba4..0000000 --- a/tests/unit/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/web/index-test.php b/web/index-test.php index 326608d..dd8a496 100644 --- a/web/index-test.php +++ b/web/index-test.php @@ -11,6 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test'); require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); -$config = require(__DIR__ . '/../tests/acceptance/_config.php'); +$config = require(__DIR__ . '/../tests/codeception/acceptance/_config.php'); (new yii\web\Application($config))->run();