16 changed files with 85 additions and 110 deletions
			
			
		@ -1,11 +0,0 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
// configuration adjustments for codeception acceptance tests. Will be merged with web.php config. | 
				
			||||
 | 
				
			||||
return [ | 
				
			||||
	'components' => [ | 
				
			||||
		'db' => [ | 
				
			||||
			'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance', | 
				
			||||
		], | 
				
			||||
	], | 
				
			||||
]; | 
				
			||||
@ -1,17 +0,0 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
// configuration adjustments for codeception functional tests. Will be merged with web.php config. | 
				
			||||
 | 
				
			||||
return [ | 
				
			||||
	'components' => [ | 
				
			||||
		'db' => [ | 
				
			||||
			'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional', | 
				
			||||
		], | 
				
			||||
		'request' => [ | 
				
			||||
			'enableCsrfValidation' => false, | 
				
			||||
		], | 
				
			||||
		'urlManager' => [ | 
				
			||||
			'baseUrl' => '/web/index.php', | 
				
			||||
		], | 
				
			||||
	], | 
				
			||||
]; | 
				
			||||
@ -1,15 +0,0 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
// configuration adjustments for codeception unit tests. Will be merged with web.php config. | 
				
			||||
 | 
				
			||||
return [ | 
				
			||||
	'components' => [ | 
				
			||||
		'fixture'	=>	[ | 
				
			||||
			'class'		=>	'yii\test\DbFixtureManager', | 
				
			||||
			'basePath'	=>	'@tests/unit/fixtures', | 
				
			||||
		], | 
				
			||||
		'db' => [ | 
				
			||||
			'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit', | 
				
			||||
		], | 
				
			||||
	], | 
				
			||||
]; | 
				
			||||
@ -1,35 +1,28 @@
					 | 
				
			||||
This folder contains various tests for the basic application. | 
				
			||||
These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/). | 
				
			||||
 | 
				
			||||
To run the tests, follow these steps: | 
				
			||||
After creating the basic application, follow these steps to prepare for the tests: | 
				
			||||
 | 
				
			||||
1. Download Codeception([Quickstart step 1](http://codeception.com/quickstart)) and put the codeception.phar in the | 
				
			||||
   application base directory (not in this `tests` directory!). | 
				
			||||
2. Adjust the test configuration files based on your environment: | 
				
			||||
   - Configure the URL for [acceptance tests](http://codeception.com/docs/04-AcceptanceTests) in `acceptance.suite.yml`. | 
				
			||||
     The URL should point to the `index-test-acceptance.php` file that is located under the `web` directory of the application. | 
				
			||||
   - `functional.suite.yml` for [functional testing](http://codeception.com/docs/05-FunctionalTests) and | 
				
			||||
     `unit.suite.yml` for [unit testing](http://codeception.com/docs/06-UnitTests) should already work out of the box | 
				
			||||
     and should not need to be adjusted. | 
				
			||||
   - If you want to run acceptance tests, you need to download [selenium standalone](http://www.seleniumhq.org/download/) | 
				
			||||
     and start it with command `java -jar {selenium-standalone-name}.jar`. | 
				
			||||
     After that you can use `WebDriver` codeception module that will connect to selenium and launch browser. | 
				
			||||
     This also allows you to use [Xvfb](https://en.wikipedia.org/wiki/Xvfb) in your tests which allows you to run tests | 
				
			||||
     without showing the running browser on the screen. There is codeception [blog post](http://codeception.com/05-24-2013/jenkins-ci-practice.html) | 
				
			||||
     that explains how it works. | 
				
			||||
1. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so | 
				
			||||
   that it points to the correct entry script URL. | 
				
			||||
2. Go to the application base directory and build the test suites: | 
				
			||||
 | 
				
			||||
3. Go to the application base directory and build the test suites: | 
				
			||||
   ``` | 
				
			||||
   php codecept.phar build    // rebuild test scripts, only need to be run once | 
				
			||||
   ``` | 
				
			||||
4. Run the tests: | 
				
			||||
   ``` | 
				
			||||
   php codecept.phar run      // run all available tests | 
				
			||||
   // you can also run a test suite alone: | 
				
			||||
   php codecept.phar run acceptance | 
				
			||||
   php codecept.phar run functional | 
				
			||||
   php codecept.phar run unit | 
				
			||||
   vendor/bin/codecept build | 
				
			||||
   ``` | 
				
			||||
 | 
				
			||||
Now you can run the tests with the following commands: | 
				
			||||
 | 
				
			||||
``` | 
				
			||||
# run all available tests | 
				
			||||
vendor/bin/codecept run | 
				
			||||
# run acceptance tests | 
				
			||||
vendor/bin/codecept run acceptance | 
				
			||||
# run functional tests | 
				
			||||
vendor/bin/codecept run functional | 
				
			||||
# run unit tests | 
				
			||||
vendor/bin/codecept run unit | 
				
			||||
``` | 
				
			||||
 | 
				
			||||
Please refer to [Codeception tutorial](http://codeception.com/docs/01-Introduction) for | 
				
			||||
more details about writing acceptance, functional and unit tests. | 
				
			||||
more details about writing and running acceptance, functional and unit tests. | 
				
			||||
					 | 
				
			||||
@ -1,9 +1,22 @@
					 | 
				
			||||
<?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', '/yii2-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/Yii.php'); | 
				
			||||
 | 
				
			||||
// set correct script paths | 
				
			||||
$_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; | 
				
			||||
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; | 
				
			||||
 | 
				
			||||
Yii::setAlias('@tests', __DIR__); | 
				
			||||
					 | 
				
			||||
@ -1,8 +1,3 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
$config = yii\helpers\ArrayHelper::merge( | 
				
			||||
	require(__DIR__ . '/../../config/web.php'), | 
				
			||||
	require(__DIR__ . '/../../config/codeception/acceptance.php') | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$application = new yii\web\Application($config); | 
				
			||||
new yii\web\Application(require(__DIR__ . '/_config.php')); | 
				
			||||
					 | 
				
			||||
@ -0,0 +1,13 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
use yii\helpers\ArrayHelper; | 
				
			||||
 | 
				
			||||
$config = require(__DIR__ . '/../../config/web.php'); | 
				
			||||
 | 
				
			||||
return ArrayHelper::merge($config, [ | 
				
			||||
	'components' => [ | 
				
			||||
		'db' => [ | 
				
			||||
			'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', | 
				
			||||
		], | 
				
			||||
	], | 
				
			||||
]); | 
				
			||||
@ -1,4 +1,3 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
// create an application instance to support URL creation before running any test | 
				
			||||
Yii::createObject(require(__DIR__ . '/../../web/index-test-functional.php')); | 
				
			||||
new yii\web\Application(require(__DIR__ . '/_config.php')); | 
				
			||||
					 | 
				
			||||
@ -0,0 +1,17 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
use yii\helpers\ArrayHelper; | 
				
			||||
 | 
				
			||||
// set correct script paths | 
				
			||||
$_SERVER['SCRIPT_FILENAME'] = TEST_ENTRY_FILE; | 
				
			||||
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; | 
				
			||||
 | 
				
			||||
$config = require(__DIR__ . '/../../config/web.php'); | 
				
			||||
 | 
				
			||||
return ArrayHelper::merge($config, [ | 
				
			||||
	'components' => [ | 
				
			||||
		'db' => [ | 
				
			||||
			'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', | 
				
			||||
		], | 
				
			||||
	], | 
				
			||||
]); | 
				
			||||
@ -1,11 +0,0 @@
					 | 
				
			||||
<?php | 
				
			||||
 | 
				
			||||
// this file is used as the entry script for codeception functional testing | 
				
			||||
 | 
				
			||||
$config = yii\helpers\ArrayHelper::merge( | 
				
			||||
	require(__DIR__ . '/../config/web.php'), | 
				
			||||
	require(__DIR__ . '/../config/codeception/functional.php') | 
				
			||||
); | 
				
			||||
 | 
				
			||||
$config['class'] = 'yii\web\Application'; | 
				
			||||
return $config; | 
				
			||||
					Loading…
					
					
				
		Reference in new issue