Ver código fonte

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.
Alexander Makarov 11 anos atrás
pai
commit
c55a791237
48 arquivos alterados com 150 adições e 144 exclusões
  1. 0 5
      composer.json
  2. 35 17
      tests/README.md
  3. 0 13
      tests/acceptance/_console.php
  4. 0 17
      tests/acceptance/yii
  5. 5 5
      codeception.yml
  6. 0 0
      tests/codeception/.gitignore
  7. 5 5
      tests/_bootstrap.php
  8. 0 0
      tests/codeception/_config.php
  9. 0 0
      tests/codeception/_data/dump.sql
  10. 0 0
      tests/codeception/_log/.gitignore
  11. 1 1
      tests/_pages/AboutPage.php
  12. 1 1
      tests/_pages/ContactPage.php
  13. 1 1
      tests/_pages/LoginPage.php
  14. 0 0
      tests/codeception/acceptance.suite.yml
  15. 1 1
      tests/acceptance/AboutCept.php
  16. 1 1
      tests/acceptance/ContactCept.php
  17. 0 0
      tests/codeception/acceptance/HomeCept.php
  18. 1 1
      tests/acceptance/LoginCept.php
  19. 0 0
      tests/codeception/acceptance/_bootstrap.php
  20. 1 1
      tests/acceptance/_config.php
  21. 4 2
      tests/_console_bootstrap.php
  22. 27 0
      tests/codeception/bin/yii_acceptance
  23. 1 1
      tests/acceptance/yii.bat
  24. 27 0
      tests/codeception/bin/yii_functional
  25. 1 1
      tests/unit/yii.bat
  26. 27 0
      tests/codeception/bin/yii_unit
  27. 1 1
      tests/functional/yii.bat
  28. 1 1
      tests/functional.suite.yml
  29. 1 1
      tests/functional/AboutCept.php
  30. 1 1
      tests/functional/ContactCept.php
  31. 0 0
      tests/codeception/functional/HomeCept.php
  32. 1 1
      tests/functional/LoginCept.php
  33. 0 0
      tests/codeception/functional/_bootstrap.php
  34. 1 1
      tests/functional/_config.php
  35. 0 0
      tests/codeception/unit.suite.yml
  36. 0 0
      tests/codeception/unit/_bootstrap.php
  37. 1 1
      tests/unit/_config.php
  38. 0 0
      tests/codeception/unit/fixtures/.gitkeep
  39. 0 0
      tests/codeception/unit/fixtures/data/.gitkeep
  40. 1 1
      tests/unit/models/ContactFormTest.php
  41. 1 1
      tests/unit/models/LoginFormTest.php
  42. 1 1
      tests/unit/models/UserTest.php
  43. 0 0
      tests/codeception/unit/templates/fixtures/.gitkeep
  44. 0 13
      tests/functional/_console.php
  45. 0 17
      tests/functional/yii
  46. 0 13
      tests/unit/_console.php
  47. 0 17
      tests/unit/yii
  48. 1 1
      web/index-test.php

+ 0 - 5
composer.json

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

+ 35 - 17
tests/README.md

@@ -1,32 +1,50 @@
-This folder contains various tests for the basic application.
-These tests are developed with [Codeception PHP Testing Framework](http://codeception.com/).
+This directory contains various tests for the basic application.
+
+Tests in `codeception` directory are developed with [Codeception PHP Testing Framework](http://codeception.com/).
 
 After creating the basic application, follow these steps to prepare for the tests:
 
-1. Install additional composer packages:
+1. Install Codeception if it's not yet installed:
+
+```
+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>
+```
 
-   ```
-   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:
+Then add `<directory>/vendor/bin` to you `PATH` environment variable. Now we're able to use `codecept` from command
+line globally.
 
-   ```
-   vendor/bin/codecept build
-   ```
+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
+```
 
-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
-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

+ 0 - 13
tests/acceptance/_console.php

@@ -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',
-            ],
-        ],
-    ]
-);

+ 0 - 17
tests/acceptance/yii

@@ -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);

+ 5 - 5
codeception.yml

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

tests/.gitignore → tests/codeception/.gitignore


+ 5 - 5
tests/_bootstrap.php

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

tests/_config.php → tests/codeception/_config.php


tests/_data/dump.sql → tests/codeception/_data/dump.sql


tests/_log/.gitignore → tests/codeception/_log/.gitignore


+ 1 - 1
tests/_pages/AboutPage.php

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

+ 1 - 1
tests/_pages/ContactPage.php

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

+ 1 - 1
tests/_pages/LoginPage.php

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

tests/acceptance.suite.yml → tests/codeception/acceptance.suite.yml


+ 1 - 1
tests/acceptance/AboutCept.php

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

+ 1 - 1
tests/acceptance/ContactCept.php

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

tests/acceptance/HomeCept.php → tests/codeception/acceptance/HomeCept.php


+ 1 - 1
tests/acceptance/LoginCept.php

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

tests/acceptance/_bootstrap.php → tests/codeception/acceptance/_bootstrap.php


+ 1 - 1
tests/acceptance/_config.php

@@ -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' => [

+ 4 - 2
tests/_console_bootstrap.php

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

+ 27 - 0
tests/codeception/bin/yii_acceptance

@@ -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);

+ 1 - 1
tests/acceptance/yii.bat

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

+ 27 - 0
tests/codeception/bin/yii_functional

@@ -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);

+ 1 - 1
tests/unit/yii.bat

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

+ 27 - 0
tests/codeception/bin/yii_unit

@@ -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);

+ 1 - 1
tests/functional/yii.bat

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

+ 1 - 1
tests/functional.suite.yml

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

+ 1 - 1
tests/functional/AboutCept.php

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

+ 1 - 1
tests/functional/ContactCept.php

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

tests/functional/HomeCept.php → tests/codeception/functional/HomeCept.php


+ 1 - 1
tests/functional/LoginCept.php

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

tests/functional/_bootstrap.php → tests/codeception/functional/_bootstrap.php


+ 1 - 1
tests/functional/_config.php

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

tests/unit.suite.yml → tests/codeception/unit.suite.yml


tests/unit/_bootstrap.php → tests/codeception/unit/_bootstrap.php


+ 1 - 1
tests/unit/_config.php

@@ -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' => [

tests/unit/fixtures/.gitkeep → tests/codeception/unit/fixtures/.gitkeep


tests/unit/fixtures/data/.gitkeep → tests/codeception/unit/fixtures/data/.gitkeep


+ 1 - 1
tests/unit/models/ContactFormTest.php

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

+ 1 - 1
tests/unit/models/LoginFormTest.php

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

+ 1 - 1
tests/unit/models/UserTest.php

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

tests/unit/templates/fixtures/.gitkeep → tests/codeception/unit/templates/fixtures/.gitkeep


+ 0 - 13
tests/functional/_console.php

@@ -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',
-            ],
-        ],
-    ]
-);

+ 0 - 17
tests/functional/yii

@@ -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);

+ 0 - 13
tests/unit/_console.php

@@ -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',
-            ],
-        ],
-    ]
-);

+ 0 - 17
tests/unit/yii

@@ -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);

+ 1 - 1
web/index-test.php

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