Commit 6f3832f3 by Alexander Makarov

Merge pull request #4723 from yiisoft/codeception-test-adjustments

Codeception test adjustments for basic and advanced applications
parents 1cfa5bc9 480b03be
...@@ -27,12 +27,17 @@ addons: ...@@ -27,12 +27,17 @@ addons:
install: install:
- composer self-update && composer --version - composer self-update && composer --version
- export PATH="$HOME/.composer/vendor/bin:$PATH"
# core framework: # core framework:
- composer install --prefer-dist - composer install --prefer-dist
- tests/unit/data/travis/mongodb-setup.sh - tests/unit/data/travis/mongodb-setup.sh
- tests/unit/data/travis/apc-setup.sh - tests/unit/data/travis/apc-setup.sh
- tests/unit/data/travis/memcache-setup.sh - tests/unit/data/travis/memcache-setup.sh
- tests/unit/data/travis/cubrid-setup.sh - tests/unit/data/travis/cubrid-setup.sh
# codeception
- composer global require "codeception/codeception=2.0.*"
- composer global require "codeception/specify=*"
- composer global require "codeception/verify=*"
# basic and advanced application: # basic and advanced application:
- tests/unit/data/travis/setup-apps.sh - tests/unit/data/travis/setup-apps.sh
...@@ -51,10 +56,21 @@ script: ...@@ -51,10 +56,21 @@ script:
if (php --version | grep -i HipHop > /dev/null); then if (php --version | grep -i HipHop > /dev/null); then
echo "skipping application tests on HHVM" echo "skipping application tests on HHVM"
else else
cd apps/basic && php vendor/bin/codecept run cd apps/basic/web
cd ../advanced/backend && ../vendor/bin/codecept run php -S localhost:8080 > /dev/null 2>&1 &
cd ../common && ../vendor/bin/codecept run PHP_PID=$!
cd ../frontend && ../vendor/bin/codecept run cd ../tests
codecept run
BASIC_EXIT=$?
kill -9 $PHP_PID
cd ../../advanced
php -S localhost:8080 > /dev/null 2>&1 &
PHP_PID=$!
cd tests
codecept run
ADVANCED_EXIT=$?
kill -9 $PHP_PID
exit $BASIC_EXIT && $ADVANCED_EXIT
fi fi
after_script: after_script:
......
...@@ -95,35 +95,3 @@ the installed application. You only need to do these once for all. ...@@ -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. 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. 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.
# these files are auto generated by codeception build
/unit/CodeGuy.php
/functional/TestGuy.php
/acceptance/WebGuy.php
<?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/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/aliases.php');
// set correct script paths
// the entry script file path for functional and acceptance tests
$_SERVER['SCRIPT_FILENAME'] = dirname(__DIR__) . '/web/index-test.php';
$_SERVER['SCRIPT_NAME'] = \Codeception\Configuration::config()['config']['test_entry_url'];
$_SERVER['SERVER_NAME'] = 'localhost';
/* Replace this file with actual dump of your database */
\ No newline at end of file
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
],
]
);
<?php
// set correct script paths
$_SERVER['SCRIPT_FILENAME'] = dirname(dirname(__DIR__)) . '/web/index-test.php';
$_SERVER['SCRIPT_NAME'] = \Codeception\Configuration::config()['config']['test_entry_url'];;
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'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'
],
],
]
);
include:
- common
- console
- backend
- frontend
paths:
log: tests/_log
settings:
colors: true
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
# these files are auto generated by codeception build
/unit/CodeGuy.php
/functional/TestGuy.php
/acceptance/WebGuy.php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
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('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
/* Replace this file with actual dump of your database */
\ No newline at end of file
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
],
],
'id' => 'app-common',
'basePath' => dirname(__DIR__),
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
[
'components' => [
'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'
],
],
]
);
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php');
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
...@@ -22,13 +22,8 @@ ...@@ -22,13 +22,8 @@
"require-dev": { "require-dev": {
"yiisoft/yii2-codeception": "*", "yiisoft/yii2-codeception": "*",
"yiisoft/yii2-debug": "*", "yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*" "yiisoft/yii2-gii": "*",
}, "yiisoft/yii2-faker": "*"
"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"
}, },
"scripts": { "scripts": {
"post-create-project-cmd": [ "post-create-project-cmd": [
......
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
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
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('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
/* Replace this file with actual dump of your database */
\ No newline at end of file
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
[
'components' => [
'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'
],
],
]
);
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php');
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
# these files are auto generated by codeception build
/unit/CodeGuy.php
/functional/TestGuy.php
/acceptance/WebGuy.php
<?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/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/aliases.php');
// set correct script paths
// the entry script file path for functional and acceptance tests
$_SERVER['SCRIPT_FILENAME'] = dirname(__DIR__) . '/web/index-test.php';
$_SERVER['SCRIPT_NAME'] = \Codeception\Configuration::config()['config']['test_entry_url'];
$_SERVER['SERVER_NAME'] = 'localhost';
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
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('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
/* Replace this file with actual dump of your database */
\ No newline at end of file
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
],
]
);
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php');
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
<?php
// set correct script paths
$_SERVER['SCRIPT_FILENAME'] = dirname(dirname(__DIR__)) . '/web/index-test.php';
$_SERVER['SCRIPT_NAME'] = \Codeception\Configuration::config()['config']['test_entry_url'];;
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_functional',
],
],
]
);
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php');
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 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
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../config/main.php'),
require(__DIR__ . '/../../config/main-local.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
],
],
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../common/config/main.php'),
require(__DIR__ . '/../../../common/config/main-local.php'),
require(__DIR__ . '/../../../console/config/main.php'),
require(__DIR__ . '/../../../console/config/main-local.php'),
[
'components' => [
'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'
],
],
]
);
#!/usr/bin/env php
<?php
/**
* Yii console bootstrap file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
// fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php');
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 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
...@@ -5,7 +5,7 @@ rem Yii command line init script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line init script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
......
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 <directory>
```
Then add `<directory>/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.
include:
- codeception/common
- codeception/console
- codeception/backend
- codeception/frontend
paths:
log: codeception/_output
settings:
colors: true
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
defined('YII_BACKEND_TEST_ENTRY_URL') or define('YII_BACKEND_TEST_ENTRY_URL', \Codeception\Configuration::config()['config']['test_entry_url']);
defined('YII_TEST_BACKEND_ENTRY_FILE') or define('YII_TEST_BACKEND_ENTRY_FILE', YII_ROOT_DIR . '/backend/web/index-test.php');
require_once(YII_ROOT_DIR . '/vendor/autoload.php');
require_once(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
require(YII_ROOT_DIR . '/common/config/aliases.php');
// set correct script paths
// the entry script file path for functional and acceptance tests
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_BACKEND_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_BACKEND_TEST_ENTRY_URL;
$_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@codeception', dirname(__DIR__));
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: WebGuy class_name: AcceptanceTester
modules: modules:
enabled: enabled:
- PhpBrowser - PhpBrowser
- common\tests\_helpers\FixtureHelper - codeception\common\_support\FixtureHelper
# you can use WebDriver instead of PhpBrowser to test javascript and ajax. # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies, # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
......
<?php <?php
use common\tests\_pages\LoginPage; use codeception_backend\AcceptanceTester;
use backend\WebGuy; use codeception\common\_pages\LoginPage;
$I = new WebGuy($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('ensure login page works'); $I->wantTo('ensure login page works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/backend/acceptance.php'));
namespace: codeception_backend
actor: Tester
paths:
tests: .
log: _output
data: _data
helpers: _support
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
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: /backend/web/index-test.php
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
#basic/web/index.php #basic/web/index.php
class_name: TestGuy class_name: FunctionalTester
modules: modules:
enabled: enabled:
- Filesystem - Filesystem
- Yii2 - Yii2
- common\tests\_helpers\FixtureHelper - codeception\common\_support\FixtureHelper
config: config:
Yii2: Yii2:
configFile: 'tests/functional/_config.php' configFile: '../config/backend/functional.php'
<?php <?php
use common\tests\_pages\LoginPage; use codeception_backend\FunctionalTester;
use backend\TestGuy; use codeception\common\_pages\LoginPage;
$I = new TestGuy($scenario); $I = new FunctionalTester($scenario);
$I->wantTo('ensure login page works'); $I->wantTo('ensure login page works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/backend/functional.php'));
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
# suite for unit (internal) tests. # suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy class_name: UnitTester
...@@ -4,5 +4,5 @@ namespace backend\tests\unit; ...@@ -4,5 +4,5 @@ namespace backend\tests\unit;
class DbTestCase extends \yii\codeception\DbTestCase class DbTestCase extends \yii\codeception\DbTestCase
{ {
public $appConfig = '@backend/tests/unit/_config.php'; public $appConfig = '@codeception/config/backend/unit.php';
} }
...@@ -4,5 +4,5 @@ namespace backend\tests\unit; ...@@ -4,5 +4,5 @@ namespace backend\tests\unit;
class TestCase extends \yii\codeception\TestCase class TestCase extends \yii\codeception\TestCase
{ {
public $appConfig = '@backend/tests/unit/_config.php'; public $appConfig = '@codeception/config/backend/unit.php';
} }
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../../vendor/autoload.php'); defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require_once(__DIR__ . '/../../common/config/aliases.php'); require_once(YII_ROOT_DIR . '/vendor/autoload.php');
require_once(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
require_once(YII_ROOT_DIR . '/common/config/aliases.php');
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_ENV') or define('YII_ENV', 'test');
...@@ -8,13 +8,24 @@ ...@@ -8,13 +8,24 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
// fcgi doesn't have STDIN and STDOUT defined by default require_once __DIR__ . '/_bootstrap.php';
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
$config = require(__DIR__ . '/_console.php'); require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/console/config/main.php'),
require(YII_ROOT_DIR . '/console/config/main-local.php'),
require(dirname(__DIR__) . '/config/acceptance.php'),
[
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'fixtureDataPath' => dirname(__DIR__) . 'common/fixtures',
'templatePath' => dirname(__DIR__) . 'common/templates'
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_acceptance" %*
@endlocal @endlocal
...@@ -8,13 +8,24 @@ ...@@ -8,13 +8,24 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
// fcgi doesn't have STDIN and STDOUT defined by default require_once __DIR__ . '/_bootstrap.php';
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
$config = require(__DIR__ . '/_console.php'); require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/console/config/main.php'),
require(YII_ROOT_DIR . '/console/config/main-local.php'),
require(dirname(__DIR__) . '/config/functional.php'),
[
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'fixtureDataPath' => dirname(__DIR__) . 'common/fixtures',
'templatePath' => dirname(__DIR__) . 'common/templates'
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_functional" %*
@endlocal @endlocal
...@@ -8,13 +8,24 @@ ...@@ -8,13 +8,24 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
// fcgi doesn't have STDIN and STDOUT defined by default require_once __DIR__ . '/_bootstrap.php';
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require_once(__DIR__ . '/../_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
$config = require(__DIR__ . '/_console.php'); require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/console/config/main.php'),
require(YII_ROOT_DIR . '/console/config/main-local.php'),
require(dirname(__DIR__) . '/config/unit.php'),
[
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'fixtureDataPath' => dirname(__DIR__) . 'common/fixtures',
'templatePath' => dirname(__DIR__) . 'common/templates'
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_unit" %*
@endlocal @endlocal
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
require_once(YII_ROOT_DIR . '/vendor/autoload.php');
require_once(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
require(YII_ROOT_DIR . '/common/config/aliases.php');
// set correct script paths
$_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@codeception', dirname(__DIR__));
\ No newline at end of file
<?php <?php
namespace tests\_pages; namespace codeception\common\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents loging page
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester|\codeception_backend\AcceptanceTester|\codeception_backend\FunctionalTester $actor
*/
class LoginPage extends BasePage class LoginPage extends BasePage
{ {
public $route = 'site/login'; public $route = 'site/login';
...@@ -14,8 +18,8 @@ class LoginPage extends BasePage ...@@ -14,8 +18,8 @@ class LoginPage extends BasePage
*/ */
public function login($username, $password) public function login($username, $password)
{ {
$this->guy->fillField('input[name="LoginForm[username]"]', $username); $this->actor->fillField('input[name="LoginForm[username]"]', $username);
$this->guy->fillField('input[name="LoginForm[password]"]', $password); $this->actor->fillField('input[name="LoginForm[password]"]', $password);
$this->guy->click('login-button'); $this->actor->click('login-button');
} }
} }
<?php <?php
namespace common\tests\_helpers; namespace codeception\common\_support;
use codeception\common\fixtures\UserFixture;
use Codeception\Module; use Codeception\Module;
use yii\test\FixtureTrait; use yii\test\FixtureTrait;
use common\tests\fixtures\UserFixture;
/** /**
* This helper is used to populate database with needed fixtures before any tests should be run. * This helper is used to populate database with needed fixtures before any tests should be run.
...@@ -16,7 +16,7 @@ class FixtureHelper extends Module ...@@ -16,7 +16,7 @@ class FixtureHelper extends Module
/** /**
* Redeclare visibility because codeception includes all public methods that not starts from "_" * Redeclare visibility because codeception includes all public methods that not starts from "_"
* and not excluded by module settings, in guy class. * and not excluded by module settings, in actor class.
*/ */
use FixtureTrait { use FixtureTrait {
loadFixtures as protected; loadFixtures as protected;
...@@ -53,7 +53,7 @@ class FixtureHelper extends Module ...@@ -53,7 +53,7 @@ class FixtureHelper extends Module
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@common/tests/fixtures/data/init_login.php', 'dataFile' => '@codeception/common/fixtures/data/init_login.php',
], ],
]; ];
} }
......
namespace: codeception_common
actor: Tester actor: Tester
paths: paths:
tests: tests tests: .
log: tests/_log log: _output
data: tests/_data data: _data
helpers: tests/_helpers helpers: _support
settings: settings:
bootstrap: _bootstrap.php bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M memory_limit: 1024M
log: true log: true
colors: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
<?php <?php
namespace common\tests\fixtures; namespace codeception\common\fixtures;
use yii\test\ActiveFixture; use yii\test\ActiveFixture;
/**
* User fixture
*/
class UserFixture extends ActiveFixture class UserFixture extends ActiveFixture
{ {
public $modelClass = 'common\models\User'; public $modelClass = 'common\models\User';
......
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
# suite for unit (internal) tests. # suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy class_name: UnitTester
<?php <?php
namespace common\tests\unit; namespace codeception\common\unit;
/**
* @inheritdoc
*/
class DbTestCase extends \yii\codeception\DbTestCase class DbTestCase extends \yii\codeception\DbTestCase
{ {
public $appConfig = '@common/tests/unit/_config.php'; public $appConfig = '@codeception/config/common/unit.php';
} }
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace common\tests\unit; namespace common\tests\unit;
/**
* @inheritdoc
*/
class TestCase extends \yii\codeception\TestCase class TestCase extends \yii\codeception\TestCase
{ {
public $appConfig = '@common/tests/unit/_config.php'; public $appConfig = '@codeception/config/common/unit.php';
} }
<?php <?php
namespace common\tests\unit\models; namespace codeception\common\unit\models;
use Yii; use Yii;
use common\tests\unit\DbTestCase; use codeception\common\unit\DbTestCase;
use Codeception\Specify; use Codeception\Specify;
use common\models\LoginForm; use common\models\LoginForm;
use common\tests\fixtures\UserFixture; use codeception\common\fixtures\UserFixture;
/**
* Login form test
*/
class LoginFormTest extends DbTestCase class LoginFormTest extends DbTestCase
{ {
...@@ -75,12 +78,15 @@ class LoginFormTest extends DbTestCase ...@@ -75,12 +78,15 @@ class LoginFormTest extends DbTestCase
}); });
} }
/**
* @inheritdoc
*/
public function fixtures() public function fixtures()
{ {
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@common/tests/unit/fixtures/data/models/user.php' 'dataFile' => '@codeception/common/unit/fixtures/data/models/user.php'
], ],
]; ];
} }
......
<?php <?php
/** /**
* application configurations shared by all test types * Application configuration shared by all applications acceptance tests
*/ */
return [ return [
'components' => [ 'components' => [
'mailer' => [ 'db' => [
'useFileTransport' => true, 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
'urlManager' => [
'showScriptName' => true,
], ],
], ],
]; ];
\ No newline at end of file
<?php
defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(dirname(__DIR__)))));
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/backend/config/main.php'),
require(YII_ROOT_DIR . '/backend/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/acceptance.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php <?php
return [];
new yii\web\Application(require(__DIR__ . '/_config.php')); \ No newline at end of file
<?php
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_BACKEND_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_BACKEND_TEST_ENTRY_URL;
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/backend/config/main.php'),
require(YII_ROOT_DIR . '/backend/config/main-local.php'),
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/functional.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/backend/config/main.php'),
require(YII_ROOT_DIR . '/backend/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/unit.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php
/**
* Application config for common unit tests
*/
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/unit.php'),
[
'id' => 'app-common',
'basePath' => dirname(__DIR__),
]
);
<?php <?php
/** /**
* application configurations shared by all test types * Application configuration shared by all applications and test types
*/ */
return [ return [
'components' => [ 'components' => [
......
<?php
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/console/config/main.php'),
require(YII_ROOT_DIR . '/console/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/unit.php'),
[
]
);
<?php
defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(dirname(__DIR__)))));
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/frontend/config/main.php'),
require(YII_ROOT_DIR . '/frontend/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/acceptance.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php <?php
return [];
new yii\web\Application(require(__DIR__ . '/_config.php')); \ No newline at end of file
<?php
$_SERVER['SCRIPT_FILENAME'] = FRONTEND_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = FRONTEND_ENTRY_URL;
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/frontend/config/main.php'),
require(YII_ROOT_DIR . '/frontend/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/functional.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php
return yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/common/config/main.php'),
require(YII_ROOT_DIR . '/common/config/main-local.php'),
require(YII_ROOT_DIR . '/frontend/config/main.php'),
require(YII_ROOT_DIR . '/frontend/config/main-local.php'),
require(dirname(__DIR__) . '/config.php'),
require(dirname(__DIR__) . '/unit.php'),
require(__DIR__ . '/config.php'),
[
]
);
<?php <?php
/** /**
* application configurations shared by all test types * Application configuration shared by all applications functional tests
*/ */
return [ return [
'components' => [ 'components' => [
'mailer' => [ 'db' => [
'useFileTransport' => true, 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_acceptance',
],
'urlManager' => [
'showScriptName' => true,
], ],
], ],
]; ];
\ No newline at end of file
<?php <?php
/** /**
* application configurations shared by all test types * Application configuration shared by all applications unit tests
*/ */
return [ return [
'components' => [ 'components' => [
'mailer' => [ 'db' => [
'useFileTransport' => true, 'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_unit',
],
'urlManager' => [
'showScriptName' => true,
], ],
], ],
]; ];
\ No newline at end of file
# these files are auto generated by codeception build # these files are auto generated by codeception build
/unit/CodeGuy.php /unit/UnitTester.php
<?php <?php
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_ENV') or define('YII_ENV', 'test');
require_once(__DIR__ . '/../../vendor/autoload.php'); defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); require_once(YII_ROOT_DIR . '/vendor/autoload.php');
require_once(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/aliases.php'); require(YII_ROOT_DIR . '/common/config/aliases.php');
// set correct script paths // set correct script paths
$_SERVER['SERVER_NAME'] = 'localhost'; $_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@codeception', dirname(__DIR__));
\ No newline at end of file
namespace: codeception_console
actor: Tester
paths:
tests: .
log: _output
data: _data
helpers: _support
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
# suite for unit (internal) tests. # suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy class_name: UnitTester
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace console\tests\unit; namespace console\tests\unit;
/**
* @inheritdoc
*/
class DbTestCase extends \yii\codeception\DbTestCase class DbTestCase extends \yii\codeception\DbTestCase
{ {
public $appConfig = '@console/tests/unit/_config.php'; public $appConfig = '@codeception/config/console/config.php';
} }
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
namespace console\tests\unit; namespace console\tests\unit;
/**
* @inheritdoc
*/
class TestCase extends \yii\codeception\TestCase class TestCase extends \yii\codeception\TestCase
{ {
public $appConfig = '@console/tests/unit/_config.php'; public $appConfig = '@codeception/config/console/config.php';
} }
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
defined('FRONTEND_ENTRY_URL') or define('FRONTEND_ENTRY_URL', \Codeception\Configuration::config()['config']['test_entry_url']);
defined('FRONTEND_ENTRY_FILE') or define('FRONTEND_ENTRY_FILE', YII_ROOT_DIR . '/frontend/web/index-test.php');
require_once(YII_ROOT_DIR . '/vendor/autoload.php');
require_once(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
require(YII_ROOT_DIR . '/common/config/aliases.php');
// set correct script paths
// the entry script file path for functional and acceptance tests
$_SERVER['SCRIPT_FILENAME'] = FRONTEND_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = FRONTEND_ENTRY_URL;
$_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@codeception', dirname(__DIR__));
\ No newline at end of file
<?php <?php
namespace tests\_pages; namespace codeception\frontend\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents about page
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor
*/
class AboutPage extends BasePage class AboutPage extends BasePage
{ {
public $route = 'site/about'; public $route = 'site/about';
......
<?php <?php
namespace tests\_pages; namespace codeception\frontend\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents contact page
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor
*/
class ContactPage extends BasePage class ContactPage extends BasePage
{ {
public $route = 'site/contact'; public $route = 'site/contact';
...@@ -15,8 +19,8 @@ class ContactPage extends BasePage ...@@ -15,8 +19,8 @@ class ContactPage extends BasePage
{ {
foreach ($contactData as $field => $value) { foreach ($contactData as $field => $value) {
$inputType = $field === 'body' ? 'textarea' : 'input'; $inputType = $field === 'body' ? 'textarea' : 'input';
$this->guy->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value); $this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
} }
$this->guy->click('contact-button'); $this->actor->click('contact-button');
} }
} }
<?php <?php
namespace frontend\tests\_pages; namespace codeception\frontend\_pages;
use \yii\codeception\BasePage; use \yii\codeception\BasePage;
/**
* Represents signup page
* @property \codeception_frontend\AcceptanceTester|\codeception_frontend\FunctionalTester $actor
*/
class SignupPage extends BasePage class SignupPage extends BasePage
{ {
...@@ -16,8 +20,8 @@ class SignupPage extends BasePage ...@@ -16,8 +20,8 @@ class SignupPage extends BasePage
{ {
foreach ($signupData as $field => $value) { foreach ($signupData as $field => $value) {
$inputType = $field === 'body' ? 'textarea' : 'input'; $inputType = $field === 'body' ? 'textarea' : 'input';
$this->guy->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value); $this->actor->fillField($inputType . '[name="SignupForm[' . $field . ']"]', $value);
} }
$this->guy->click('signup-button'); $this->actor->click('signup-button');
} }
} }
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: WebGuy class_name: AcceptanceTester
modules: modules:
enabled: enabled:
- PhpBrowser - PhpBrowser
- common\tests\_helpers\FixtureHelper - codeception\common\_support\FixtureHelper
# you can use WebDriver instead of PhpBrowser to test javascript and ajax. # you can use WebDriver instead of PhpBrowser to test javascript and ajax.
# This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium # This will require you to install selenium. See http://codeception.com/docs/04-AcceptanceTests#Selenium
# "restart" option is used by the WebDriver to start each time per test-file new session and cookies, # "restart" option is used by the WebDriver to start each time per test-file new session and cookies,
......
<?php <?php
use codeception_frontend\AcceptanceTester;
use codeception\frontend\_pages\AboutPage;
use frontend\tests\_pages\AboutPage; $I = new AcceptanceTester($scenario);
use frontend\WebGuy;
$I = new WebGuy($scenario);
$I->wantTo('ensure that about works'); $I->wantTo('ensure that about works');
AboutPage::openBy($I); AboutPage::openBy($I);
$I->see('About', 'h1'); $I->see('About', 'h1');
<?php <?php
use codeception_frontend\AcceptanceTester;
use codeception\frontend\_pages\ContactPage;
use frontend\tests\_pages\ContactPage; $I = new AcceptanceTester($scenario);
use frontend\WebGuy;
$I = new WebGuy($scenario);
$I->wantTo('ensure that contact works'); $I->wantTo('ensure that contact works');
$contactPage = ContactPage::openBy($I); $contactPage = ContactPage::openBy($I);
......
<?php <?php
use codeception_frontend\AcceptanceTester;
use frontend\WebGuy; $I = new AcceptanceTester($scenario);
$I = new WebGuy($scenario);
$I->wantTo('ensure that home page works'); $I->wantTo('ensure that home page works');
$I->amOnPage(Yii::$app->homeUrl); $I->amOnPage(Yii::$app->homeUrl);
$I->see('My Company'); $I->see('My Company');
......
<?php <?php
use codeception_frontend\AcceptanceTester;
use codeception\common\_pages\LoginPage;
use common\tests\_pages\LoginPage; $I = new AcceptanceTester($scenario);
use frontend\WebGuy;
$I = new WebGuy($scenario);
$I->wantTo('ensure login page works'); $I->wantTo('ensure login page works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php <?php
namespace frontend\tests\acceptance; namespace codeception\frontend\acceptance;
use frontend\tests\_pages\SignupPage; use codeception\frontend\_pages\SignupPage;
use common\models\User; use common\models\User;
class SignupCest class SignupCest
...@@ -10,7 +10,7 @@ class SignupCest ...@@ -10,7 +10,7 @@ class SignupCest
/** /**
* This method is called before each cest class test method * This method is called before each cest class test method
* @param \Codeception\Event\Test $event * @param \Codeception\Event\TestEvent $event
*/ */
public function _before($event) public function _before($event)
{ {
...@@ -18,7 +18,7 @@ class SignupCest ...@@ -18,7 +18,7 @@ class SignupCest
/** /**
* This method is called after each cest class test method, even if test failed. * This method is called after each cest class test method, even if test failed.
* @param \Codeception\Event\Test $event * @param \Codeception\Event\TestEvent $event
*/ */
public function _after($event) public function _after($event)
{ {
...@@ -30,14 +30,14 @@ class SignupCest ...@@ -30,14 +30,14 @@ class SignupCest
/** /**
* This method is called when test fails. * This method is called when test fails.
* @param \Codeception\Event\Fail $event * @param \Codeception\Event\FailEvent $event
*/ */
public function _fail($event) public function _fail($event)
{ {
} }
/** /**
* @param \WebGuy $I * @param \codeception_frontend\AcceptanceTester $I
* @param \Codeception\Scenario $scenario * @param \Codeception\Scenario $scenario
*/ */
public function testUserSignup($I, $scenario) public function testUserSignup($I, $scenario)
......
<?php
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/frontend/acceptance.php'));
namespace: frontend namespace: codeception_frontend
actor: Tester actor: Tester
paths: paths:
tests: tests tests: .
log: tests/_log log: _output
data: tests/_data data: _data
helpers: tests/_helpers helpers: _support
settings: settings:
bootstrap: _bootstrap.php bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite suite_class: \PHPUnit_Framework_TestSuite
colors: true colors: true
memory_limit: 1024M memory_limit: 1024M
log: true log: true
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
config: config:
# the entry script URL (without host info) for functional and acceptance tests # the entry script URL (without host info) for functional and acceptance tests
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL # 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
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
#basic/web/index.php #basic/web/index.php
class_name: TestGuy class_name: FunctionalTester
modules: modules:
enabled: enabled:
- Filesystem - Filesystem
- Yii2 - Yii2
- common\tests\_helpers\FixtureHelper - codeception\common\_support\FixtureHelper
config: config:
Yii2: Yii2:
configFile: 'tests/functional/_config.php' configFile: '../config/frontend/functional.php'
<?php <?php
use codeception_frontend\FunctionalTester;
use codeception\frontend\_pages\AboutPage;
use frontend\tests\_pages\AboutPage; $I = new FunctionalTester($scenario);
use frontend\TestGuy;
$I = new TestGuy($scenario);
$I->wantTo('ensure that about works'); $I->wantTo('ensure that about works');
AboutPage::openBy($I); AboutPage::openBy($I);
$I->see('About', 'h1'); $I->see('About', 'h1');
<?php <?php
use codeception_frontend\FunctionalTester;
use codeception\frontend\_pages\ContactPage;
use frontend\tests\_pages\ContactPage; $I = new FunctionalTester($scenario);
use frontend\TestGuy;
$I = new TestGuy($scenario);
$I->wantTo('ensure that contact works'); $I->wantTo('ensure that contact works');
$contactPage = ContactPage::openBy($I); $contactPage = ContactPage::openBy($I);
......
<?php <?php
use codeception_frontend\FunctionalTester;
use frontend\TestGuy; $I = new FunctionalTester($scenario);
$I = new TestGuy($scenario);
$I->wantTo('ensure that home page works'); $I->wantTo('ensure that home page works');
$I->amOnPage(Yii::$app->homeUrl); $I->amOnPage(Yii::$app->homeUrl);
$I->see('My Company'); $I->see('My Company');
......
<?php <?php
use codeception_frontend\FunctionalTester;
use codeception\common\_pages\LoginPage;
use common\tests\_pages\LoginPage; $I = new FunctionalTester($scenario);
use frontend\TestGuy;
$I = new TestGuy($scenario);
$I->wantTo('ensure login page works'); $I->wantTo('ensure login page works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php <?php
namespace frontend\tests\functional; namespace codeception\frontend\functional;
use frontend\tests\_pages\SignupPage; use codeception\frontend\_pages\SignupPage;
use common\models\User; use common\models\User;
class SignupCest class SignupCest
...@@ -10,7 +10,7 @@ class SignupCest ...@@ -10,7 +10,7 @@ class SignupCest
/** /**
* This method is called before each cest class test method * This method is called before each cest class test method
* @param \Codeception\Event\Test $event * @param \Codeception\Event\TestEvent $event
*/ */
public function _before($event) public function _before($event)
{ {
...@@ -18,7 +18,7 @@ class SignupCest ...@@ -18,7 +18,7 @@ class SignupCest
/** /**
* This method is called after each cest class test method, even if test failed. * This method is called after each cest class test method, even if test failed.
* @param \Codeception\Event\Test $event * @param \Codeception\Event\TestEvent $event
*/ */
public function _after($event) public function _after($event)
{ {
...@@ -30,7 +30,7 @@ class SignupCest ...@@ -30,7 +30,7 @@ class SignupCest
/** /**
* This method is called when test fails. * This method is called when test fails.
* @param \Codeception\Event\Fail $event * @param \Codeception\Event\FailEvent $event
*/ */
public function _fail($event) public function _fail($event)
{ {
...@@ -39,7 +39,7 @@ class SignupCest ...@@ -39,7 +39,7 @@ class SignupCest
/** /**
* *
* @param \TestGuy $I * @param \codeception_frontend\FunctionalTester $I
* @param \Codeception\Scenario $scenario * @param \Codeception\Scenario $scenario
*/ */
public function testUserSignup($I, $scenario) public function testUserSignup($I, $scenario)
......
<?php
new yii\web\Application(require(dirname(dirname(__DIR__)) . '/config/frontend/functional.php'));
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
# suite for unit (internal) tests. # suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy class_name: UnitTester
<?php <?php
namespace frontend\tests\unit; namespace codeception\frontend\unit;
/**
* @inheritdoc
*/
class DbTestCase extends \yii\codeception\DbTestCase class DbTestCase extends \yii\codeception\DbTestCase
{ {
public $appConfig = '@frontend/tests/unit/_config.php'; public $appConfig = '@codeception/config/frontend/unit.php';
} }
<?php <?php
namespace frontend\tests\unit; namespace codeception\frontend\unit;
/**
* @inheritdoc
*/
class TestCase extends \yii\codeception\TestCase class TestCase extends \yii\codeception\TestCase
{ {
public $appConfig = '@frontend/tests/unit/_config.php'; public $appConfig = '@codeception/config/frontend/unit.php';
} }
<?php <?php
namespace frontend\tests\unit\models; namespace codeception\frontend\unit\models;
use Yii; use Yii;
use frontend\tests\unit\TestCase; use codeception\frontend\unit\TestCase;
use frontend\models\ContactForm; use frontend\models\ContactForm;
class ContactFormTest extends TestCase class ContactFormTest extends TestCase
......
<?php <?php
namespace frontend\tests\unit\models; namespace codeception\frontend\tests\models;
use Yii; use Yii;
use frontend\tests\unit\DbTestCase; use codeception\frontend\unit\DbTestCase;
use frontend\models\PasswordResetRequestForm; use frontend\models\PasswordResetRequestForm;
use common\tests\fixtures\UserFixture; use codeception\common\fixtures\UserFixture;
use common\models\User; use common\models\User;
use Codeception\Specify; use Codeception\Specify;
...@@ -75,7 +75,7 @@ class PasswordResetRequestFormTest extends DbTestCase ...@@ -75,7 +75,7 @@ class PasswordResetRequestFormTest extends DbTestCase
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php' 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php'
], ],
]; ];
} }
......
<?php <?php
namespace frontend\tests\unit\models; namespace codeception\frontend\unit\models;
use frontend\tests\unit\DbTestCase; use codeception\frontend\unit\DbTestCase;
use common\tests\fixtures\UserFixture; use codeception\common\fixtures\UserFixture;
use frontend\models\ResetPasswordForm; use frontend\models\ResetPasswordForm;
class ResetPasswordFormTest extends DbTestCase class ResetPasswordFormTest extends DbTestCase
{ {
/** /**
* @expectedException yii\base\InvalidParamException * @expectedException \yii\base\InvalidParamException
*/ */
public function testResetWrongToken() public function testResetWrongToken()
{ {
...@@ -18,7 +18,7 @@ class ResetPasswordFormTest extends DbTestCase ...@@ -18,7 +18,7 @@ class ResetPasswordFormTest extends DbTestCase
} }
/** /**
* @expectedException yii\base\InvalidParamException * @expectedException \yii\base\InvalidParamException
*/ */
public function testResetEmptyToken() public function testResetEmptyToken()
{ {
...@@ -36,7 +36,7 @@ class ResetPasswordFormTest extends DbTestCase ...@@ -36,7 +36,7 @@ class ResetPasswordFormTest extends DbTestCase
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php' 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php'
], ],
]; ];
} }
......
<?php <?php
namespace frontend\tests\unit\models; namespace codeception\frontend\unit\models;
use frontend\tests\unit\DbTestCase; use codeception\frontend\unit\DbTestCase;
use common\tests\fixtures\UserFixture; use codeception\common\fixtures\UserFixture;
use Codeception\Specify; use Codeception\Specify;
use frontend\models\SignupForm; use frontend\models\SignupForm;
...@@ -45,7 +45,7 @@ class SignupFormTest extends DbTestCase ...@@ -45,7 +45,7 @@ class SignupFormTest extends DbTestCase
return [ return [
'user' => [ 'user' => [
'class' => UserFixture::className(), 'class' => UserFixture::className(),
'dataFile' => '@frontend/tests/unit/fixtures/data/models/user.php', 'dataFile' => '@codeception/frontend/unit/fixtures/data/models/user.php',
], ],
]; ];
} }
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
......
...@@ -24,11 +24,6 @@ ...@@ -24,11 +24,6 @@
"yiisoft/yii2-debug": "*", "yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*" "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": { "scripts": {
"post-create-project-cmd": [ "post-create-project-cmd": [
"yii\\composer\\Installer::setPermission", "yii\\composer\\Installer::setPermission",
......
...@@ -9,7 +9,7 @@ $config = [ ...@@ -9,7 +9,7 @@ $config = [
'components' => [ 'components' => [
'request' => [ 'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '', 'cookieValidationKey' => 'thisIsAKey',
], ],
'cache' => [ 'cache' => [
'class' => 'yii\caching\FileCache', 'class' => 'yii\caching\FileCache',
...@@ -38,6 +38,10 @@ $config = [ ...@@ -38,6 +38,10 @@ $config = [
], ],
], ],
'db' => require(__DIR__ . '/db.php'), 'db' => require(__DIR__ . '/db.php'),
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
], ],
'params' => $params, 'params' => $params,
]; ];
......
# these files are auto generated by codeception build
/unit/CodeGuy.php
/functional/TestGuy.php
/acceptance/WebGuy.php
This folder contains various tests for the basic application. This directory contains various tests for the basic application.
These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/).
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: 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:
```
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 <directory>
```
``` Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command
php composer.phar require --dev "codeception/codeception: 2.0.*" "codeception/specify: *" "codeception/verify: *" line globally.
```
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:
``` 2. Build the test suites:
vendor/bin/codecept build
``` ```
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
```
Now you can run the tests with the following commands: 4. Now you can run the tests with the following commands:
``` ```
# run all available tests # run all available tests
vendor/bin/codecept run codecept run
# run acceptance tests # run acceptance tests
vendor/bin/codecept run acceptance codecept run acceptance
# run functional tests # run functional tests
vendor/bin/codecept run functional codecept run functional
# run unit tests # run unit tests
vendor/bin/codecept run unit codecept run unit
``` ```
Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for
......
<?php
// 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');
// 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('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/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__);
/* Replace this file with actual dump of your database */
\ No newline at end of file
<?php
new yii\web\Application(require(__DIR__ . '/_config.php'));
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance',
],
],
]
);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 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
namespace: backend
actor: Tester actor: Tester
paths: paths:
tests: tests tests: codeception
log: tests/_log log: codeception/_output
data: tests/_data data: codeception/_data
helpers: tests/_helpers helpers: codeception/_support
settings: settings:
bootstrap: _bootstrap.php bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M memory_limit: 1024M
log: true log: true
modules: colors: true
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
config: config:
# the entry script URL (without host info) for functional and acceptance tests # the entry script URL (without host info) for functional and acceptance tests
# PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL # PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
test_entry_url: /advanced/backend/web/index-test.php test_entry_url: /index-test.php
\ No newline at end of file
# these files are auto generated by codeception build
/unit/UnitTester.php
/functional/FunctionalTester.php
/acceptance/AcceptanceTester.php
<?php <?php
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_ENV') or define('YII_ENV', 'test');
require_once(__DIR__ . '/../../vendor/autoload.php'); defined('YII_TEST_ENTRY_URL') or define('YII_TEST_ENTRY_URL', \Codeception\Configuration::config()['config']['test_entry_url']);
defined('YII_TEST_ENTRY_FILE') or define('YII_TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index-test.php');
require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../../common/config/aliases.php'); $_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
// set correct script paths
$_SERVER['SERVER_NAME'] = 'localhost'; $_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@codeception', __DIR__);
<?php <?php
namespace frontend\tests\_pages; namespace codeception\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents about page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class AboutPage extends BasePage class AboutPage extends BasePage
{ {
public $route = 'site/about'; public $route = 'site/about';
......
<?php <?php
namespace frontend\tests\_pages; namespace codeception\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents contact page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class ContactPage extends BasePage class ContactPage extends BasePage
{ {
public $route = 'site/contact'; public $route = 'site/contact';
...@@ -15,8 +19,8 @@ class ContactPage extends BasePage ...@@ -15,8 +19,8 @@ class ContactPage extends BasePage
{ {
foreach ($contactData as $field => $value) { foreach ($contactData as $field => $value) {
$inputType = $field === 'body' ? 'textarea' : 'input'; $inputType = $field === 'body' ? 'textarea' : 'input';
$this->guy->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value); $this->actor->fillField($inputType . '[name="ContactForm[' . $field . ']"]', $value);
} }
$this->guy->click('contact-button'); $this->actor->click('contact-button');
} }
} }
<?php <?php
namespace common\tests\_pages; namespace codeception\_pages;
use yii\codeception\BasePage; use yii\codeception\BasePage;
/**
* Represents login page
* @property \AcceptanceTester|\FunctionalTester $actor
*/
class LoginPage extends BasePage class LoginPage extends BasePage
{ {
public $route = 'site/login'; public $route = 'site/login';
...@@ -14,8 +18,8 @@ class LoginPage extends BasePage ...@@ -14,8 +18,8 @@ class LoginPage extends BasePage
*/ */
public function login($username, $password) public function login($username, $password)
{ {
$this->guy->fillField('input[name="LoginForm[username]"]', $username); $this->actor->fillField('input[name="LoginForm[username]"]', $username);
$this->guy->fillField('input[name="LoginForm[password]"]', $password); $this->actor->fillField('input[name="LoginForm[password]"]', $password);
$this->guy->click('login-button'); $this->actor->click('login-button');
} }
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: WebGuy class_name: AcceptanceTester
modules: modules:
enabled: enabled:
- PhpBrowser - PhpBrowser
......
<?php <?php
use tests\_pages\AboutPage; use codeception\_pages\AboutPage;
$I = new WebGuy($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('ensure that about works'); $I->wantTo('ensure that about works');
AboutPage::openBy($I); AboutPage::openBy($I);
$I->see('About', 'h1'); $I->see('About', 'h1');
<?php <?php
use tests\_pages\ContactPage; use codeception\_pages\ContactPage;
$I = new WebGuy($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('ensure that contact works'); $I->wantTo('ensure that contact works');
$contactPage = ContactPage::openBy($I); $contactPage = ContactPage::openBy($I);
......
<?php <?php
$I = new WebGuy($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('ensure that home page works'); $I->wantTo('ensure that home page works');
$I->amOnPage(Yii::$app->homeUrl); $I->amOnPage(Yii::$app->homeUrl);
$I->see('My Company'); $I->see('My Company');
......
<?php <?php
use tests\_pages\LoginPage; use codeception\_pages\LoginPage;
$I = new WebGuy($scenario); $I = new AcceptanceTester($scenario);
$I->wantTo('ensure that login works'); $I->wantTo('ensure that login works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php <?php
new yii\web\Application(require(dirname(__DIR__) . '/config/acceptance.php'));
new yii\web\Application(require(__DIR__ . '/_config.php'));
<?php <?php
defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test'); defined('YII_ENV') or define('YII_ENV', 'test');
// fcgi doesn't have STDIN and STDOUT defined by default // fcgi doesn't have STDIN and STDOUT defined by default
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r')); defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w')); defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/../vendor/autoload.php'); defined('YII_ROOT_DIR') or define('YII_ROOT_DIR', dirname(dirname(dirname(__DIR__))));
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(YII_ROOT_DIR . '/vendor/autoload.php');
require(YII_ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');
...@@ -8,9 +8,19 @@ ...@@ -8,9 +8,19 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
require_once __DIR__ . '/../_console_bootstrap.php'; require_once __DIR__ . '/_bootstrap.php';
$config = require(__DIR__ . '/_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../config/config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance',
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_acceptance" %*
@endlocal @endlocal
...@@ -8,9 +8,19 @@ ...@@ -8,9 +8,19 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
require_once __DIR__ . '/../_console_bootstrap.php'; require_once __DIR__ . '/_bootstrap.php';
$config = require(__DIR__ . '/_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../config/config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional',
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_functional" %*
@endlocal @endlocal
...@@ -8,9 +8,19 @@ ...@@ -8,9 +8,19 @@
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
require_once __DIR__ . '/../_console_bootstrap.php'; require_once __DIR__ . '/_bootstrap.php';
$config = require(__DIR__ . '/_console.php'); $config = yii\helpers\ArrayHelper::merge(
require(YII_ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../config/config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit',
],
],
]
);
$application = new yii\console\Application($config); $application = new yii\console\Application($config);
$exitCode = $application->run(); $exitCode = $application->run();
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0 ...@@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %* "%PHP_COMMAND%" "%YII_PATH%yii_unit" %*
@endlocal @endlocal
<?php <?php
/**
* Application configuration for acceptance tests
*/
return yii\helpers\ArrayHelper::merge( return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/web.php'), require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'), require(__DIR__ . '/config.php'),
[ [
'components' => [ 'components' => [
'db' => [ 'db' => [
......
<?php <?php
/** /**
* application configurations shared by all test types * Application configuration shared by all test types
*/ */
return [ return [
'components' => [ 'components' => [
......
<?php <?php
$_SERVER['SCRIPT_FILENAME'] = YII_TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = YII_TEST_ENTRY_URL;
/**
* Application configuration for functional tests
*/
return yii\helpers\ArrayHelper::merge( return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/console.php'), require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'), require(__DIR__ . '/config.php'),
[ [
'components' => [ 'components' => [
'db' => [ 'db' => [
......
<?php <?php
/**
* Application configuration for unit tests
*/
return yii\helpers\ArrayHelper::merge( return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/web.php'), require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'), require(__DIR__ . '/config.php'),
[ [
'components' => [ 'components' => [
'db' => [ 'db' => [
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
#basic/web/index.php #basic/web/index.php
class_name: TestGuy class_name: FunctionalTester
modules: modules:
enabled: enabled:
- Filesystem - Filesystem
- Yii2 - Yii2
config: config:
Yii2: Yii2:
configFile: 'tests/functional/_config.php' configFile: 'codeception/config/functional.php'
<?php <?php
use tests\_pages\AboutPage; use codeception\_pages\AboutPage;
$I = new TestGuy($scenario); $I = new FunctionalTester($scenario);
$I->wantTo('ensure that about works'); $I->wantTo('ensure that about works');
AboutPage::openBy($I); AboutPage::openBy($I);
$I->see('About', 'h1'); $I->see('About', 'h1');
<?php <?php
use tests\_pages\ContactPage; use codeception\_pages\ContactPage;
$I = new TestGuy($scenario); $I = new FunctionalTester($scenario);
$I->wantTo('ensure that contact works'); $I->wantTo('ensure that contact works');
$contactPage = ContactPage::openBy($I); $contactPage = ContactPage::openBy($I);
......
<?php <?php
$I = new TestGuy($scenario); $I = new FunctionalTester($scenario);
$I->wantTo('ensure that home page works'); $I->wantTo('ensure that home page works');
$I->amOnPage(Yii::$app->homeUrl); $I->amOnPage(Yii::$app->homeUrl);
$I->see('My Company'); $I->see('My Company');
......
<?php <?php
use tests\_pages\LoginPage; use codeception\_pages\LoginPage;
$I = new TestGuy($scenario); $I = new FunctionalTester($scenario);
$I->wantTo('ensure that login works'); $I->wantTo('ensure that login works');
$loginPage = LoginPage::openBy($I); $loginPage = LoginPage::openBy($I);
......
<?php <?php
new yii\web\Application(require(dirname(__DIR__) . '/config/functional.php'));
new yii\web\Application(require(__DIR__ . '/_config.php'));
...@@ -3,4 +3,4 @@ ...@@ -3,4 +3,4 @@
# suite for unit (internal) tests. # suite for unit (internal) tests.
# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. # RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.
class_name: CodeGuy class_name: UnitTester
<?php <?php
namespace tests\unit\models; namespace codeception\unit\models;
use Yii; use Yii;
use yii\codeception\TestCase; use yii\codeception\TestCase;
......
<?php <?php
namespace tests\unit\models; namespace codeception\unit\models;
use Yii; use Yii;
use yii\codeception\TestCase; use yii\codeception\TestCase;
......
<?php <?php
namespace tests\unit\models; namespace codeception\unit\models;
use yii\codeception\TestCase; use yii\codeception\TestCase;
......
<?php
new yii\web\Application(require(__DIR__ . '/_config.php'));
<?php
// set correct script paths
$_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.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional',
],
],
]
);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 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
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit',
],
],
]
);
@echo off
rem -------------------------------------------------------------
rem Yii command line bootstrap script for Windows.
rem
rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 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
...@@ -11,6 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test'); ...@@ -11,6 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../tests/acceptance/_config.php'); $config = require(__DIR__ . '/../tests/codeception/config/acceptance.php');
(new yii\web\Application($config))->run(); (new yii\web\Application($config))->run();
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
......
...@@ -4,23 +4,8 @@ Acceptance Tests ...@@ -4,23 +4,8 @@ Acceptance Tests
> Note: This section is under development. > Note: This section is under development.
- http://codeception.com/docs/04-AcceptanceTests - 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 Please refer to instructions provided in `apps/advanced/tests/README.md` and `apps/basic/tests/README.md`.
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');
```
Functional Tests Functional Tests
---------------- ================
> Note: This section is under development. > Note: This section is under development.
- http://codeception.com/docs/05-FunctionalTests - 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
...@@ -34,4 +34,11 @@ composer global require "codeception/specify=*" ...@@ -34,4 +34,11 @@ composer global require "codeception/specify=*"
composer global require "codeception/verify=*" 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 <directory>
```
Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command
line globally.
...@@ -3,11 +3,6 @@ Unit Tests ...@@ -3,11 +3,6 @@ Unit Tests
> Note: This section is under development. > 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 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. 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. That is, given different input parameters, the test verifies the method returns expected results.
...@@ -17,3 +12,8 @@ Unit testing in Yii is built on top of PHPUnit and, optionally, Codeception so i ...@@ -17,3 +12,8 @@ Unit testing in Yii is built on top of PHPUnit and, optionally, Codeception so i
- [PHPUnit docs starting from chapter 2](http://phpunit.de/manual/current/en/writing-tests-for-phpunit.html). - [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). - [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`.
...@@ -29,57 +29,6 @@ You can now execute unit tests by running `phpunit`. ...@@ -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 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`. `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 Extensions
---------- ----------
...@@ -89,3 +38,7 @@ Just add them to the `composer.json` as you would normally do e.g. add `"yiisoft ...@@ -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 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. 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.
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
......
...@@ -29,19 +29,19 @@ abstract class BasePage extends Component ...@@ -29,19 +29,19 @@ abstract class BasePage extends Component
public $route; public $route;
/** /**
* @var \Codeception\AbstractGuy the testing guy object * @var \Codeception\Actor the testing guy object
*/ */
protected $guy; protected $actor;
/** /**
* Constructor. * Constructor.
* *
* @param \Codeception\AbstractGuy $I the testing guy object * @param \Codeception\Actor $I the testing guy object
*/ */
public function __construct($I) public function __construct($I)
{ {
$this->guy = $I; $this->actor = $I;
} }
/** /**
...@@ -67,7 +67,7 @@ abstract class BasePage extends Component ...@@ -67,7 +67,7 @@ abstract class BasePage extends Component
/** /**
* Creates a page instance and sets the test guy to use [[url]]. * Creates a page instance and sets the test guy to use [[url]].
* @param \Codeception\AbstractGuy $I the test guy instance * @param \Codeception\Actor $I the test guy instance
* @param array $params the GET parameters to be used to generate [[url]] * @param array $params the GET parameters to be used to generate [[url]]
* @return static the page instance * @return static the page instance
*/ */
......
...@@ -10,6 +10,8 @@ namespace yii\codeception; ...@@ -10,6 +10,8 @@ namespace yii\codeception;
use yii\test\InitDbFixture; use yii\test\InitDbFixture;
/** /**
* Base class for database test cases
*
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
......
...@@ -52,11 +52,11 @@ If you want to use codeception modules and helpers in your unit tests, you can d ...@@ -52,11 +52,11 @@ If you want to use codeception modules and helpers in your unit tests, you can d
$this->getModule('CodeHelper'); #or some other module $this->getModule('CodeHelper'); #or some other module
``` ```
You also can use all guy methods by accessing guy instance like: You also can use all actor methods by accessing actor instance like:
```php ```php
<?php <?php
$this->codeGuy->someMethodFromModule(); $this->unitTester->someMethodFromModule();
``` ```
Codeception events Codeception events
------------------ ------------------
......
...@@ -31,7 +31,7 @@ class TestCase extends Test ...@@ -31,7 +31,7 @@ class TestCase extends Test
* The application configuration array may contain an optional `class` element which specifies the class * 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. * 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/config/unit.php';
/** /**
......
...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows. ...@@ -5,7 +5,7 @@ rem Yii command line bootstrap script for Windows.
rem rem
rem @author Qiang Xue <qiang.xue@gmail.com> rem @author Qiang Xue <qiang.xue@gmail.com>
rem @link http://www.yiiframework.com/ rem @link http://www.yiiframework.com/
rem @copyright Copyright &copy; 2012 Yii Software LLC rem @copyright Copyright (c) 2008 Yii Software LLC
rem @license http://www.yiiframework.com/license/ rem @license http://www.yiiframework.com/license/
rem ------------------------------------------------------------- rem -------------------------------------------------------------
......
...@@ -7,8 +7,9 @@ else ...@@ -7,8 +7,9 @@ else
mysql -e 'CREATE DATABASE yii2_advanced_acceptance;'; mysql -e 'CREATE DATABASE yii2_advanced_acceptance;';
mysql -e 'CREATE DATABASE yii2_advanced_functional;'; mysql -e 'CREATE DATABASE yii2_advanced_functional;';
mysql -e 'CREATE DATABASE yii2_advanced_unit;'; mysql -e 'CREATE DATABASE yii2_advanced_unit;';
cd apps/advanced/frontend/tests/acceptance && php yii migrate --interactive=0 cd apps/advanced/tests/codeception/bin
cd ../functional && php yii migrate --interactive=0 php yii_acceptance migrate --interactive=0
cd ../unit && php yii migrate --interactive=0 && cd ../../../../.. php yii_functional migrate --interactive=0
php yii_unit migrate --interactive=0
cd ../../../../..
fi fi
...@@ -7,24 +7,20 @@ else ...@@ -7,24 +7,20 @@ else
# basic application: # basic application:
composer install --dev --prefer-dist -d apps/basic composer install --dev --prefer-dist -d apps/basic
cd apps/basic && composer require --dev codeception/codeception:2.0.* codeception/specify:* codeception/verify:* cd apps/basic && sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" config/web.php
sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" config/web.php cd tests && codecept build && cd ../../..
php vendor/bin/codecept build && cd ../..
# advanced application: # advanced application:
composer install --dev --prefer-dist -d apps/advanced composer install --dev --prefer-dist -d apps/advanced
cd apps/advanced && composer require --dev codeception/codeception:2.0.* codeception/specify:* codeception/verify:* cd apps/advanced && ./init --env=Development
./init --env=Development
sed -i s/root/travis/ common/config/main-local.php 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'/" frontend/config/main.php
sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" backend/config/main.php sed -i "s/'cookieValidationKey' => ''/'cookieValidationKey' => 'testkey'/" backend/config/main.php
cd backend && php ../vendor/bin/codecept build cd tests/codeception/backend && codecept build
cd ../common && php ../vendor/bin/codecept build cd ../common && codecept build
cd ../frontend && php ../vendor/bin/codecept build && cd ../../.. cd ../console && codecept build
cd ../frontend && codecept build
# boot server cd ../../../
cd apps && php -S localhost:8080 > /dev/null 2>&1 &
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment