From 03a2fb25335b1f740356c42474c2691a0006ac16 Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Tue, 28 Jun 2016 14:12:30 +0200 Subject: [PATCH] Yii1 module improvements: added `init` part to not conflict with WebDriver (#3285) --- docs/modules/Yii1.md | 75 +++++++++++++++++++-------- src/Codeception/Module/Yii1.php | 91 +++++++++++++++++++++++++-------- 2 files changed, 125 insertions(+), 41 deletions(-) diff --git a/docs/modules/Yii1.md b/docs/modules/Yii1.md index ce222336da..6e500f5837 100644 --- a/docs/modules/Yii1.md +++ b/docs/modules/Yii1.md @@ -1,17 +1,19 @@ # Yii1 -This module provides integration with Yii framework (http://www.yiiframework.com/) (1.1.14dev). +This module provides integration with [Yii Framework 1.1](http://www.yiiframework.com/doc/guide/). The following configurations are available for this module: - + + * `appPath` - full path to the application, include index.php + * `url` - full url to the index.php entry script + In your index.php you must return an array with correct configuration for the application: For the simple created yii application index.php will be like this: -
+
+```php
+ 'CWebApplication',
        'config' => $config,
 );
-
+``` + +You can use this module by setting params in your `functional.suite.yml`: -You can use this module by setting params in your functional.suite.yml: -
-class_name: TestGuy
+```yaml
+class_name: FunctionalTester
 modules:
-    enabled: [Yii1, TestHelper]
-    config:
-        Yii1:
+    enabled:
+        - Yii1:
             appPath: '/path/to/index.php'
             url: 'http://localhost/path/to/index.php'
-
- + - \Helper\Functional +``` You will also need to install [Codeception-Yii Bridge](https://github.com/Codeception/YiiBridge) which include component wrappers for testing. -When you are done, you can test this module by creating new empty Yii application and creating this scenario: -
-$I = new TestGuy($scenario);
+When you are done, you can test this module by creating new empty Yii application and creating this Cept scenario:
+
+```
+php codecept.phar g:cept functional IndexCept
+```
+
+and write it as in example:
+
+```php
+wantTo('Test index page');
 $I->amOnPage('/index.php');
 $I->see('My Web Application','#header #logo');
@@ -57,12 +67,37 @@ $I->click('#login-form input[type="submit"]');
 $I->seeLink('Logout (demo)');
 $I->click('Logout (demo)');
 $I->seeLink('Login');
-
+``` + Then run codeception: php codecept.phar --steps run functional You must see "OK" and that all steps are marked with asterisk (*). Do not forget that after adding module in your functional.suite.yml you must run codeception "build" command. -@property Codeception\Lib\Connector\Yii1 $client +### Public Properties + +`client`: instance of `\Codeception\Lib\Connector\Yii1` + +### Parts + +* `init`: only initializes module and not provides any actions from it. Can be used for unit/acceptance tests to avoid conflicts. + +### Acceptance Testing Example: + +In `acceptance.suite.yml`: + +```yaml +class_name: AcceptanceTester +modules: + enabled: + - WebDriver: + browser: firefox + url: http://localhost + - Yii1: + appPath: '/path/to/index.php' + url: 'http://localhost/path/to/index.php' + part: init # to not conflict with WebDriver + - \Helper\Acceptance +``` ## Actions diff --git a/src/Codeception/Module/Yii1.php b/src/Codeception/Module/Yii1.php index e9b3296e33..9d827054aa 100644 --- a/src/Codeception/Module/Yii1.php +++ b/src/Codeception/Module/Yii1.php @@ -3,23 +3,26 @@ use Codeception\Lib\Framework; use Codeception\Exception\ModuleConfigException; +use Codeception\Lib\Interfaces\PartedModule; use Codeception\TestInterface; use Codeception\Lib\Connector\Yii1 as Yii1Connector; use Codeception\Util\ReflectionHelper; use Yii; /** - * This module provides integration with Yii framework (http://www.yiiframework.com/) (1.1.14dev). + * This module provides integration with [Yii Framework 1.1](http://www.yiiframework.com/doc/guide/). * * The following configurations are available for this module: - * + * + * * `appPath` - full path to the application, include index.php + * * `url` - full url to the index.php entry script + * * In your index.php you must return an array with correct configuration for the application: * * For the simple created yii application index.php will be like this: - *
+ *
+ * ```php
+ *  'CWebApplication',
  *        'config' => $config,
  * );
- * 
+ * ``` * - * You can use this module by setting params in your functional.suite.yml: - *
- * class_name: TestGuy
+ * You can use this module by setting params in your `functional.suite.yml`:
+ *
+ * ```yaml
+ * class_name: FunctionalTester
  * modules:
- *     enabled: [Yii1, TestHelper]
- *     config:
- *         Yii1:
+ *     enabled:
+ *         - Yii1:
  *             appPath: '/path/to/index.php'
  *             url: 'http://localhost/path/to/index.php'
- * 
- * + * - \Helper\Functional + * ``` * * You will also need to install [Codeception-Yii Bridge](https://github.com/Codeception/YiiBridge) * which include component wrappers for testing. * - * When you are done, you can test this module by creating new empty Yii application and creating this scenario: - *
- * $I = new TestGuy($scenario);
+ * When you are done, you can test this module by creating new empty Yii application and creating this Cept scenario:
+ *
+ * ```
+ * php codecept.phar g:cept functional IndexCept
+ * ```
+ *
+ * and write it as in example:
+ *
+ * ```php
+ * wantTo('Test index page');
  * $I->amOnPage('/index.php');
  * $I->see('My Web Application','#header #logo');
@@ -65,14 +76,47 @@
  * $I->seeLink('Logout (demo)');
  * $I->click('Logout (demo)');
  * $I->seeLink('Login');
- * 
+ * ``` + * * Then run codeception: php codecept.phar --steps run functional * You must see "OK" and that all steps are marked with asterisk (*). * Do not forget that after adding module in your functional.suite.yml you must run codeception "build" command. * - * @property Codeception\Lib\Connector\Yii1 $client + * ### Public Properties + * + * `client`: instance of `\Codeception\Lib\Connector\Yii1` + * + * ### Parts + * + * If you ever encounter error message: + * + * ``` + * Yii1 module conflicts with WebDriver + * ``` + * + * you should include Yii module partially, with `init` part only + * + * * `init`: only initializes module and not provides any actions from it. Can be used for unit/acceptance tests to avoid conflicts. + * + * ### Acceptance Testing Example: + * + * In `acceptance.suite.yml`: + * + * ```yaml + * class_name: AcceptanceTester + * modules: + * enabled: + * - WebDriver: + * browser: firefox + * url: http://localhost + * - Yii1: + * appPath: '/path/to/index.php' + * url: 'http://localhost/path/to/index.php' + * part: init # to not conflict with WebDriver + * - \Helper\Acceptance + * ``` */ -class Yii1 extends Framework +class Yii1 extends Framework implements PartedModule { /** @@ -212,4 +256,9 @@ public function getInternalDomains() } return array_unique($domains); } + + public function _parts() + { + return ['init', 'initialize']; + } }