From 3f4ee3e48c1fe9a4ffac25cdd9c2f84b4eb7c06a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 28 Dec 2013 15:04:08 -0500 Subject: [PATCH] Fixes #1604: fixed URL and cookie problems. Refactored tests. --- apps/basic/config/codeception/acceptance.php | 11 ------- apps/basic/config/codeception/functional.php | 17 ----------- apps/basic/config/codeception/unit.php | 15 ---------- apps/basic/tests/README.md | 45 ++++++++++++---------------- apps/basic/tests/_bootstrap.php | 13 ++++++++ apps/basic/tests/acceptance.suite.yml | 4 +-- apps/basic/tests/acceptance/HomeCept.php | 2 +- apps/basic/tests/acceptance/_bootstrap.php | 7 +---- apps/basic/tests/acceptance/_config.php | 13 ++++++++ apps/basic/tests/functional.suite.yml | 3 +- apps/basic/tests/functional/HomeCept.php | 2 +- apps/basic/tests/functional/_bootstrap.php | 3 +- apps/basic/tests/functional/_config.php | 17 +++++++++++ apps/basic/web/index-test-acceptance.php | 16 ---------- apps/basic/web/index-test-functional.php | 11 ------- apps/basic/web/index-test.php | 16 ++++++++++ 16 files changed, 85 insertions(+), 110 deletions(-) delete mode 100644 apps/basic/config/codeception/acceptance.php delete mode 100644 apps/basic/config/codeception/functional.php delete mode 100644 apps/basic/config/codeception/unit.php create mode 100644 apps/basic/tests/acceptance/_config.php create mode 100644 apps/basic/tests/functional/_config.php delete mode 100644 apps/basic/web/index-test-acceptance.php delete mode 100644 apps/basic/web/index-test-functional.php create mode 100644 apps/basic/web/index-test.php diff --git a/apps/basic/config/codeception/acceptance.php b/apps/basic/config/codeception/acceptance.php deleted file mode 100644 index 6036f88..0000000 --- a/apps/basic/config/codeception/acceptance.php +++ /dev/null @@ -1,11 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance', - ], - ], -]; diff --git a/apps/basic/config/codeception/functional.php b/apps/basic/config/codeception/functional.php deleted file mode 100644 index 210b97d..0000000 --- a/apps/basic/config/codeception/functional.php +++ /dev/null @@ -1,17 +0,0 @@ - [ - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional', - ], - 'request' => [ - 'enableCsrfValidation' => false, - ], - 'urlManager' => [ - 'baseUrl' => '/web/index.php', - ], - ], -]; diff --git a/apps/basic/config/codeception/unit.php b/apps/basic/config/codeception/unit.php deleted file mode 100644 index fd66970..0000000 --- a/apps/basic/config/codeception/unit.php +++ /dev/null @@ -1,15 +0,0 @@ - [ - 'fixture' => [ - 'class' => 'yii\test\DbFixtureManager', - 'basePath' => '@tests/unit/fixtures', - ], - 'db' => [ - 'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit', - ], - ], -]; diff --git a/apps/basic/tests/README.md b/apps/basic/tests/README.md index 5ff2669..83b0511 100644 --- a/apps/basic/tests/README.md +++ b/apps/basic/tests/README.md @@ -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. diff --git a/apps/basic/tests/_bootstrap.php b/apps/basic/tests/_bootstrap.php index ec9390e..5a40d64 100644 --- a/apps/basic/tests/_bootstrap.php +++ b/apps/basic/tests/_bootstrap.php @@ -1,9 +1,22 @@ wantTo('ensure that home page works'); -$I->amOnPage(''); +$I->amOnPage(Yii::$app->homeUrl); $I->see('My Company'); $I->seeLink('About'); $I->click('About'); diff --git a/apps/basic/tests/acceptance/_bootstrap.php b/apps/basic/tests/acceptance/_bootstrap.php index 32bac62..6ce3d17 100644 --- a/apps/basic/tests/acceptance/_bootstrap.php +++ b/apps/basic/tests/acceptance/_bootstrap.php @@ -1,8 +1,3 @@ [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_acceptance', + ], + ], +]); diff --git a/apps/basic/tests/functional.suite.yml b/apps/basic/tests/functional.suite.yml index b7d86de..0d400af 100644 --- a/apps/basic/tests/functional.suite.yml +++ b/apps/basic/tests/functional.suite.yml @@ -14,5 +14,4 @@ modules: - Yii2 config: Yii2: - entryScript: 'web/index-test-functional.php' - url: 'http://localhost/' + configFile: 'tests/functional/_config.php' diff --git a/apps/basic/tests/functional/HomeCept.php b/apps/basic/tests/functional/HomeCept.php index 0658ba2..3258ba3 100644 --- a/apps/basic/tests/functional/HomeCept.php +++ b/apps/basic/tests/functional/HomeCept.php @@ -2,7 +2,7 @@ $I = new TestGuy($scenario); $I->wantTo('ensure that home page works'); -$I->amOnPage(''); +$I->amOnPage(Yii::$app->homeUrl); $I->see('My Company'); $I->seeLink('About'); $I->click('About'); diff --git a/apps/basic/tests/functional/_bootstrap.php b/apps/basic/tests/functional/_bootstrap.php index 6692104..6ce3d17 100644 --- a/apps/basic/tests/functional/_bootstrap.php +++ b/apps/basic/tests/functional/_bootstrap.php @@ -1,4 +1,3 @@ [ + 'db' => [ + 'dsn' => 'mysql:host=localhost;dbname=yii2_basic_functional', + ], + ], +]); diff --git a/apps/basic/web/index-test-acceptance.php b/apps/basic/web/index-test-acceptance.php deleted file mode 100644 index ef9ec75..0000000 --- a/apps/basic/web/index-test-acceptance.php +++ /dev/null @@ -1,16 +0,0 @@ -run(); diff --git a/apps/basic/web/index-test-functional.php b/apps/basic/web/index-test-functional.php deleted file mode 100644 index 65fd3fa..0000000 --- a/apps/basic/web/index-test-functional.php +++ /dev/null @@ -1,11 +0,0 @@ -run();