Codeception test adjustments for basic and advanced applications

- Moved everything test-related into `tests` directory. Codeception tests are in `codeception`.
- Removed database module since we're using fixtures and migrations.
- Moved console entry points and bootstrap into `tests/codeception/bin`.
- Adjusted travis build scripts.
- Adjusted documentation to be consistent and reflect changes made.
This commit is contained in:
Alexander Makarov 2014-08-15 03:30:47 +04:00
parent f77cd8b411
commit c55a791237
48 changed files with 150 additions and 144 deletions

View File

@ -24,11 +24,6 @@
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*"
},
"suggest": {
"codeception/codeception": "Codeception, 2.0.* is currently works well with Yii.",
"codeception/specify": "BDD style code blocks for PHPUnit and Codeception",
"codeception/verify": "BDD Assertions for PHPUnit and Codeception"
},
"scripts": {
"post-create-project-cmd": [
"yii\\composer\\Installer::setPermission",

View File

@ -1,32 +1,50 @@
This folder contains various tests for the basic application.
These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/).
This directory contains various tests for the basic application.
Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
After creating the basic application, follow these steps to prepare for the tests:
1. Install additional composer packages:
1. Install Codeception if it's not yet installed:
```
php composer.phar require --dev "codeception/codeception: 2.0.*" "codeception/specify: *" "codeception/verify: *"
```
2. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so
that it points to the correct entry script URL.
3. Go to the application base directory and build the test suites:
```
composer global require "codeception/codeception=2.0.*"
composer global require "codeception/specify=*"
composer global require "codeception/verify=*"
```
```
vendor/bin/codecept build
```
If you've never used Composer for global packages run `composer global status`. It should output:
Now you can run the tests with the following commands:
```
Changed current directory to <directory>
```
Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command
line globally.
2. Build the test suites:
```
codecept build
```
3. In order to be able to run acceptance tests you need to start a webserver. The simplest way is to use PHP built in
webserver. In the `web` directory execute the following:
```
php -S localhost:8080
```
4. Now you can run the tests with the following commands:
```
# run all available tests
vendor/bin/codecept run
codecept run
# run acceptance tests
vendor/bin/codecept run acceptance
codecept run acceptance
# run functional tests
vendor/bin/codecept run functional
codecept run functional
# run unit tests
vendor/bin/codecept run unit
codecept run unit
```
Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for

View File

@ -1,13 +0,0 @@
<?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',
],
],
]
);

View File

@ -1,17 +0,0 @@
#!/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/
*/
require_once __DIR__ . '/../_console_bootstrap.php';
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -1,9 +1,9 @@
actor: Tester
paths:
tests: tests
log: tests/_log
data: tests/_data
helpers: tests/_helpers
tests: codeception
log: codeception/_log
data: codeception/_data
helpers: codeception/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
@ -16,4 +16,4 @@ modules:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
dump: codeception/_data/dump.sql

View File

@ -2,22 +2,22 @@
// the entry script URL (without host info) for functional and acceptance tests
// PLEASE ADJUST IT TO THE ACTUAL ENTRY SCRIPT URL
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/basic/web/index-test.php');
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/index-test.php');
// the entry script file path for functional and acceptance tests
defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(__DIR__) . '/web/index-test.php');
defined('TEST_ENTRY_FILE') or define('TEST_ENTRY_FILE', dirname(dirname(__DIR__)) . '/web/index-test.php');
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../../vendor/autoload.php');
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require_once(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
// set correct script paths
$_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL;
$_SERVER['SERVER_NAME'] = 'localhost';
Yii::setAlias('@tests', __DIR__);
Yii::setAlias('@codeception', __DIR__);

View File

@ -1,6 +1,6 @@
<?php
namespace tests\_pages;
namespace codeception\_pages;
use yii\codeception\BasePage;

View File

@ -1,6 +1,6 @@
<?php
namespace tests\_pages;
namespace codeception\_pages;
use yii\codeception\BasePage;

View File

@ -1,6 +1,6 @@
<?php
namespace tests\_pages;
namespace codeception\_pages;
use yii\codeception\BasePage;

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\AboutPage;
use codeception\_pages\AboutPage;
$I = new WebGuy($scenario);
$I->wantTo('ensure that about works');

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\ContactPage;
use codeception\_pages\ContactPage;
$I = new WebGuy($scenario);
$I->wantTo('ensure that contact works');

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\LoginPage;
use codeception\_pages\LoginPage;
$I = new WebGuy($scenario);
$I->wantTo('ensure that login works');

View File

@ -1,7 +1,7 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/web.php'),
require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [

View File

@ -8,5 +8,7 @@ defined('YII_ENV') or define('YII_ENV', 'test');
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));
defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
defined('ROOT_DIR') or define('ROOT_DIR', dirname(dirname(dirname(__DIR__))));
require(ROOT_DIR . '/vendor/autoload.php');
require(ROOT_DIR . '/vendor/yiisoft/yii2/Yii.php');

View File

@ -0,0 +1,27 @@
#!/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/
*/
require_once __DIR__ . '/_console_bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require(ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance',
],
],
]
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %*
"%PHP_COMMAND%" "%YII_PATH%yii_acceptance" %*
@endlocal

View File

@ -0,0 +1,27 @@
#!/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/
*/
require_once __DIR__ . '/_console_bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require(ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional',
],
],
]
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %*
"%PHP_COMMAND%" "%YII_PATH%yii_functional" %*
@endlocal

View File

@ -0,0 +1,27 @@
#!/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/
*/
require_once __DIR__ . '/_console_bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require(ROOT_DIR . '/config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_unit',
],
],
]
);
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -15,6 +15,6 @@ set YII_PATH=%~dp0
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe
"%PHP_COMMAND%" "%YII_PATH%yii" %*
"%PHP_COMMAND%" "%YII_PATH%yii_unit" %*
@endlocal

View File

@ -13,4 +13,4 @@ modules:
- Yii2
config:
Yii2:
configFile: 'tests/functional/_config.php'
configFile: 'codeception/functional/_config.php'

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\AboutPage;
use codeception\_pages\AboutPage;
$I = new TestGuy($scenario);
$I->wantTo('ensure that about works');

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\ContactPage;
use codeception\_pages\ContactPage;
$I = new TestGuy($scenario);
$I->wantTo('ensure that contact works');

View File

@ -1,6 +1,6 @@
<?php
use tests\_pages\LoginPage;
use codeception\_pages\LoginPage;
$I = new TestGuy($scenario);
$I->wantTo('ensure that login works');

View File

@ -5,7 +5,7 @@ $_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE;
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL;
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/web.php'),
require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [

View File

@ -1,7 +1,7 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/web.php'),
require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [

View File

@ -1,6 +1,6 @@
<?php
namespace tests\unit\models;
namespace codeception\unit\models;
use Yii;
use yii\codeception\TestCase;

View File

@ -1,6 +1,6 @@
<?php
namespace tests\unit\models;
namespace codeception\unit\models;
use Yii;
use yii\codeception\TestCase;

View File

@ -1,6 +1,6 @@
<?php
namespace tests\unit\models;
namespace codeception\unit\models;
use yii\codeception\TestCase;

View File

@ -1,13 +0,0 @@
<?php
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../config/console.php'),
require(__DIR__ . '/../_config.php'),
[
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional',
],
],
]
);

View File

@ -1,17 +0,0 @@
#!/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/
*/
require_once __DIR__ . '/../_console_bootstrap.php';
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -1,13 +0,0 @@
<?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',
],
],
]
);

View File

@ -1,17 +0,0 @@
#!/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/
*/
require_once __DIR__ . '/../_console_bootstrap.php';
$config = require(__DIR__ . '/_console.php');
$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);

View File

@ -11,6 +11,6 @@ defined('YII_ENV') or define('YII_ENV', 'test');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../tests/acceptance/_config.php');
$config = require(__DIR__ . '/../tests/codeception/acceptance/_config.php');
(new yii\web\Application($config))->run();