Skip to content

Commit

Permalink
Yii1 module improvements: added init part to not conflict with WebD…
Browse files Browse the repository at this point in the history
…river (Codeception#3285)
  • Loading branch information
DavertMik committed Jun 28, 2016
1 parent dc23acf commit 03a2fb2
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 41 deletions.
75 changes: 55 additions & 20 deletions 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:
<ul>
<li>appPath - full path to the application, include index.php</li>
<li>url - full url to the index.php entry script</li>
</ul>

* `appPath` - full path to the application, include index.php</li>
* `url` - full url to the index.php entry script</li>

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:
<pre>

```php
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
Expand All @@ -25,26 +27,34 @@ return array(
'class' => 'CWebApplication',
'config' => $config,
);
</pre>
```

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:
<pre>
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'
</pre>

- \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:
<pre>
$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
<?php
$I = new FunctionalTester($scenario);
$I->wantTo('Test index page');
$I->amOnPage('/index.php');
$I->see('My Web Application','#header #logo');
Expand All @@ -57,12 +67,37 @@ $I->click('#login-form input[type="submit"]');
$I->seeLink('Logout (demo)');
$I->click('Logout (demo)');
$I->seeLink('Login');
</pre>
```

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
Expand Down
91 changes: 70 additions & 21 deletions src/Codeception/Module/Yii1.php
Expand Up @@ -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:
* <ul>
* <li>appPath - full path to the application, include index.php</li>
* <li>url - full url to the index.php entry script</li>
* </ul>
*
* * `appPath` - full path to the application, include index.php</li>
* * `url` - full url to the index.php entry script</li>
*
* 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:
* <pre>
*
* ```php
* <?php
* // change the following paths if necessary
* $yii=dirname(__FILE__).'/../yii/framework/yii.php';
* $config=dirname(__FILE__).'/protected/config/main.php';
Expand All @@ -33,26 +36,34 @@
* 'class' => 'CWebApplication',
* 'config' => $config,
* );
* </pre>
* ```
*
* You can use this module by setting params in your functional.suite.yml:
* <pre>
* 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'
* </pre>
*
* - \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:
* <pre>
* $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
* <?php
* $I = new FunctionalTester($scenario);
* $I->wantTo('Test index page');
* $I->amOnPage('/index.php');
* $I->see('My Web Application','#header #logo');
Expand All @@ -65,14 +76,47 @@
* $I->seeLink('Logout (demo)');
* $I->click('Logout (demo)');
* $I->seeLink('Login');
* </pre>
* ```
*
* 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
{

/**
Expand Down Expand Up @@ -212,4 +256,9 @@ public function getInternalDomains()
}
return array_unique($domains);
}

public function _parts()
{
return ['init', 'initialize'];
}
}

0 comments on commit 03a2fb2

Please sign in to comment.