Yii Codeception Module

It is totally not clear what you need to do to use this with Yii.

Not to me, anyway. :)

So, I downloaded codeception.phar into the root of my yii application.

Now what?

functional.suite.yml - I have to create that myself?

In the root folder?

I don’t quite get the thing about [i]You need to use CodeceptionHttpRequest from plugins directory (plugins\frameworks\yii\web),

[/i]…

Do I tell Yii about this in what config? and how?

test.php in protected/config?

I will do some more testing tomorrow when I am less dense, but I think the docs could be greatly improved.

Also, remember: Phundament is Schmunk’s framework, it’s not vanilla Yii, so any guides from it is rather irrelevant (but maybe helpful).

I see elsewhere that Schmunk put the phar in protected/vendor/codeception and ran this:


vendor/bin/codecept bootstrap tests/codeception

I will do that tomorrow. ;)

I ran


php vendors/codecept.phar bootstrap

in my protected directory.

I guess I should continue the guide for the Yii module from here.

Point the CHttpRequest to CodeceptionHttpRequest in protected/config/test.php, right?

After adding the path alias to the codeception yii module, of course.

I still think the docs assumes too much on behalf of the user. ;)

So, I edit the yml like this:




class_name: TestGuy

modules:

    enabled: [Yii1, TestHelper]

    config:

        Yii1:

            appPath: '/path/to/index-test.php'

            url: 'http://localhost/path/to/index-test.php'



Where, of course, the config points to config/test.php where I tell Yii to use the Codeception HttpRequest component.

So, then I run codeception from the protected folder.

That sounds like a deal.

I’ll do that tomorrow - I am wasted now. :lol:

<edit>

Should I put it in a separate ‘codeception’ folder in tests?

I see elsewhere that for unit tests, the Yii unit tests is preferred over Codeception’s unit tests?

Well, yes, as for me, my folders structure is like that:

tests/

 codeception/  #all codecepiton tests goes here (codecept.phar bootstrap command)


 functional/   #some end-to-end tests with behat by itself


 unit/         #some unit-tests with phpunit

I also think that maybe you can use PhpBrowser it set more request headers and other params because it involves server, for now i am not using Yii1 module and switched to PhpBrowser for functional tests because of some problems with cyrillic and not-standart symbols in Yii1 module. PhpBrowser also as fast as tests with symfony browser kit with Yii1 module.

@jacmoe:

I install codeception via, guess what, composer, then it is placed into ./vendor/bin

I also used the global installation, but had some path issues there.

I briefly toyed with the idea of using composer, but … you know, it’s just a simple wget and that’s it. :lol:

I gave up, actually.

I accidentally ran the sample code for Yii as acceptance test and it gave me an OK, even though none of the tests were actually true.

And then I ran into db issues, etc.

But might tackle it again.

The documentation is really scarce, and assumes a lot of things (like prior exposure to Codeception, which is silly, actually), I also looked at your setup, but it didn’t work. Mainly due to db failures…

I see that you are using a dump.sql file?

I might try that.

Does it work against MySQL?

I am using fixtures in Yii, but that doesn’t seem to work with Codeception.

I will probably use a data mock library/tool and generate a test db.

One last thing: do you need to set up the PHP 5.4 browser? From php.ini, I mean?

@Ragazzo:

I’ve heard that you are writing a survival guide.

That sounds great. ;)

I also see that you wrote some helpers for Codeception - like login, etc. Looks like it could be useful.

Any license on those things?

I am not using the dump.sql file, but I think it has to be defined in the config.

I use migrations to setup the test db, although they were not created for that purpose.

But for the details you’ve to talk to @Ragazzo.

I will put a random db dump in there - thanks for the hint.

((Actually, I will put a dump of the real db, sans data))

Migrations sounds like a great idea!

Was this question for me or Ragazzo? … if it was for me, all stuff I publish on github is BSD licensed.

Question was for you, of course. Thanks. :)

I will ask more later when I have un-confused myself.

You can use them with Codeception only in phpunit tests, so like




MyCodeceptionYiiPhpunitTest extends CDbTestCase

{

}



About article, yes, i’ve finished it yesterday, it is now up to DavertMik to make maybe some markup editions or smth. else. Article mainly about some codeception features (CEST classes), my “vision” of BDD and differences between acceptance and functional tests, difference between Behat+Mink and Codeception and why do i prefer Codeception over Behat+Mink, and about using Codeception with CI Jenkins (basically through phpunit Jenkins plugin). So whole article is divided in this 3 parts.

Also, @schmunk can i ask you (if you of course will have time) about maybe writing article or some brief-look of codeception too?)) I mean that if someone using codeception feel free to share with community your experience)

Also if that article will be interested for users, maybe i will write one more about codeception event-handling and groups(similar to tags in behat). For now afaik DavertMik writing code for "groups" feature.

@Ragazzo: For sure you can ask, but … I am like a testing noob, can’t really write an article about codeception ;) and I really don’t have the time at the moment. Sorry.

Yes, time is that we all need)) ok, hope you like codeception and write more tests with it ;)

Well, guys there is a first of three part of that article is now available, thanks to DavertMik)

http://codeception.com/05-06-2013/specification-testing-coparison.html

Please feel free to comment, and maybe add some suggestions.

Hi guys, so after new Codeception release 1.6.1 , second part of the article was released, it contents some recipes on how to use new CEST classes formats and some differences between CESTs and CEPTs.

http://codeception.com/05-11-2013/playing-with-cests.html

Also pay attention to recipes that was written by davertMik http://codeception.com/docs/07-AdvancedUsage . It also contents new features overview, such like groups.

So, last chapter (3 of 3) of my recipe-article is available on Codeception site, some useful tips and tricks:

http://codeception.com/05-24-2013/jenkins-ci-practice.html

Thanks for support on github too ;)

Hi,

I’m having problems with the autoloader. If I run a suite of tests individually (eg unit or functional) no problems, but if I try to run all tests for the project then I run into problems with loading the modules.

It seems that it pre-loads all modules before running any tests. It loads the functional test modules first which includes Yii1, then it loads the unit test modules but because Yii1 has included Yii, it tries loading through YiiBase::autoload which then cannot find ‘[yii base path]/../../Codeception/Modules/Yii1.php’ for example.

Any ideas on what I’m doing wrong?

Bogsey, sorry for the late answer, yes seems like problems in autoloaders, anyway i suggest for Yii1 functional tests use PhpBrowser and for acceptance WebDriver, there were some problems due Yii1 architecture, good to know that they are solved in Yii2.

Also you and other developers can help us to test Yii2 and Codeception integration for yii2-advanced/yii2-basic boilerplates. See this PR for comments/suggestions:

Thank you and all yii developers that help Codeception :)