Added basic yii support for codeception #115

Merged
merged 2 commits into from Jan 26, 2013

Conversation

Projects
None yet
3 participants
@Ragazzo
Contributor

Ragazzo commented Jan 18, 2013

This PR provides basic yii and codeception integration. In Codeception\Module\Yii1 there are docs about how to use it and how to patch CHttpRequest. I did tests on basic yii application that was created by yiic webapp and they passed. Scenario that i use is in the Yii1 module docs. So i will later do a gist with those docs and will add link on it in the module description, and i think will provide some debug info for this module like in the codeception docs are written (http://codeception.com/docs/05-FunctionalTests)

It's preferred that it be able to print additional debug information.

But i think this one can be merged so other developers will already have working integration and they can modify it or add something new. What do u think @DavertMik ?

@Ragazzo Ragazzo referenced this pull request in yiisoft/yii Jan 20, 2013

Closed

Yii and Codeception #1998

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Jan 23, 2013

Contributor

@DavertMik so i added new class(plugins/frameworks/yii/CodeceptionHttpRequest) that must be used in codeception to avoid headers sent, it also handle cookies. I've tested on yii fresh created app, that was created through console by running yiic webapp and i've tested on currently developing application with db, cache, etc..., connector and module works correctly. But i have some trobles with codeception itself when it cant see selector like this button[type="submit"] or it sometimes cant see text when i call $I->see(), but page renders correctly. You can test it too on some yii web app, or create new with this guide http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app and run the cept that i've wrote in the module Yii docs, this cept:

$I = new TestGuy($scenario);
$I->wantTo('Test index page');
$I->amOnPage('/index.php');
$I->see('My Web Application','#header #logo');
$I->click('Login');
$I->see('Login','h1');
$I->see('Username');
$I->fillField('#LoginForm_username','demo');
$I->fillField('#LoginForm_password','demo');
$I->click('#login-form input[type="submit"]');
$I->seeLink('Logout (demo)');
$I->click('Logout (demo)');
$I->seeLink('Login');

But dont forget to add in protected/config/main.php in components array:

'request' => array(
    'class'=>'CodeceptionHttpRequest',
),

and put this file (from plugins/frameworks/yii/CodeceptionHttpRequest) to components folder under protected, so it will be auto-imported when app starts.

Contributor

Ragazzo commented Jan 23, 2013

@DavertMik so i added new class(plugins/frameworks/yii/CodeceptionHttpRequest) that must be used in codeception to avoid headers sent, it also handle cookies. I've tested on yii fresh created app, that was created through console by running yiic webapp and i've tested on currently developing application with db, cache, etc..., connector and module works correctly. But i have some trobles with codeception itself when it cant see selector like this button[type="submit"] or it sometimes cant see text when i call $I->see(), but page renders correctly. You can test it too on some yii web app, or create new with this guide http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app and run the cept that i've wrote in the module Yii docs, this cept:

$I = new TestGuy($scenario);
$I->wantTo('Test index page');
$I->amOnPage('/index.php');
$I->see('My Web Application','#header #logo');
$I->click('Login');
$I->see('Login','h1');
$I->see('Username');
$I->fillField('#LoginForm_username','demo');
$I->fillField('#LoginForm_password','demo');
$I->click('#login-form input[type="submit"]');
$I->seeLink('Logout (demo)');
$I->click('Logout (demo)');
$I->seeLink('Login');

But dont forget to add in protected/config/main.php in components array:

'request' => array(
    'class'=>'CodeceptionHttpRequest',
),

and put this file (from plugins/frameworks/yii/CodeceptionHttpRequest) to components folder under protected, so it will be auto-imported when app starts.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Jan 25, 2013

Contributor

@DavertMik did u test/check it?)

Contributor

Ragazzo commented Jan 25, 2013

@DavertMik did u test/check it?)

DavertMik added a commit that referenced this pull request Jan 26, 2013

@DavertMik DavertMik merged commit 5107ce5 into Codeception:master Jan 26, 2013

1 check failed

default The Travis build failed
Details
@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jan 26, 2013

Member

sorry, not yet. Didn't have time last days. Well, let's merge and find out )
Thanks for this commit. Great job!

Member

DavertMik commented Jan 26, 2013

sorry, not yet. Didn't have time last days. Well, let's merge and find out )
Thanks for this commit. Great job!

@Ragazzo Ragazzo deleted the Ragazzo:Yii-and-Codeception-integration branch Jan 26, 2013

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jan 27, 2013

Member

I have:

<?php
return CMap::mergeArray(
    require(dirname(__FILE__).'/main.php'),
    array(
        'components'=>array(
            'fixture'=>array(
                'class'=>'system.test.CDbFixtureManager',
            ),
            'db'=>array(
                'connectionString'=>'sqlite:'.dirname(__FILE__).'/../data/blog-test.db',
            ),
        'request' => array(
            'class'=> CODECEPTION_LIB_ROOT.'/plugins/frameworks/yii/web/CodeceptionHttpRequest',
        ),

I get:

Cannot redeclare class CodeceptionHttpRequest

:(

Member

DavertMik commented Jan 27, 2013

I have:

<?php
return CMap::mergeArray(
    require(dirname(__FILE__).'/main.php'),
    array(
        'components'=>array(
            'fixture'=>array(
                'class'=>'system.test.CDbFixtureManager',
            ),
            'db'=>array(
                'connectionString'=>'sqlite:'.dirname(__FILE__).'/../data/blog-test.db',
            ),
        'request' => array(
            'class'=> CODECEPTION_LIB_ROOT.'/plugins/frameworks/yii/web/CodeceptionHttpRequest',
        ),

I get:

Cannot redeclare class CodeceptionHttpRequest

:(

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Jan 27, 2013

Contributor

No, i mean put CodeceptionHttpRequest under the yii application components, because Yii autoloader wil not found file in the codeception directory (
So request will be:

        'request' => array(
            'class'=> 'CodeceptionHttpRequest',
        ),

where CodeceptionHttpRequest is a file that located under yourapp/protected/components
I will do some more research on how maybe add out-of-the-box support for it, will try to provide PR in few days, but for now as i said, all you need to do is just copy it on your components folder of your app )

Contributor

Ragazzo commented Jan 27, 2013

No, i mean put CodeceptionHttpRequest under the yii application components, because Yii autoloader wil not found file in the codeception directory (
So request will be:

        'request' => array(
            'class'=> 'CodeceptionHttpRequest',
        ),

where CodeceptionHttpRequest is a file that located under yourapp/protected/components
I will do some more research on how maybe add out-of-the-box support for it, will try to provide PR in few days, but for now as i said, all you need to do is just copy it on your components folder of your app )

@schmunk42

This comment has been minimized.

Show comment
Hide comment
@schmunk42

schmunk42 Mar 4, 2013

Contributor

@Ragazzo I installed codeception in my Yii Application (Phundament) via composer and I am able to use it out of the box, at least without CodeceptionHttpRequest - but I've only tried acceptance tests so far, so maybe I am missing something?!

See this document about Installing Phundament and this one about adding codeception and here are my (combined) Cepts for Phundament.

Let me know, if you want to elaborate this.

Contributor

schmunk42 commented Mar 4, 2013

@Ragazzo I installed codeception in my Yii Application (Phundament) via composer and I am able to use it out of the box, at least without CodeceptionHttpRequest - but I've only tried acceptance tests so far, so maybe I am missing something?!

See this document about Installing Phundament and this one about adding codeception and here are my (combined) Cepts for Phundament.

Let me know, if you want to elaborate this.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 4, 2013

Contributor

Well, CodeceptionHttpRequest is only needed in functional tests where all tests are proceed in the codeception internals (without curl just symfony browser-kit), so Yii1 module purpose is to use it in codeceptionfunctional (they are much faster then acceptance) and unit tests, for acceptance tests you dont need it. Need to notice that in last days there were important fix for the unit testing with codeception and Yii, so if u want to use latest snapshot you need to use codeception source, or add plugins\frameworks\yii1 directory in phar complier file lists (so the Yii1 module in codeception will auto-import CodeceptionHttpRequest and other things like CTestCase, CDbTestCase). We've discussed this (adding this folder in the phar file lists) with @DavertMik here #198 (comment).

Contributor

Ragazzo commented Mar 4, 2013

Well, CodeceptionHttpRequest is only needed in functional tests where all tests are proceed in the codeception internals (without curl just symfony browser-kit), so Yii1 module purpose is to use it in codeceptionfunctional (they are much faster then acceptance) and unit tests, for acceptance tests you dont need it. Need to notice that in last days there were important fix for the unit testing with codeception and Yii, so if u want to use latest snapshot you need to use codeception source, or add plugins\frameworks\yii1 directory in phar complier file lists (so the Yii1 module in codeception will auto-import CodeceptionHttpRequest and other things like CTestCase, CDbTestCase). We've discussed this (adding this folder in the phar file lists) with @DavertMik here #198 (comment).

@schmunk42

This comment has been minimized.

Show comment
Hide comment
@schmunk42

schmunk42 Mar 4, 2013

Contributor

Thank you so far, I think I need to take a closer look at it.

Contributor

schmunk42 commented Mar 4, 2013

Thank you so far, I think I need to take a closer look at it.

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 4, 2013

Contributor

Ok) feel free to create new issues on codeception repo about some Yii module improvements, bugs, etc. any help or suggestions are really appreciated :)

Contributor

Ragazzo commented Mar 4, 2013

Ok) feel free to create new issues on codeception repo about some Yii module improvements, bugs, etc. any help or suggestions are really appreciated :)

@schmunk42

This comment has been minimized.

Show comment
Hide comment
@schmunk42

schmunk42 Mar 4, 2013

Contributor

So I've a question ... my app still creates the default tests from the Yii Web App Skeleton into tests/.
But when I run codeception bootstrap then its tests also get generated into the same directory.

But AFAIK codeception can at least do the same things for you, like Yii's default test suite, but in a much more convenient way.

Would you recommend to replace Yii's default test suite completely with codeception or would it lack some features?

Contributor

schmunk42 commented Mar 4, 2013

So I've a question ... my app still creates the default tests from the Yii Web App Skeleton into tests/.
But when I run codeception bootstrap then its tests also get generated into the same directory.

But AFAIK codeception can at least do the same things for you, like Yii's default test suite, but in a much more convenient way.

Would you recommend to replace Yii's default test suite completely with codeception or would it lack some features?

@Ragazzo

This comment has been minimized.

Show comment
Hide comment
@Ragazzo

Ragazzo Mar 4, 2013

Contributor

Well, afaik you can place codeception tests anywhere u want (need to check bootstrap config switchers), but as for me i got this structure in protected folder:

tests
    codeception
        codeception.yml \\here generated by codeception files and other
        fixtures \\fixtures for codeception
    functional  \\standard yii tests files and folders goes below
    unit
     ....

For now i prefer classic phpunit tests in Yii, thats why i use unit folder in standard yii tests folder, i use codeception more for acceptance and functional tests, but you can also use it for unit-tests too, it can handle them out-of-the-box (u can also generate them with generate:phpunit command). As for me this all just "a matter of taste"

Contributor

Ragazzo commented Mar 4, 2013

Well, afaik you can place codeception tests anywhere u want (need to check bootstrap config switchers), but as for me i got this structure in protected folder:

tests
    codeception
        codeception.yml \\here generated by codeception files and other
        fixtures \\fixtures for codeception
    functional  \\standard yii tests files and folders goes below
    unit
     ....

For now i prefer classic phpunit tests in Yii, thats why i use unit folder in standard yii tests folder, i use codeception more for acceptance and functional tests, but you can also use it for unit-tests too, it can handle them out-of-the-box (u can also generate them with generate:phpunit command). As for me this all just "a matter of taste"

@schmunk42

This comment has been minimized.

Show comment
Hide comment
@schmunk42

schmunk42 Mar 4, 2013

Contributor

I think ... I'll do it the same way, that sounds good, thank you!

Contributor

schmunk42 commented Mar 4, 2013

I think ... I'll do it the same way, that sounds good, thank you!

@schmunk42

This comment has been minimized.

Show comment
Hide comment
@schmunk42

schmunk42 Mar 5, 2013

Contributor

Just for the record, I did the following:

vendor/bin/codecept bootstrap tests/codeception

I've also updated our wiki page.

Contributor

schmunk42 commented Mar 5, 2013

Just for the record, I did the following:

vendor/bin/codecept bootstrap tests/codeception

I've also updated our wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment