Tests Yii2

Hi, I created a new project Yii2 advanced template. On the start I have folder tests who holds basic tests frontpage site. e.g login page, homeCept, aboutCept etc.

I have now two questions:

1 How i can run this tests ?

2 Do i need download through composer package codeception? "codeception/codeception": "2.0.*" ?

3 What’s in folder vendro/bin in codeception file? If I will execute command “codeception bootstrap”, it will create new folder tests under vendor/bin… Whose folder tests i have to use to my tests?

Hi,

I am as you and trying to figure out how to do testing Yii2. so I share with you what I know so far.

After you install and init Yii2 advance template, and test to make sure the frontend.dev and backend.dev is working. Then to do test

you need to install codeception by




composer global require "codeception/codeception:*"



The command will install codeception globally. Then, you need to add codeception command line to your ‘PATH’ (google on how to it on linux/window) so that you can do ‘codecept’ command without typing the full path.

Then for testing, because you are using yii2 advance template, front end and back end has different tests.

To test front end, you need to go to www/yii-application/tests/codeception/frontend

To test back end, you need to go to www/yii-application/tests/codeception/backend

from there, you can




codecept build

codecept run # this will run all your acceptance, functional and unit test suite



For your reference, read Codeception quick start (http://codeception.com/quickstart#.VroyDFgrKUk) and Codeception getting start (http://codeception.com/docs/02-GettingStarted#.VroyOVgrKUk) it tells you how to run all suite, 1 suite or action in 1 suite

it’s not working. I use global composer, but if I enter app/tests/codeception/frontend and try type codecept bulid or codecept run, my console tell me, that not recognize codecept. It command working only if I’m in vendor/bin folder becouse there is codecept file.

work here, but he creates a new folder tests… i nothing understand with this. Now i have 3 folders tests

under app/tests

under vendor/bin/tests

under vendor/codecetpion/codeception/tests…

You need to add the path to the global composer bin directory to your PATH environment variable so that your operating system can resolve it.

Cna you take me example those variable? i have…

Cuurent show me if i type composer global status my COMPOSER_HOME variable patch

C:\Users\YourUserName\AppData\Roaming\Composer\vendor\codeception\codeception

replace YourUserName with your user name and add the above to PATH variable, then close and open command prompt again

He require c:/.../vendor/bin ;)

Thanks, it working.

one more problem :D

[yii\db\Exception]

SQLSTATE[HY000] [1049] Unknown database ‘yii2_advanced_tests’

Why i get exception after execute codecept run?

because ‘yii2_advanced_tests’ db does not exist. you have to replace it with your database name.

Search ‘yii2_advanced_tests’ in your whole project and replace all occurrences within ‘tests’ directory

Read this tutorial - it may help you http://danaluther.blogspot.ca/2015/12/testing-in-yii-20-with-codeception.html

Thanks, it solve problem :)