6.1. Codeception Basics - shinokada/php_notes GitHub Wiki
Install codeception
Install composer
Find latest package from Packagist
Create composer.json
cd path/to/dir
vim composer.json
// composer.json
{
"require":{
},
"require-dev":{
"codeception/codeception": "2.1.*@dev"
}
}
In the terminal run composer install --dev. This will add a director vendor with all files and directories.
You can add an alias
t="vendor/bin/codecept"
Or add vendor/bin/ to path.
Run bootstrap in the terminal.
codecept bootstrap
This will creat a test directory with files and directories. Notice directory, acceptance, funcional and unit and files, acceptance.suite.yml, functional.suite.yml and unit.suite.yml.
In tests/acceptance.suite.yml, set URL.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser
- AcceptanceHelper
config:
PhpBrowser:
url: 'http://localhost/codeception-test/'
In terminal
codecept generate:cept acceptance HomePage //createing acceptance test called HomePage
This will create a file acceptance/HomePageCept.php
Add the following.
<?php
$I = new WebGuy($scenario);
$I->wantTo('verify that the home page welcomes me');
$I->amOnPage('/');
$I->see('Welcome');
On the terminal,
codecept run
Run individual tests.
codecept run acceptance
codecept run functional
codecept run unit
How to run a php in any directory.
// terminal
php -S localhost:8888
// change tests/acceptance.suite.yml
url: 'http://localhost:8888/'
If you want to see welcome with h1 tag, change in acceptance?homePageCept.php
$I->see('Welcome','h1');