Yii Codeception Module
#1
Posted 15 January 2013 - 12:49 PM
#2
Posted 23 January 2013 - 04:46 PM
#3
Posted 08 February 2013 - 06:39 PM
http://codeception.c...tion-1-5-3.html
#4
Posted 21 February 2013 - 09:26 AM
Ragazzo, on 08 February 2013 - 06:39 PM, said:
http://codeception.c...tion-1-5-3.html
Hi, that's nice that you interested in integration codeception to yii. Codeception is looking very nice and promising. I also decided to play/try it but have some problems.
First of all what is
public function setHeaders()
{
$this->_headers = Yii::app()->request->getAllHeaders();
}
Does CHttpRequest have getAllHeaders ?
And what about unit tests? In order to load yii enviroment I need to create Yii application again in _unit/bootstrap and in this case I got exception from YiiBase
throw new CException(Yii::t('yii','Yii application can only be created once.'));
So for now I have to override base CWebApplication class by mine and check if Yii::app() then do not initialize it again.
#5
Posted 22 February 2013 - 12:22 AM
#6
Posted 22 February 2013 - 08:09 AM
Look. At first in order to use your module for functional and unit tests I added it in functional.suite and unit.suite config files
modules:
enabled: [..., Yii1]
So therefore I initialize and include Codeception\Module\Yii1 2 times.
$this->appSettings = require_once($this->config['appPath']); //get application settings in the entry script
$this->_appConfig = require_once($this->appSettings['config']);
when I include it next time require_once return null and it didn't work. Also I need to add Yii::setApplication(null); as you do in Codeception\Util\Connector\Yii1
public function _initialize()
{
$this->appSettings = require($this->config['appPath']); //get application settings in the entry script
$this->_appConfig = require($this->appSettings['config']);
$_SERVER['SCRIPT_NAME'] = str_replace('http://localhost','',$this->config['url']);
$_SERVER['SCRIPT_FILENAME'] = $this->config['appPath'];
Yii::setApplication(null);
Yii::createApplication($this->appSettings['class'],$this->_appConfig);
}
Now as for Codeception\Util\Connector\Yii1 yep when I changed request class it helped. But still required additional changes. Look inside
public function doRequest($request)
For instance I have uri http://mydomain.local/post/3
First of all
$uri = str_replace('http://localhost','',$request->getUri());
$scriptName = str_replace('http://localhost','',$this->url);
What is localhost, I bet this is not correct or useless. I briefly scan the code perhaps localhost was set in
Symfony\Component\BrowserKit\Client as default. But you have to config it somehow. And definitely localhost has no relation to scriptname. But ok you can change config value and this will work.
But take a look in
if (strpos($uri,$scriptName) === false)
$uri = $scriptName.$queryString;
this is incorrect.
At this point for my example uri I have $uri = 'post/3' and $scriptName = 'index-test.php' and finally for all pages my $uri = 'index-test.php'
Please review my changes and update module.
#7
Posted 22 February 2013 - 05:23 PM
#8
Posted 03 March 2013 - 10:39 AM
#9
Posted 25 March 2013 - 04:42 PM
#10
Posted 07 April 2013 - 10:37 AM
>php codecept.phar --steps --defer-flush run functional IndexCept.php
Also feel free to ask some questions or submit bug-issues or PR in codeception repo about Yii1 module, your help is really appreciated).
#11
Posted 16 April 2013 - 03:39 AM
first, thanks for your work and excuse me if I start asking silly or provoking questions
I got similar problems like radzserg when using your module. Why did you change the index-test.php file? Like returning an array instead of creating the webapp.
Wouldn't it be better to specify the application class and config in the Yii1 module configuration and then initialize the app with these settings in the module?
And why do you need the module at all, what are your use-cases? - I asking just because it runs fine for me without the module. But I had to include the PhpBrowser module for my functional tests, is this the "slow" stuff? I still don't fully understand et the difference between acceptance and functional tests.
Best regards,
schmunk
PS: On the codeception page it states, that Codeception is the first testing suite for Yii, that's not really true, Yii always ships with a test folder and corresponding configs.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#12
Posted 16 April 2013 - 04:12 AM
Quote
I am not from Italia, hm)
Quote
me too...)
Quote
Wouldn't it be better to specify the application class and config in the Yii1 module configuration and then initialize the app with these settings in the module?
Well, main reason was that module must be easy-install with little config params, and some developers also has different settings in "index.php" entry scripts, so if just put only config and app class in Yii1 module config it will be wrong because some sttings in entry scripts will not be applied.
Quote
yes, correct, module was designed and written about 3 months ago so in that time functional tests were tests that can be run without server only through symfony browser-kit, codeception works fine through borwser-kit with symfony2 integrations as i know and with Kohana/Zend integrations too, so module for Yii1 was created with those reasons.
Quote
right, i also use PhpBrowser for functional tests, it is not so fast as use only integration with browser-kit, but it is faster than selenium tests. So you are correct here to use it for functional tests.
Quote
well the main difference is that acceptance tests do not know anything about application inner code (if we talking about functional tests you can use for them also some modules like FileSystem). So the main difference on testing web-pages is that selenium tests are very slow, and phpbrowser test are much faster, thats why you prefer phpbrowser for functional tests to cover some basic functionality, and some functionality that not covered by functional tests (with phpbrowser)will be covered with acceptance tests (with Selenium2). As for me my functional tests (lets say 10 of them, differen tests, some of them of course CRUD-tests) can run in 50 sec. when acceptance tests will take a 4-5 minute at least.
BTW. the difference beetwen new Cests-forman and Cepts is that Cests are more like phpunit-selenium tests i think, in Cests you have _before/_after/_failed methods to manage your fixtures or smth. else, and cepts are only flat-files scenarios, so when u test some CRUD-functionality you can write 1 long cept, or you can use new Cest format, with same verbose level and user (TestGuy\WebGuy) and split each of (CRUD) in separate method.
Quote
Looks like some misunderstanding, ofcourse Yii has out-of-the-box support for phpunit tests, can you please point where is this written will change it of course.
#13
Posted 28 April 2013 - 01:15 AM
About the statement, it's here:
Quote
By itself Yii framework does not have an engine for functional testing. So Codeception is the first and only functional testing framework for Yii.
http://codeception.c...tionalTests#Yii
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#14
Posted 04 May 2013 - 05:22 PM
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 You need to use CodeceptionHttpRequest from plugins directory (plugins\frameworks\yii\web),
..
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).
#15
Posted 04 May 2013 - 05:24 PM
vendor/bin/codecept bootstrap tests/codeception
I will do that tomorrow.
#16
Posted 04 May 2013 - 06:33 PM
php vendors/codecept.phar bootstrapin 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.
#17
Posted 04 May 2013 - 06:37 PM
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.
<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?
#18
Posted 05 May 2013 - 03:38 AM
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.
#19
Posted 05 May 2013 - 06:48 PM
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.
Fork on github
Follow phundament on Twitter
DevSystem: Mac OS X 10.7 - PHP 5.3 - Apache2 - Yii 1.1 / trunk - Firefox or Safari
#20
Posted 06 May 2013 - 09:21 AM
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.

Help












