Yii2 tests: Codeception configuration and first test

Author: Rafal Marguzewicz
Published:
Categories: Yii2
Tags:


codeception logoThis tutorial is for Yii2 Basic Application Template. Yii2 especially the version 2.0.10+ help to begin tests with codeception. If Yii2 and codeception are install, we can compile and run default tests with command: (root path of application).

codecept build
codecept run

And we will see this screen:
yii2 test unit functional

Default tests of Yii2 check correct opening contact page whether page contact (site/contact), fill out the contact form does not generate unexpected problems etc.

For easy use codeception with Yii2, i propose to do a few things:

  1. install codeception globally and locally
  2. set the PATH, or an alias for codeception bin folder
  3. check whether codeception has a properly configured files

1. Install codeception globally and locally by composer

It is possible that during the installation Yii2 also codeception is installed, you can check the file composer.json your application, section require-dev.

"require-dev": {
        "codeception/base": "^2.x.x",
        "codeception/verify": "~0.x.x",
        "codeception/specify": "~0.x.x"
    },

If you do not have, install this command

composer require "codeception/codeception=2.2.*" "codeception/specify=*" "codeception/verify=*"

To use short commands type codecept run I recommend to install codeception globally

composer global require "codeception/codeception=2.2.*" "codeception/specify=*" "codeception/verify=*"

Now you can use command

~/.composer/vendor/bin/codecept

codeception composer

2. set the PATH, or an alias for codeception

Both can do in the same file /home/<user>/.bashrc
PATH method
export PATH="$PATH:~/.config/composer/vendor/bin" (or ~/.composer/vendor/bin)
alias method
alias codecept="~/.config/composer/vendor/bin/codecept"

After reload bash, short command and globally are avaiable:


codecept bootstrap
codecept build
codecept run

In case if you have another system, see how to add a new PATH environment variable.

3. Codeception config files

You can find config file in /config/test.php and /config/test-db.php

Yii2 tests: Codeception configuration and first test
3 / 4 votes


Your email address will not be published. Required fields are marked *

Name *
Email *

Read previous post:
Redirect http to https and WWW to non-WWW NGINX Yii2 WordPress

Full example redirect all HTTP requests to HTTPS and WWW to non-WWW with Nginx. You can use this for to...

Close