diff --git a/.travis.yml b/.travis.yml index 439e42ff5e..f38cf5d04f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,10 +47,8 @@ before_script: script: - vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --exclude-group mssql,oci,wincache,xcache,zenddata - - cd apps/basic && php vendor/bin/codecept run - - cd ../advanced/backend && ../vendor/bin/codecept run - - cd ../common && ../vendor/bin/codecept run - - cd ../frontend && ../vendor/bin/codecept run + - cd apps/basic/tests && php ../vendor/bin/codecept run + - cd ../../advanced/tests && ../vendor/bin/codecept run after_script: - cd ../../.. diff --git a/apps/advanced/README.md b/apps/advanced/README.md index 508a4140bd..efd10e6380 100644 --- a/apps/advanced/README.md +++ b/apps/advanced/README.md @@ -95,35 +95,3 @@ the installed application. You only need to do these once for all. To login into the application, you need to first sign up, with any of your email address, username and password. Then, you can login into the application with same email address and password at any time. - -TESTING -------- - -Install additional composer packages: -* `php composer.phar require --dev codeception/codeception:2.0.* codeception/specify:* codeception/verify:* yiisoft/yii2-faker:*` - -This application boilerplate use database in testing, so you should create three databases that are used in tests: -* `yii2_advanced_unit` - database for unit tests; -* `yii2_advanced_functional` - database for functional tests; -* `yii2_advanced_acceptance` - database for acceptance tests. - -To make your database up to date, you can run in needed test folder `yii migrate`, for example -if you are starting from `frontend` tests then you should run `yii migrate` in each suite folder `acceptance`, `functional`, `unit` -it will upgrade your database to the last state according migrations. - -To be able to run acceptance tests you need a running webserver. For this you can use the php builtin server and run it in the directory where your main project folder is located. For example if your application is located in `/www/advanced` all you need to is: -`cd /www` and then `php -S 127.0.0.1:8080` because the default configuration of acceptance tests expects the url of the application to be `/advanced/`. -If you already have a server configured or your application is not located in a folder called `advanced`, you may need to adjust the `test_entry_url` in `backend/codeception.yml` and `frontend/codeception.yml`. - -After that is done you should be able to run your tests, for example to run `frontend` tests do: - -* `cd frontend` -* `../vendor/bin/codecept build` -* `../vendor/bin/codecept run` - -In similar way you can run tests for other application tiers - `backend`, `console`, `common`. - -If you already have run `../vendor/bin/codecept build` for each application, you can run all tests by one command: `vendor/bin/codecept run` - -You also can adjust you application suite configs and `_bootstrap.php` settings to use other urls and files, as it is can be done in `yii2-basic`. -Current template also includes [yii2-faker](https://github.com/yiisoft/yii2/tree/master/extensions/faker) extension, that is correctly setup for each application tier. diff --git a/apps/advanced/backend/tests/_bootstrap.php b/apps/advanced/backend/tests/_bootstrap.php deleted file mode 100644 index bc9d17c28a..0000000000 --- a/apps/advanced/backend/tests/_bootstrap.php +++ /dev/null @@ -1,18 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', - ], - ], - ] -); diff --git a/apps/advanced/backend/tests/acceptance/_console.php b/apps/advanced/backend/tests/acceptance/_console.php deleted file mode 100644 index bae7e44b03..0000000000 --- a/apps/advanced/backend/tests/acceptance/_console.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', - ], - ], - ] -); diff --git a/apps/advanced/backend/tests/acceptance/yii b/apps/advanced/backend/tests/acceptance/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/backend/tests/acceptance/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/backend/tests/functional/_console.php b/apps/advanced/backend/tests/functional/_console.php deleted file mode 100644 index d76662c4e5..0000000000 --- a/apps/advanced/backend/tests/functional/_console.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional', - ], - ], - ] -); diff --git a/apps/advanced/backend/tests/functional/yii b/apps/advanced/backend/tests/functional/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/backend/tests/functional/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/backend/tests/unit/_console.php b/apps/advanced/backend/tests/unit/_console.php deleted file mode 100644 index d7a17913f9..0000000000 --- a/apps/advanced/backend/tests/unit/_console.php +++ /dev/null @@ -1,22 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', - ], - ], - 'controllerMap' => [ - 'fixture' => [ - 'class' => 'yii\faker\FixtureController', - 'fixtureDataPath' => '@backend/tests/unit/fixtures/data', - 'templatePath' => '@commmon/tests/templates/fixtures' - ], - ], - ] -); diff --git a/apps/advanced/backend/tests/unit/yii b/apps/advanced/backend/tests/unit/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/backend/tests/unit/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/codeception.yml b/apps/advanced/codeception.yml deleted file mode 100644 index c94b9fde94..0000000000 --- a/apps/advanced/codeception.yml +++ /dev/null @@ -1,11 +0,0 @@ -include: - - common - - console - - backend - - frontend - -paths: - log: tests/_log - -settings: - colors: true diff --git a/apps/advanced/common/codeception.yml b/apps/advanced/common/codeception.yml deleted file mode 100644 index 4ee15239c3..0000000000 --- a/apps/advanced/common/codeception.yml +++ /dev/null @@ -1,20 +0,0 @@ -namespace: common -actor: Tester -paths: - tests: tests - log: tests/_log - data: tests/_data - helpers: tests/_helpers -settings: - bootstrap: _bootstrap.php - suite_class: \PHPUnit_Framework_TestSuite - colors: true - memory_limit: 1024M - log: true -modules: - config: - Db: - dsn: '' - user: '' - password: '' - dump: tests/_data/dump.sql diff --git a/apps/advanced/common/tests/_bootstrap.php b/apps/advanced/common/tests/_bootstrap.php deleted file mode 100644 index 15b36bc2d2..0000000000 --- a/apps/advanced/common/tests/_bootstrap.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', - ], - ], - 'controllerMap' => [ - 'fixture' => [ - 'class' => 'yii\faker\FixtureController', - 'fixtureDataPath' => '@common/tests/unit/fixtures/data', - 'templatePath' => '@common/tests/templates/fixtures' - ], - ], - ] -); diff --git a/apps/advanced/common/tests/unit/yii b/apps/advanced/common/tests/unit/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/common/tests/unit/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/composer.json b/apps/advanced/composer.json index 639396b136..c0162626d4 100644 --- a/apps/advanced/composer.json +++ b/apps/advanced/composer.json @@ -22,13 +22,8 @@ "require-dev": { "yiisoft/yii2-codeception": "*", "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", - "yiisoft/yii2-faker": "Fixtures generator for Yii2 based on Faker lib" + "yiisoft/yii2-gii": "*", + "yiisoft/yii2-faker": "*" }, "scripts": { "post-create-project-cmd": [ diff --git a/apps/advanced/console/codeception.yml b/apps/advanced/console/codeception.yml deleted file mode 100644 index 94a12e3570..0000000000 --- a/apps/advanced/console/codeception.yml +++ /dev/null @@ -1,20 +0,0 @@ -namespace: console -actor: Tester -paths: - tests: tests - log: tests/_log - data: tests/_data - helpers: tests/_helpers -settings: - bootstrap: _bootstrap.php - suite_class: \PHPUnit_Framework_TestSuite - colors: true - memory_limit: 1024M - log: true -modules: - config: - Db: - dsn: '' - user: '' - password: '' - dump: tests/_data/dump.sql diff --git a/apps/advanced/console/tests/_bootstrap.php b/apps/advanced/console/tests/_bootstrap.php deleted file mode 100644 index 15b36bc2d2..0000000000 --- a/apps/advanced/console/tests/_bootstrap.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', - ], - ], - ] -); diff --git a/apps/advanced/console/tests/unit/_console.php b/apps/advanced/console/tests/unit/_console.php deleted file mode 100644 index bbb5fa366f..0000000000 --- a/apps/advanced/console/tests/unit/_console.php +++ /dev/null @@ -1,22 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', - ], - ], - 'controllerMap' => [ - 'fixture' => [ - 'class' => 'yii\faker\FixtureController', - 'fixtureDataPath' => '@console/tests/unit/fixtures/data', - 'templatePath' => '@common/tests/templates/fixtures' - ], - ], - ] -); diff --git a/apps/advanced/console/tests/unit/yii b/apps/advanced/console/tests/unit/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/console/tests/unit/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/console/tests/unit/yii.bat b/apps/advanced/console/tests/unit/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/advanced/console/tests/unit/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/advanced/frontend/tests/_bootstrap.php b/apps/advanced/frontend/tests/_bootstrap.php deleted file mode 100644 index bc9d17c28a..0000000000 --- a/apps/advanced/frontend/tests/_bootstrap.php +++ /dev/null @@ -1,18 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', - ], - ], - ] -); diff --git a/apps/advanced/frontend/tests/acceptance/_console.php b/apps/advanced/frontend/tests/acceptance/_console.php deleted file mode 100644 index bae7e44b03..0000000000 --- a/apps/advanced/frontend/tests/acceptance/_console.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', - ], - ], - ] -); diff --git a/apps/advanced/frontend/tests/acceptance/yii b/apps/advanced/frontend/tests/acceptance/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/frontend/tests/acceptance/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/frontend/tests/acceptance/yii.bat b/apps/advanced/frontend/tests/acceptance/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/advanced/frontend/tests/acceptance/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/advanced/frontend/tests/functional/_console.php b/apps/advanced/frontend/tests/functional/_console.php deleted file mode 100644 index d76662c4e5..0000000000 --- a/apps/advanced/frontend/tests/functional/_console.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional', - ], - ], - ] -); diff --git a/apps/advanced/frontend/tests/functional/yii b/apps/advanced/frontend/tests/functional/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/frontend/tests/functional/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/frontend/tests/functional/yii.bat b/apps/advanced/frontend/tests/functional/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/advanced/frontend/tests/functional/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/advanced/frontend/tests/unit/DbTestCase.php b/apps/advanced/frontend/tests/unit/DbTestCase.php deleted file mode 100644 index f175a3b9fd..0000000000 --- a/apps/advanced/frontend/tests/unit/DbTestCase.php +++ /dev/null @@ -1,8 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', - ], - ], - 'controllerMap' => [ - 'fixture' => [ - 'class' => 'yii\faker\FixtureController', - 'fixtureDataPath' => '@frontend/tests/unit/fixtures/data', - 'templatePath' => '@common/tests/templates/fixtures' - ], - ], - ] -); diff --git a/apps/advanced/frontend/tests/unit/yii b/apps/advanced/frontend/tests/unit/yii deleted file mode 100644 index a348a9ae7d..0000000000 --- a/apps/advanced/frontend/tests/unit/yii +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/advanced/frontend/tests/unit/yii.bat b/apps/advanced/frontend/tests/unit/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/advanced/frontend/tests/unit/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/advanced/tests/README.md b/apps/advanced/tests/README.md new file mode 100644 index 0000000000..3f9a6237e7 --- /dev/null +++ b/apps/advanced/tests/README.md @@ -0,0 +1,70 @@ +This directory contains various tests for the advanced applications. + +Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/). + +After creating and setting up the advanced application, follow these steps to prepare for the tests: + +1. Install Codeception if it's not yet installed: + +``` +composer global require "codeception/codeception=2.0.*" +composer global require "codeception/specify=*" +composer global require "codeception/verify=*" +``` + +If you've never used Composer for global packages run `composer global status`. It should output: + +``` +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. Install faker extension by running the following from template root directory where `composer.json` is: + +``` +composer require --dev yiisoft/yii2-faker:* +``` + + +3. Create three databases that are used in tests: + +* `yii2_advanced_unit` - for unit tests; +* `yii2_advanced_functional` - for functional tests; +* `yii2_advanced_acceptance` - for acceptance tests. + +Then update databases by applying migrations: + +``` +codeception/bin/yii_acceptance migrate +codeception/bin/yii_functional migrate +codeception/bin/yii_unit migrate +``` + +4. 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 root directory where `common`, `frontend` etc. are execute the following: + +``` +php -S localhost:8080 +``` + +5. Now you can run the tests with the following commands: + +``` +# frontend tests +cd frontend +codecept build +codecept run + +# backend tests + +cd backend +codecept build +codecept run + +# etc. +``` + +If you already have run `codecept build` for each application, you can run all tests by a single `codecept run` in the +`tests` directory. diff --git a/apps/advanced/tests/codeception.yml b/apps/advanced/tests/codeception.yml new file mode 100644 index 0000000000..4142b8a7e2 --- /dev/null +++ b/apps/advanced/tests/codeception.yml @@ -0,0 +1,11 @@ +include: + - codeception/common + - codeception/console + - codeception/backend + - codeception/frontend + +paths: + log: codeception/_log + +settings: + colors: true diff --git a/apps/advanced/backend/tests/_log/.gitignore b/apps/advanced/tests/codeception/_log/.gitignore similarity index 100% rename from apps/advanced/backend/tests/_log/.gitignore rename to apps/advanced/tests/codeception/_log/.gitignore diff --git a/apps/advanced/backend/tests/.gitignore b/apps/advanced/tests/codeception/backend/.gitignore similarity index 100% rename from apps/advanced/backend/tests/.gitignore rename to apps/advanced/tests/codeception/backend/.gitignore diff --git a/apps/advanced/tests/codeception/backend/_bootstrap.php b/apps/advanced/tests/codeception/backend/_bootstrap.php new file mode 100644 index 0000000000..eff0d345bf --- /dev/null +++ b/apps/advanced/tests/codeception/backend/_bootstrap.php @@ -0,0 +1,20 @@ +wantTo('ensure login page works'); diff --git a/apps/advanced/backend/tests/acceptance/_bootstrap.php b/apps/advanced/tests/codeception/backend/acceptance/_bootstrap.php similarity index 100% rename from apps/advanced/backend/tests/acceptance/_bootstrap.php rename to apps/advanced/tests/codeception/backend/acceptance/_bootstrap.php diff --git a/apps/advanced/tests/codeception/backend/acceptance/_config.php b/apps/advanced/tests/codeception/backend/acceptance/_config.php new file mode 100644 index 0000000000..92fab0a123 --- /dev/null +++ b/apps/advanced/tests/codeception/backend/acceptance/_config.php @@ -0,0 +1,16 @@ + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', + ], + ], + ] +); diff --git a/apps/advanced/backend/codeception.yml b/apps/advanced/tests/codeception/backend/codeception.yml similarity index 50% rename from apps/advanced/backend/codeception.yml rename to apps/advanced/tests/codeception/backend/codeception.yml index 49a978b6dc..eb0ddc462c 100644 --- a/apps/advanced/backend/codeception.yml +++ b/apps/advanced/tests/codeception/backend/codeception.yml @@ -1,24 +1,17 @@ -namespace: backend +namespace: codeception_backend actor: Tester paths: - tests: tests - log: tests/_log - data: tests/_data - helpers: tests/_helpers + tests: . + log: _log + data: _data + helpers: _helpers settings: bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite colors: true memory_limit: 1024M log: true -modules: - config: - Db: - dsn: '' - user: '' - password: '' - dump: tests/_data/dump.sql config: # the entry script URL (without host info) for functional and acceptance tests # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL - test_entry_url: /advanced/backend/web/index-test.php + test_entry_url: /backend/web/index-test.php diff --git a/apps/advanced/frontend/tests/functional.suite.yml b/apps/advanced/tests/codeception/backend/functional.suite.yml similarity index 78% rename from apps/advanced/frontend/tests/functional.suite.yml rename to apps/advanced/tests/codeception/backend/functional.suite.yml index 3c828f5c15..85003ea12e 100644 --- a/apps/advanced/frontend/tests/functional.suite.yml +++ b/apps/advanced/tests/codeception/backend/functional.suite.yml @@ -11,7 +11,7 @@ modules: enabled: - Filesystem - Yii2 - - common\tests\_helpers\FixtureHelper + - codeception\common\_helpers\FixtureHelper config: Yii2: - configFile: 'tests/functional/_config.php' + configFile: 'functional/_config.php' diff --git a/apps/advanced/frontend/tests/functional/LoginCept.php b/apps/advanced/tests/codeception/backend/functional/LoginCept.php similarity index 91% rename from apps/advanced/frontend/tests/functional/LoginCept.php rename to apps/advanced/tests/codeception/backend/functional/LoginCept.php index 7e1e1be508..fdccdb3f94 100644 --- a/apps/advanced/frontend/tests/functional/LoginCept.php +++ b/apps/advanced/tests/codeception/backend/functional/LoginCept.php @@ -1,7 +1,7 @@ wantTo('ensure login page works'); diff --git a/apps/advanced/backend/tests/functional/_bootstrap.php b/apps/advanced/tests/codeception/backend/functional/_bootstrap.php similarity index 100% rename from apps/advanced/backend/tests/functional/_bootstrap.php rename to apps/advanced/tests/codeception/backend/functional/_bootstrap.php diff --git a/apps/advanced/frontend/tests/functional/_config.php b/apps/advanced/tests/codeception/backend/functional/_config.php similarity index 55% rename from apps/advanced/frontend/tests/functional/_config.php rename to apps/advanced/tests/codeception/backend/functional/_config.php index 15d3100cfc..28a7905af4 100644 --- a/apps/advanced/frontend/tests/functional/_config.php +++ b/apps/advanced/tests/codeception/backend/functional/_config.php @@ -1,14 +1,14 @@ [ diff --git a/apps/advanced/backend/tests/unit.suite.yml b/apps/advanced/tests/codeception/backend/unit.suite.yml similarity index 100% rename from apps/advanced/backend/tests/unit.suite.yml rename to apps/advanced/tests/codeception/backend/unit.suite.yml diff --git a/apps/advanced/backend/tests/unit/DbTestCase.php b/apps/advanced/tests/codeception/backend/unit/DbTestCase.php similarity index 100% rename from apps/advanced/backend/tests/unit/DbTestCase.php rename to apps/advanced/tests/codeception/backend/unit/DbTestCase.php diff --git a/apps/advanced/backend/tests/unit/TestCase.php b/apps/advanced/tests/codeception/backend/unit/TestCase.php similarity index 100% rename from apps/advanced/backend/tests/unit/TestCase.php rename to apps/advanced/tests/codeception/backend/unit/TestCase.php diff --git a/apps/advanced/backend/tests/unit/_bootstrap.php b/apps/advanced/tests/codeception/backend/unit/_bootstrap.php similarity index 100% rename from apps/advanced/backend/tests/unit/_bootstrap.php rename to apps/advanced/tests/codeception/backend/unit/_bootstrap.php diff --git a/apps/advanced/tests/codeception/backend/unit/_config.php b/apps/advanced/tests/codeception/backend/unit/_config.php new file mode 100644 index 0000000000..6cf1d2e57a --- /dev/null +++ b/apps/advanced/tests/codeception/backend/unit/_config.php @@ -0,0 +1,16 @@ + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', + ], + ], + ] +); diff --git a/apps/advanced/backend/tests/unit/fixtures/data/.gitkeep b/apps/advanced/tests/codeception/backend/unit/fixtures/data/.gitkeep similarity index 100% rename from apps/advanced/backend/tests/unit/fixtures/data/.gitkeep rename to apps/advanced/tests/codeception/backend/unit/fixtures/data/.gitkeep diff --git a/apps/advanced/common/tests/_console.php b/apps/advanced/tests/codeception/bin/_console_bootstrap.php similarity index 66% rename from apps/advanced/common/tests/_console.php rename to apps/advanced/tests/codeception/bin/_console_bootstrap.php index b38c84efdb..a9cbe29f98 100644 --- a/apps/advanced/common/tests/_console.php +++ b/apps/advanced/tests/codeception/bin/_console_bootstrap.php @@ -11,9 +11,11 @@ defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); -require_once(__DIR__ . '/../../vendor/autoload.php'); -require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); -require_once(__DIR__ . '/../../common/config/aliases.php'); +defined('ROOT_DIR') or define('ROOT_DIR', dirname(dirname(dirname(__DIR__)))); + +require_once(ROOT_DIR . '/vendor/autoload.php'); +require_once(ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php'); +require_once(ROOT_DIR . '/common/config/aliases.php'); defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'test'); diff --git a/apps/advanced/tests/codeception/bin/yii_acceptance b/apps/advanced/tests/codeception/bin/yii_acceptance new file mode 100644 index 0000000000..e4628d5314 --- /dev/null +++ b/apps/advanced/tests/codeception/bin/yii_acceptance @@ -0,0 +1,36 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', + ], + ], + 'controllerMap' => [ + 'fixture' => [ + 'class' => 'yii\faker\FixtureController', + 'fixtureDataPath' => dirname(__DIR__) . '_data/fixtures', + 'templatePath' => dirname(__DIR__) . '_data/templates' + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/apps/advanced/backend/tests/acceptance/yii.bat b/apps/advanced/tests/codeception/bin/yii_acceptance.bat similarity index 91% rename from apps/advanced/backend/tests/acceptance/yii.bat rename to apps/advanced/tests/codeception/bin/yii_acceptance.bat index 5e21e2e990..389f89325d 100644 --- a/apps/advanced/backend/tests/acceptance/yii.bat +++ b/apps/advanced/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/apps/advanced/tests/codeception/bin/yii_functional b/apps/advanced/tests/codeception/bin/yii_functional new file mode 100644 index 0000000000..dc94100191 --- /dev/null +++ b/apps/advanced/tests/codeception/bin/yii_functional @@ -0,0 +1,36 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional', + ], + ], + 'controllerMap' => [ + 'fixture' => [ + 'class' => 'yii\faker\FixtureController', + 'fixtureDataPath' => dirname(__DIR__) . '_data/fixtures', + 'templatePath' => dirname(__DIR__) . '_data/templates' + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/apps/advanced/backend/tests/functional/yii.bat b/apps/advanced/tests/codeception/bin/yii_functional.bat similarity index 91% rename from apps/advanced/backend/tests/functional/yii.bat rename to apps/advanced/tests/codeception/bin/yii_functional.bat index 5e21e2e990..98fae88531 100644 --- a/apps/advanced/backend/tests/functional/yii.bat +++ b/apps/advanced/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/apps/advanced/tests/codeception/bin/yii_unit b/apps/advanced/tests/codeception/bin/yii_unit new file mode 100644 index 0000000000..d315d58d36 --- /dev/null +++ b/apps/advanced/tests/codeception/bin/yii_unit @@ -0,0 +1,36 @@ +#!/usr/bin/env php + [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit', + ], + ], + 'controllerMap' => [ + 'fixture' => [ + 'class' => 'yii\faker\FixtureController', + 'fixtureDataPath' => dirname(__DIR__) . '_data/fixtures', + 'templatePath' => dirname(__DIR__) . '_data/templates' + ], + ], + ] +); + +$application = new yii\console\Application($config); +$exitCode = $application->run(); +exit($exitCode); diff --git a/apps/advanced/backend/tests/unit/yii.bat b/apps/advanced/tests/codeception/bin/yii_unit.bat similarity index 92% rename from apps/advanced/backend/tests/unit/yii.bat rename to apps/advanced/tests/codeception/bin/yii_unit.bat index 5e21e2e990..511e61d223 100644 --- a/apps/advanced/backend/tests/unit/yii.bat +++ b/apps/advanced/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/apps/advanced/common/tests/.gitignore b/apps/advanced/tests/codeception/common/.gitignore similarity index 100% rename from apps/advanced/common/tests/.gitignore rename to apps/advanced/tests/codeception/common/.gitignore diff --git a/apps/advanced/tests/codeception/common/_bootstrap.php b/apps/advanced/tests/codeception/common/_bootstrap.php new file mode 100644 index 0000000000..97053d97fb --- /dev/null +++ b/apps/advanced/tests/codeception/common/_bootstrap.php @@ -0,0 +1,16 @@ + [ 'class' => UserFixture::className(), - 'dataFile' => '@common/tests/fixtures/data/init_login.php', + 'dataFile' => '@codeception/common/fixtures/data/init_login.php', ], ]; } diff --git a/apps/advanced/console/tests/_log/.gitignore b/apps/advanced/tests/codeception/common/_log/.gitignore similarity index 100% rename from apps/advanced/console/tests/_log/.gitignore rename to apps/advanced/tests/codeception/common/_log/.gitignore diff --git a/apps/advanced/common/tests/_pages/LoginPage.php b/apps/advanced/tests/codeception/common/_pages/LoginPage.php similarity index 92% rename from apps/advanced/common/tests/_pages/LoginPage.php rename to apps/advanced/tests/codeception/common/_pages/LoginPage.php index b0d4c754f4..1293e0ea90 100644 --- a/apps/advanced/common/tests/_pages/LoginPage.php +++ b/apps/advanced/tests/codeception/common/_pages/LoginPage.php @@ -1,6 +1,6 @@ [ diff --git a/apps/advanced/common/tests/unit/fixtures/data/models/user.php b/apps/advanced/tests/codeception/common/unit/fixtures/data/models/user.php similarity index 100% rename from apps/advanced/common/tests/unit/fixtures/data/models/user.php rename to apps/advanced/tests/codeception/common/unit/fixtures/data/models/user.php diff --git a/apps/advanced/common/tests/unit/models/LoginFormTest.php b/apps/advanced/tests/codeception/common/unit/models/LoginFormTest.php similarity index 91% rename from apps/advanced/common/tests/unit/models/LoginFormTest.php rename to apps/advanced/tests/codeception/common/unit/models/LoginFormTest.php index ba83ef479a..2f786e067b 100644 --- a/apps/advanced/common/tests/unit/models/LoginFormTest.php +++ b/apps/advanced/tests/codeception/common/unit/models/LoginFormTest.php @@ -1,12 +1,12 @@ [ 'class' => UserFixture::className(), - 'dataFile' => '@common/tests/unit/fixtures/data/models/user.php' + 'dataFile' => '@codeception/common/unit/fixtures/data/models/user.php' ], ]; } diff --git a/apps/advanced/console/tests/.gitignore b/apps/advanced/tests/codeception/console/.gitignore similarity index 100% rename from apps/advanced/console/tests/.gitignore rename to apps/advanced/tests/codeception/console/.gitignore diff --git a/apps/advanced/tests/codeception/console/_bootstrap.php b/apps/advanced/tests/codeception/console/_bootstrap.php new file mode 100644 index 0000000000..97053d97fb --- /dev/null +++ b/apps/advanced/tests/codeception/console/_bootstrap.php @@ -0,0 +1,16 @@ +wantTo('ensure that about works'); diff --git a/apps/advanced/frontend/tests/acceptance/ContactCept.php b/apps/advanced/tests/codeception/frontend/acceptance/ContactCept.php similarity index 94% rename from apps/advanced/frontend/tests/acceptance/ContactCept.php rename to apps/advanced/tests/codeception/frontend/acceptance/ContactCept.php index 5a36e1d5f3..e76771a6f6 100644 --- a/apps/advanced/frontend/tests/acceptance/ContactCept.php +++ b/apps/advanced/tests/codeception/frontend/acceptance/ContactCept.php @@ -1,7 +1,6 @@ wantTo('ensure that contact works'); diff --git a/apps/advanced/frontend/tests/acceptance/HomeCept.php b/apps/advanced/tests/codeception/frontend/acceptance/HomeCept.php similarity index 86% rename from apps/advanced/frontend/tests/acceptance/HomeCept.php rename to apps/advanced/tests/codeception/frontend/acceptance/HomeCept.php index 4f5cc19966..c9eb9062f9 100644 --- a/apps/advanced/frontend/tests/acceptance/HomeCept.php +++ b/apps/advanced/tests/codeception/frontend/acceptance/HomeCept.php @@ -1,6 +1,5 @@ wantTo('ensure that home page works'); diff --git a/apps/advanced/frontend/tests/acceptance/LoginCept.php b/apps/advanced/tests/codeception/frontend/acceptance/LoginCept.php similarity index 92% rename from apps/advanced/frontend/tests/acceptance/LoginCept.php rename to apps/advanced/tests/codeception/frontend/acceptance/LoginCept.php index 3728baff1d..ba065ad489 100644 --- a/apps/advanced/frontend/tests/acceptance/LoginCept.php +++ b/apps/advanced/tests/codeception/frontend/acceptance/LoginCept.php @@ -1,7 +1,6 @@ wantTo('ensure login page works'); diff --git a/apps/advanced/frontend/tests/acceptance/SignupCest.php b/apps/advanced/tests/codeception/frontend/acceptance/SignupCest.php similarity index 96% rename from apps/advanced/frontend/tests/acceptance/SignupCest.php rename to apps/advanced/tests/codeception/frontend/acceptance/SignupCest.php index c086773ae1..b12566f6cd 100644 --- a/apps/advanced/frontend/tests/acceptance/SignupCest.php +++ b/apps/advanced/tests/codeception/frontend/acceptance/SignupCest.php @@ -1,8 +1,8 @@ [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance', + ], + ], + ] +); diff --git a/apps/advanced/frontend/codeception.yml b/apps/advanced/tests/codeception/frontend/codeception.yml similarity index 50% rename from apps/advanced/frontend/codeception.yml rename to apps/advanced/tests/codeception/frontend/codeception.yml index 7fa2a38f83..2476308037 100644 --- a/apps/advanced/frontend/codeception.yml +++ b/apps/advanced/tests/codeception/frontend/codeception.yml @@ -1,24 +1,17 @@ -namespace: frontend +namespace: codeception_frontend actor: Tester paths: - tests: tests - log: tests/_log - data: tests/_data - helpers: tests/_helpers + tests: . + log: _log + data: _data + helpers: _helpers settings: bootstrap: _bootstrap.php suite_class: \PHPUnit_Framework_TestSuite colors: true memory_limit: 1024M log: true -modules: - config: - Db: - dsn: '' - user: '' - password: '' - dump: tests/_data/dump.sql config: # the entry script URL (without host info) for functional and acceptance tests # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL - test_entry_url: /advanced/frontend/web/index-test.php + test_entry_url: /frontend/web/index-test.php diff --git a/apps/advanced/backend/tests/functional.suite.yml b/apps/advanced/tests/codeception/frontend/functional.suite.yml similarity index 78% rename from apps/advanced/backend/tests/functional.suite.yml rename to apps/advanced/tests/codeception/frontend/functional.suite.yml index 3c828f5c15..85003ea12e 100644 --- a/apps/advanced/backend/tests/functional.suite.yml +++ b/apps/advanced/tests/codeception/frontend/functional.suite.yml @@ -11,7 +11,7 @@ modules: enabled: - Filesystem - Yii2 - - common\tests\_helpers\FixtureHelper + - codeception\common\_helpers\FixtureHelper config: Yii2: - configFile: 'tests/functional/_config.php' + configFile: 'functional/_config.php' diff --git a/apps/advanced/frontend/tests/functional/AboutCept.php b/apps/advanced/tests/codeception/frontend/functional/AboutCept.php similarity index 61% rename from apps/advanced/frontend/tests/functional/AboutCept.php rename to apps/advanced/tests/codeception/frontend/functional/AboutCept.php index f9dd1a5a03..f65548ded1 100644 --- a/apps/advanced/frontend/tests/functional/AboutCept.php +++ b/apps/advanced/tests/codeception/frontend/functional/AboutCept.php @@ -1,7 +1,6 @@ wantTo('ensure that about works'); diff --git a/apps/advanced/frontend/tests/functional/ContactCept.php b/apps/advanced/tests/codeception/frontend/functional/ContactCept.php similarity index 94% rename from apps/advanced/frontend/tests/functional/ContactCept.php rename to apps/advanced/tests/codeception/frontend/functional/ContactCept.php index 774428c8bd..96efefd813 100644 --- a/apps/advanced/frontend/tests/functional/ContactCept.php +++ b/apps/advanced/tests/codeception/frontend/functional/ContactCept.php @@ -1,7 +1,6 @@ wantTo('ensure that contact works'); diff --git a/apps/advanced/frontend/tests/functional/HomeCept.php b/apps/advanced/tests/codeception/frontend/functional/HomeCept.php similarity index 86% rename from apps/advanced/frontend/tests/functional/HomeCept.php rename to apps/advanced/tests/codeception/frontend/functional/HomeCept.php index 1bc1d5b6ea..14a88a27b6 100644 --- a/apps/advanced/frontend/tests/functional/HomeCept.php +++ b/apps/advanced/tests/codeception/frontend/functional/HomeCept.php @@ -1,7 +1,5 @@ wantTo('ensure that home page works'); $I->amOnPage(Yii::$app->homeUrl); diff --git a/apps/advanced/backend/tests/functional/LoginCept.php b/apps/advanced/tests/codeception/frontend/functional/LoginCept.php similarity index 91% rename from apps/advanced/backend/tests/functional/LoginCept.php rename to apps/advanced/tests/codeception/frontend/functional/LoginCept.php index 5bba9594a7..4c81fd52a3 100644 --- a/apps/advanced/backend/tests/functional/LoginCept.php +++ b/apps/advanced/tests/codeception/frontend/functional/LoginCept.php @@ -1,7 +1,6 @@ wantTo('ensure login page works'); diff --git a/apps/advanced/frontend/tests/functional/SignupCest.php b/apps/advanced/tests/codeception/frontend/functional/SignupCest.php similarity index 96% rename from apps/advanced/frontend/tests/functional/SignupCest.php rename to apps/advanced/tests/codeception/frontend/functional/SignupCest.php index 5287aeec6a..d6bfef6433 100644 --- a/apps/advanced/frontend/tests/functional/SignupCest.php +++ b/apps/advanced/tests/codeception/frontend/functional/SignupCest.php @@ -1,8 +1,8 @@ [ diff --git a/apps/advanced/frontend/tests/unit.suite.yml b/apps/advanced/tests/codeception/frontend/unit.suite.yml similarity index 100% rename from apps/advanced/frontend/tests/unit.suite.yml rename to apps/advanced/tests/codeception/frontend/unit.suite.yml diff --git a/apps/advanced/tests/codeception/frontend/unit/DbTestCase.php b/apps/advanced/tests/codeception/frontend/unit/DbTestCase.php new file mode 100644 index 0000000000..c164872dd9 --- /dev/null +++ b/apps/advanced/tests/codeception/frontend/unit/DbTestCase.php @@ -0,0 +1,8 @@ + [ diff --git a/apps/advanced/frontend/tests/unit/fixtures/data/models/user.php b/apps/advanced/tests/codeception/frontend/unit/fixtures/data/models/user.php similarity index 100% rename from apps/advanced/frontend/tests/unit/fixtures/data/models/user.php rename to apps/advanced/tests/codeception/frontend/unit/fixtures/data/models/user.php diff --git a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php b/apps/advanced/tests/codeception/frontend/unit/models/ContactFormTest.php similarity index 95% rename from apps/advanced/frontend/tests/unit/models/ContactFormTest.php rename to apps/advanced/tests/codeception/frontend/unit/models/ContactFormTest.php index a30824ef3f..f2781a2e6a 100644 --- a/apps/advanced/frontend/tests/unit/models/ContactFormTest.php +++ b/apps/advanced/tests/codeception/frontend/unit/models/ContactFormTest.php @@ -1,9 +1,9 @@ [ 'class' => UserFixture::className(), - 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php' + 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php' ], ]; } diff --git a/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php b/apps/advanced/tests/codeception/frontend/unit/models/ResetPasswordFormTest.php similarity index 68% rename from apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php rename to apps/advanced/tests/codeception/frontend/unit/models/ResetPasswordFormTest.php index 419b424ee9..1997b2f4f7 100644 --- a/apps/advanced/frontend/tests/unit/models/ResetPasswordFormTest.php +++ b/apps/advanced/tests/codeception/frontend/unit/models/ResetPasswordFormTest.php @@ -1,16 +1,16 @@ [ 'class' => UserFixture::className(), - 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php' + 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php' ], ]; } diff --git a/apps/advanced/frontend/tests/unit/models/SignupFormTest.php b/apps/advanced/tests/codeception/frontend/unit/models/SignupFormTest.php similarity index 85% rename from apps/advanced/frontend/tests/unit/models/SignupFormTest.php rename to apps/advanced/tests/codeception/frontend/unit/models/SignupFormTest.php index d761421e13..ff8b56d288 100644 --- a/apps/advanced/frontend/tests/unit/models/SignupFormTest.php +++ b/apps/advanced/tests/codeception/frontend/unit/models/SignupFormTest.php @@ -1,9 +1,9 @@ [ 'class' => UserFixture::className(), - 'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php', + 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php', ], ]; } diff --git a/apps/basic/composer.json b/apps/basic/composer.json index a21128bf31..607accb1b8 100644 --- a/apps/basic/composer.json +++ b/apps/basic/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/apps/basic/tests/README.md b/apps/basic/tests/README.md index e1aed9a6e1..1c4b50bcac 100644 --- a/apps/basic/tests/README.md +++ b/apps/basic/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/apps/basic/tests/_data/dump.sql b/apps/basic/tests/_data/dump.sql deleted file mode 100644 index 4bc742ce67..0000000000 --- a/apps/basic/tests/_data/dump.sql +++ /dev/null @@ -1 +0,0 @@ -/* Replace this file with actual dump of your database */ \ No newline at end of file diff --git a/apps/basic/tests/acceptance/_console.php b/apps/basic/tests/acceptance/_console.php deleted file mode 100644 index 03cdd1ff6f..0000000000 --- a/apps/basic/tests/acceptance/_console.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', - ], - ], - ] -); diff --git a/apps/basic/tests/acceptance/yii b/apps/basic/tests/acceptance/yii deleted file mode 100644 index e587ba4004..0000000000 --- a/apps/basic/tests/acceptance/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/basic/tests/acceptance/yii.bat b/apps/basic/tests/acceptance/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/basic/tests/acceptance/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/basic/codeception.yml b/apps/basic/tests/codeception.yml similarity index 62% rename from apps/basic/codeception.yml rename to apps/basic/tests/codeception.yml index 496ebd9c3f..64952529e2 100644 --- a/apps/basic/codeception.yml +++ b/apps/basic/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/apps/basic/tests/.gitignore b/apps/basic/tests/codeception/.gitignore similarity index 100% rename from apps/basic/tests/.gitignore rename to apps/basic/tests/codeception/.gitignore diff --git a/apps/basic/tests/_bootstrap.php b/apps/basic/tests/codeception/_bootstrap.php similarity index 65% rename from apps/basic/tests/_bootstrap.php rename to apps/basic/tests/codeception/_bootstrap.php index 4890b3ed7a..ecd76de938 100644 --- a/apps/basic/tests/_bootstrap.php +++ b/apps/basic/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/apps/basic/tests/_config.php b/apps/basic/tests/codeception/_config.php similarity index 100% rename from apps/basic/tests/_config.php rename to apps/basic/tests/codeception/_config.php diff --git a/apps/advanced/backend/tests/_data/dump.sql b/apps/basic/tests/codeception/_data/dump.sql similarity index 100% rename from apps/advanced/backend/tests/_data/dump.sql rename to apps/basic/tests/codeception/_data/dump.sql diff --git a/apps/basic/tests/_log/.gitignore b/apps/basic/tests/codeception/_log/.gitignore similarity index 100% rename from apps/basic/tests/_log/.gitignore rename to apps/basic/tests/codeception/_log/.gitignore diff --git a/apps/basic/tests/_pages/AboutPage.php b/apps/basic/tests/codeception/_pages/AboutPage.php similarity index 78% rename from apps/basic/tests/_pages/AboutPage.php rename to apps/basic/tests/codeception/_pages/AboutPage.php index 77acdb8159..727cd38592 100644 --- a/apps/basic/tests/_pages/AboutPage.php +++ b/apps/basic/tests/codeception/_pages/AboutPage.php @@ -1,6 +1,6 @@ wantTo('ensure that about works'); diff --git a/apps/basic/tests/acceptance/ContactCept.php b/apps/basic/tests/codeception/acceptance/ContactCept.php similarity index 97% rename from apps/basic/tests/acceptance/ContactCept.php rename to apps/basic/tests/codeception/acceptance/ContactCept.php index e76ac9beb7..50aa69acb4 100644 --- a/apps/basic/tests/acceptance/ContactCept.php +++ b/apps/basic/tests/codeception/acceptance/ContactCept.php @@ -1,6 +1,6 @@ wantTo('ensure that contact works'); diff --git a/apps/basic/tests/acceptance/HomeCept.php b/apps/basic/tests/codeception/acceptance/HomeCept.php similarity index 100% rename from apps/basic/tests/acceptance/HomeCept.php rename to apps/basic/tests/codeception/acceptance/HomeCept.php diff --git a/apps/basic/tests/acceptance/LoginCept.php b/apps/basic/tests/codeception/acceptance/LoginCept.php similarity index 95% rename from apps/basic/tests/acceptance/LoginCept.php rename to apps/basic/tests/codeception/acceptance/LoginCept.php index c7c9ae3069..ff093b3bd3 100644 --- a/apps/basic/tests/acceptance/LoginCept.php +++ b/apps/basic/tests/codeception/acceptance/LoginCept.php @@ -1,6 +1,6 @@ wantTo('ensure that login works'); diff --git a/apps/basic/tests/acceptance/_bootstrap.php b/apps/basic/tests/codeception/acceptance/_bootstrap.php similarity index 100% rename from apps/basic/tests/acceptance/_bootstrap.php rename to apps/basic/tests/codeception/acceptance/_bootstrap.php diff --git a/apps/basic/tests/acceptance/_config.php b/apps/basic/tests/codeception/acceptance/_config.php similarity index 83% rename from apps/basic/tests/acceptance/_config.php rename to apps/basic/tests/codeception/acceptance/_config.php index 857a804f49..d620a7d9e9 100644 --- a/apps/basic/tests/acceptance/_config.php +++ b/apps/basic/tests/codeception/acceptance/_config.php @@ -1,7 +1,7 @@ [ diff --git a/apps/basic/tests/_console_bootstrap.php b/apps/basic/tests/codeception/bin/_console_bootstrap.php similarity index 62% rename from apps/basic/tests/_console_bootstrap.php rename to apps/basic/tests/codeception/bin/_console_bootstrap.php index 81287f3d86..eff8b403fe 100644 --- a/apps/basic/tests/_console_bootstrap.php +++ b/apps/basic/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/apps/basic/tests/codeception/bin/yii_acceptance b/apps/basic/tests/codeception/bin/yii_acceptance new file mode 100644 index 0000000000..a02d9daf1f --- /dev/null +++ b/apps/basic/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/apps/basic/tests/codeception/bin/yii_acceptance.bat b/apps/basic/tests/codeception/bin/yii_acceptance.bat new file mode 100644 index 0000000000..389f89325d --- /dev/null +++ b/apps/basic/tests/codeception/bin/yii_acceptance.bat @@ -0,0 +1,20 @@ +@echo off + +rem ------------------------------------------------------------- +rem Yii command line bootstrap script for Windows. +rem +rem @author Qiang Xue +rem @link http://www.yiiframework.com/ +rem @copyright Copyright © 2012 Yii Software LLC +rem @license http://www.yiiframework.com/license/ +rem ------------------------------------------------------------- + +@setlocal + +set YII_PATH=%~dp0 + +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe + +"%PHP_COMMAND%" "%YII_PATH%yii_acceptance" %* + +@endlocal diff --git a/apps/basic/tests/codeception/bin/yii_functional b/apps/basic/tests/codeception/bin/yii_functional new file mode 100644 index 0000000000..44051e2caf --- /dev/null +++ b/apps/basic/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/apps/basic/tests/codeception/bin/yii_functional.bat b/apps/basic/tests/codeception/bin/yii_functional.bat new file mode 100644 index 0000000000..98fae88531 --- /dev/null +++ b/apps/basic/tests/codeception/bin/yii_functional.bat @@ -0,0 +1,20 @@ +@echo off + +rem ------------------------------------------------------------- +rem Yii command line bootstrap script for Windows. +rem +rem @author Qiang Xue +rem @link http://www.yiiframework.com/ +rem @copyright Copyright © 2012 Yii Software LLC +rem @license http://www.yiiframework.com/license/ +rem ------------------------------------------------------------- + +@setlocal + +set YII_PATH=%~dp0 + +if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe + +"%PHP_COMMAND%" "%YII_PATH%yii_functional" %* + +@endlocal diff --git a/apps/basic/tests/codeception/bin/yii_unit b/apps/basic/tests/codeception/bin/yii_unit new file mode 100644 index 0000000000..e9b799903d --- /dev/null +++ b/apps/basic/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/apps/advanced/common/tests/unit/yii.bat b/apps/basic/tests/codeception/bin/yii_unit.bat similarity index 92% rename from apps/advanced/common/tests/unit/yii.bat rename to apps/basic/tests/codeception/bin/yii_unit.bat index 5e21e2e990..511e61d223 100644 --- a/apps/advanced/common/tests/unit/yii.bat +++ b/apps/basic/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/apps/basic/tests/functional.suite.yml b/apps/basic/tests/codeception/functional.suite.yml similarity index 85% rename from apps/basic/tests/functional.suite.yml rename to apps/basic/tests/codeception/functional.suite.yml index 916ef1aaad..3b5008139a 100644 --- a/apps/basic/tests/functional.suite.yml +++ b/apps/basic/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/apps/basic/tests/functional/AboutCept.php b/apps/basic/tests/codeception/functional/AboutCept.php similarity index 78% rename from apps/basic/tests/functional/AboutCept.php rename to apps/basic/tests/codeception/functional/AboutCept.php index 1875c2e113..6312061444 100644 --- a/apps/basic/tests/functional/AboutCept.php +++ b/apps/basic/tests/codeception/functional/AboutCept.php @@ -1,6 +1,6 @@ wantTo('ensure that about works'); diff --git a/apps/basic/tests/functional/ContactCept.php b/apps/basic/tests/codeception/functional/ContactCept.php similarity index 97% rename from apps/basic/tests/functional/ContactCept.php rename to apps/basic/tests/codeception/functional/ContactCept.php index 49d7735fd7..f13b51cf28 100644 --- a/apps/basic/tests/functional/ContactCept.php +++ b/apps/basic/tests/codeception/functional/ContactCept.php @@ -1,6 +1,6 @@ wantTo('ensure that contact works'); diff --git a/apps/basic/tests/functional/HomeCept.php b/apps/basic/tests/codeception/functional/HomeCept.php similarity index 100% rename from apps/basic/tests/functional/HomeCept.php rename to apps/basic/tests/codeception/functional/HomeCept.php diff --git a/apps/basic/tests/functional/LoginCept.php b/apps/basic/tests/codeception/functional/LoginCept.php similarity index 95% rename from apps/basic/tests/functional/LoginCept.php rename to apps/basic/tests/codeception/functional/LoginCept.php index e5285cdb24..77189b8854 100644 --- a/apps/basic/tests/functional/LoginCept.php +++ b/apps/basic/tests/codeception/functional/LoginCept.php @@ -1,6 +1,6 @@ wantTo('ensure that login works'); diff --git a/apps/basic/tests/functional/_bootstrap.php b/apps/basic/tests/codeception/functional/_bootstrap.php similarity index 100% rename from apps/basic/tests/functional/_bootstrap.php rename to apps/basic/tests/codeception/functional/_bootstrap.php diff --git a/apps/basic/tests/functional/_config.php b/apps/basic/tests/codeception/functional/_config.php similarity index 87% rename from apps/basic/tests/functional/_config.php rename to apps/basic/tests/codeception/functional/_config.php index 512e802bb2..3d50fdbaf0 100644 --- a/apps/basic/tests/functional/_config.php +++ b/apps/basic/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/apps/basic/tests/unit.suite.yml b/apps/basic/tests/codeception/unit.suite.yml similarity index 100% rename from apps/basic/tests/unit.suite.yml rename to apps/basic/tests/codeception/unit.suite.yml diff --git a/apps/basic/tests/unit/_bootstrap.php b/apps/basic/tests/codeception/unit/_bootstrap.php similarity index 100% rename from apps/basic/tests/unit/_bootstrap.php rename to apps/basic/tests/codeception/unit/_bootstrap.php diff --git a/apps/basic/tests/unit/_config.php b/apps/basic/tests/codeception/unit/_config.php similarity index 83% rename from apps/basic/tests/unit/_config.php rename to apps/basic/tests/codeception/unit/_config.php index 2559ef31e0..36b0114469 100644 --- a/apps/basic/tests/unit/_config.php +++ b/apps/basic/tests/codeception/unit/_config.php @@ -1,7 +1,7 @@ [ diff --git a/apps/basic/tests/unit/fixtures/.gitkeep b/apps/basic/tests/codeception/unit/fixtures/.gitkeep similarity index 100% rename from apps/basic/tests/unit/fixtures/.gitkeep rename to apps/basic/tests/codeception/unit/fixtures/.gitkeep diff --git a/apps/basic/tests/unit/fixtures/data/.gitkeep b/apps/basic/tests/codeception/unit/fixtures/data/.gitkeep similarity index 100% rename from apps/basic/tests/unit/fixtures/data/.gitkeep rename to apps/basic/tests/codeception/unit/fixtures/data/.gitkeep diff --git a/apps/basic/tests/unit/models/ContactFormTest.php b/apps/basic/tests/codeception/unit/models/ContactFormTest.php similarity index 98% rename from apps/basic/tests/unit/models/ContactFormTest.php rename to apps/basic/tests/codeception/unit/models/ContactFormTest.php index 6e69cecd3d..8adda18c61 100644 --- a/apps/basic/tests/unit/models/ContactFormTest.php +++ b/apps/basic/tests/codeception/unit/models/ContactFormTest.php @@ -1,6 +1,6 @@ [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', - ], - ], - ] -); diff --git a/apps/basic/tests/functional/yii b/apps/basic/tests/functional/yii deleted file mode 100644 index e587ba4004..0000000000 --- a/apps/basic/tests/functional/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/basic/tests/functional/yii.bat b/apps/basic/tests/functional/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/basic/tests/functional/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/basic/tests/unit/_console.php b/apps/basic/tests/unit/_console.php deleted file mode 100644 index 04272a3216..0000000000 --- a/apps/basic/tests/unit/_console.php +++ /dev/null @@ -1,13 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit', - ], - ], - ] -); diff --git a/apps/basic/tests/unit/yii b/apps/basic/tests/unit/yii deleted file mode 100644 index e587ba4004..0000000000 --- a/apps/basic/tests/unit/yii +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env php -run(); -exit($exitCode); diff --git a/apps/basic/tests/unit/yii.bat b/apps/basic/tests/unit/yii.bat deleted file mode 100644 index 5e21e2e990..0000000000 --- a/apps/basic/tests/unit/yii.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off - -rem ------------------------------------------------------------- -rem Yii command line bootstrap script for Windows. -rem -rem @author Qiang Xue -rem @link http://www.yiiframework.com/ -rem @copyright Copyright © 2012 Yii Software LLC -rem @license http://www.yiiframework.com/license/ -rem ------------------------------------------------------------- - -@setlocal - -set YII_PATH=%~dp0 - -if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe - -"%PHP_COMMAND%" "%YII_PATH%yii" %* - -@endlocal diff --git a/apps/basic/web/index-test.php b/apps/basic/web/index-test.php index 326608d21c..dd8a4965c2 100644 --- a/apps/basic/web/index-test.php +++ b/apps/basic/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(); diff --git a/docs/guide/test-acceptance.md b/docs/guide/test-acceptance.md index e3871549b7..c36d9a4fb1 100644 --- a/docs/guide/test-acceptance.md +++ b/docs/guide/test-acceptance.md @@ -4,23 +4,8 @@ Acceptance Tests > Note: This section is under development. - http://codeception.com/docs/04-AcceptanceTests -- https://github.com/yiisoft/yii2/blob/master/apps/advanced/README.md#testing -- https://github.com/yiisoft/yii2/blob/master/apps/basic/tests/README.md -How to run webserver --------------------- +Running basic and advanced template acceptance tests +---------------------------------------------------- -In order to perform acceptance tests you need a web server. Since PHP 5.4 has built-in one, we can use it. For the basic -application template it would be: - -``` -cd web -php -S localhost:8080 -``` - -In order for the tests to work correctly you need to adjust `TEST_ENTRY_URL` in `_bootstrap.php` file. It should point -to `index-test.php` of your webserver. Since we're running directly from its directory the line would be: - -```php -defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/index-test.php'); -``` +Please refer to instructions provided in `apps/advanced/tests/README.md` and `apps/basic/tests/README.md`. diff --git a/docs/guide/test-functional.md b/docs/guide/test-functional.md index f5eac8a900..6041bed707 100644 --- a/docs/guide/test-functional.md +++ b/docs/guide/test-functional.md @@ -1,8 +1,11 @@ Functional Tests ----------------- +================ > Note: This section is under development. - http://codeception.com/docs/05-FunctionalTests -- https://github.com/yiisoft/yii2/blob/master/apps/advanced/README.md#testing -- https://github.com/yiisoft/yii2/blob/master/apps/basic/tests/README.md + +Running basic and advanced template functional tests +---------------------------------------------------- + +Please refer to instructions provided in `apps/advanced/tests/README.md` and `apps/basic/tests/README.md`. \ No newline at end of file diff --git a/docs/guide/test-overview.md b/docs/guide/test-overview.md index 089e3cb878..3d20db3818 100644 --- a/docs/guide/test-overview.md +++ b/docs/guide/test-overview.md @@ -34,4 +34,11 @@ composer global require "codeception/specify=*" composer global require "codeception/verify=*" ``` -That's it. Now we're able to use `codecept` from command line. +If you've never used Composer for global packages run `composer global status`. It should output: + +``` +Changed current directory to +``` + +Then add `/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command +line globally. diff --git a/docs/guide/test-unit.md b/docs/guide/test-unit.md index 9a2c41f43f..fd9be74f2d 100644 --- a/docs/guide/test-unit.md +++ b/docs/guide/test-unit.md @@ -3,11 +3,6 @@ Unit Tests > Note: This section is under development. -TODO: - -- https://github.com/yiisoft/yii2/blob/master/apps/advanced/README.md#testing -- https://github.com/yiisoft/yii2/blob/master/apps/basic/tests/README.md - A unit test verifies that a single unit of code is working as expected. In object-oriented programming, the most basic code unit is a class. A unit test thus mainly needs to verify that each of the class interface methods works properly. That is, given different input parameters, the test verifies the method returns expected results. @@ -16,4 +11,9 @@ Unit tests are usually developed by people who write the classes being tested. Unit testing in Yii is built on top of PHPUnit and, optionally, Codeception so it's recommended to go through their docs: - [PHPUnit docs starting from chapter 2](http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html). -- [Codeception Unit Tests](http://codeception.com/docs/06-UnitTests). \ No newline at end of file +- [Codeception Unit Tests](http://codeception.com/docs/06-UnitTests). + +Running basic and advanced template unit tests +---------------------------------------------- + +Please refer to instructions provided in `apps/advanced/tests/README.md` and `apps/basic/tests/README.md`. diff --git a/docs/internals/getting-started.md b/docs/internals/getting-started.md index e0f4b6d6ad..41c6483ec1 100644 --- a/docs/internals/getting-started.md +++ b/docs/internals/getting-started.md @@ -29,57 +29,6 @@ You can now execute unit tests by running `phpunit`. You may limit the tests to a group of tests you are working on e.g. to run only tests for the validators and redis `phpunit --group=validators,redis`. -Functional and acceptance tests -------------------------------- - -In order to run functional and acceptance tests you need to install additional composer packages for the application you're going -to test. Add the following four packages to your `composer.json` `require-dev` section: - -``` -"yiisoft/yii2-codeception": "*", -``` - -For advanced application you may need `yiisoft/yii2-faker: *` as well. - -Then for the basic application template run `./build/build app/link basic`. For advanced template command is -`./build/build app/link advanced`. - -After package installation is complete you can run the following for basic app: - -``` -cd apps/basic -codecept build -codecept run -``` - -For advanced application frontend it will be: - -``` -cd apps/advanced/frontend -codecept build -codecept run -``` - -Note that you need a running webserver in order to pass acceptance tests. That can be easily achieved with PHP's built-in -webserver: - -``` -cd apps/advanced/frontend/www -php -S 127.0.0.1:8080 -``` - -Note that you should have Codeception and PHPUnit installed globally: - -``` -composer global require "phpunit/phpunit=4.1.*" -composer global require "codeception/codeception=2.0.*" -composer global require "codeception/specify=*" -composer global require "codeception/verify=*" -``` - -After running commands you'll see "Changed current directory to /your/global/composer/dir" message. If it's the -first time you're installing a package globally you need to add `/your/global/composer/dir/vendor/bin/` to your `PATH`. - Extensions ---------- @@ -89,3 +38,7 @@ Just add them to the `composer.json` as you would normally do e.g. add `"yiisoft Running `./build/build app/link basic` will install the extension and its dependecies and create a symlink to `extensions/redis` so you are not working the composer vendor dir but the yii2 repo directly. +Functional and acceptance tests for applications +------------------------------------------------ + +See `apps/advanced/tests/README.md` and `apps/basic/tests/README.md` to learn about how to run Codeception tests. diff --git a/extensions/codeception/TestCase.php b/extensions/codeception/TestCase.php index e889249b0a..c6f31073e4 100644 --- a/extensions/codeception/TestCase.php +++ b/extensions/codeception/TestCase.php @@ -31,7 +31,7 @@ class TestCase extends Test * The application configuration array may contain an optional `class` element which specifies the class * name of the application instance to be created. By default, a [[\yii\web\Application]] instance will be created. */ - public $appConfig = '@tests/unit/_config.php'; + public $appConfig = '@codeception/unit/_config.php'; /** diff --git a/tests/unit/data/travis/init-apps.sh b/tests/unit/data/travis/init-apps.sh index 7c5c27aa02..214e283a15 100755 --- a/tests/unit/data/travis/init-apps.sh +++ b/tests/unit/data/travis/init-apps.sh @@ -7,8 +7,9 @@ else mysql -e 'CREATE DATABASE yii2_advanced_acceptance;'; mysql -e 'CREATE DATABASE yii2_advanced_functional;'; mysql -e 'CREATE DATABASE yii2_advanced_unit;'; - cd apps/advanced/frontend/tests/acceptance && php yii migrate --interactive=0 - cd ../functional && php yii migrate --interactive=0 - cd ../unit && php yii migrate --interactive=0 && cd ../../../../.. - + cd apps/advanced/tests/codeception/bin + php yii_acceptance migrate --interactive=0 + php yii_functional migrate --interactive=0 + php yii_unit migrate --interactive=0 + cd ../../../../.. fi diff --git a/tests/unit/data/travis/setup-apps.sh b/tests/unit/data/travis/setup-apps.sh index 9b52ad7dee..fdb168add4 100755 --- a/tests/unit/data/travis/setup-apps.sh +++ b/tests/unit/data/travis/setup-apps.sh @@ -9,7 +9,7 @@ else composer install --dev --prefer-dist -d apps/basic cd apps/basic && composer require --dev codeception/codeception:2.0.* codeception/specify:* codeception/verify:* sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" config/web.php - php vendor/bin/codecept build && cd ../.. + cd tests && php vendor/bin/codecept build && cd ../../.. # advanced application: @@ -20,9 +20,9 @@ else sed -i s/root/travis/ common/config/main-local.php sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" frontend/config/main.php sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" backend/config/main.php - cd backend && php ../vendor/bin/codecept build - cd ../common && php ../vendor/bin/codecept build - cd ../frontend && php ../vendor/bin/codecept build && cd ../../.. + cd tests/codeception/backend && php ../../../vendor/bin/codecept build + cd ../../../common && php ../../../vendor/bin/codecept build + cd ../../../frontend && php ../../../vendor/bin/codecept build && cd ../../../../../.. # boot server cd apps && php -S localhost:8080 > /dev/null 2>&1 &