Name: codeception
Owner: CakePHP
Description: CakePHP module for Codeception
Created: 2015-02-09 15:32:47.0
Updated: 2018-04-11 05:51:29.0
Pushed: 2018-03-14 01:37:06.0
Size: 208
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A codeception module to test your CakePHP 3 powered application. Using Codeception with CakePHP opens up a whole new set of testing capabilities.
(i.e. browser-based workflow tests)
(i.e. direct, internal method tests)
From a CakePHP application, run the following from the command-line:
mposer require --dev cakephp/codeception:dev-master && composer run-script post-install-cmd
If you are developing a plugin, add the post-install script to your composer.json
first:
"scripts": {
"post-install-cmd": "Cake\\Codeception\\Console\\Installer::customizeCodeceptionBinary"
}
Once installed, you can now run bootstrap
which will create all the codeception required files
in your application:
ndor/bin/codecept bootstrap
This creates the following files/folders in your app
directory:
codeception.yml
src
??? TestSuite
??? Codeception
??? AcceptanceTester.php
??? FunctionalTester.php
??? UnitTester.php
??? Helper
? ??? Acceptance.php
? ??? Functional.php
? ??? Unit.php
??? _generated
??? .gitignore
tests
??? Acceptance.suite.yml
??? Functional.suite.yml
??? Unit.suite.yml
??? Acceptance
? ??? bootstrap.php
??? Fixture
? ??? dump.sql
??? Functional
? ??? bootstrap.php
??? Unit
??? bootstrap.php
As you might have noticed, the CakePHP implementation differs in a couple things:
Functional
vs. functional
)bootstrap.php
, no underscore prefix (vs. _bootstrap.php
)src/TestSuite/Codeception
for custom modules (helpers) (vs. tests/_helpers
)tmp/tests
to store logs (vs. tests/_logs
)tests/Fixture
to fixture data (vs. tests/_data
)tests/Envs
to fixture data (vs. tests/_envs
).gitignore
to never track auto-generated filescodecept
binaryTo better understand how Codeception tests work, please check the official documentation.
p
new FunctionalTester($scenario);
wantTo('ensure that adding a bookmark works');
amOnPage('/bookmarks/add');
see('Submit');
submitForm('#add', [
'title' => 'First bookmark',
seeInSession([
'Flash'
…
seeInConfig($key, $value = null)
seeInConfig('App.name'); // checks only that the key exists
seeInConfig('App.name', 'CakePHP');
seeInConfig(['App.name' => 'CakePHP']);
dontSeeInConfig($key, $value = null)
dontSeeInConfig('App.name'); // checks only that the key does not exist
dontSeeInConfig('App.name', 'CakePHP');
dontSeeInConfig(['App.name' => 'CakePHP']);
haveRecord($model, $data = [])
This is useful when you need a record for just one test (temporary fixture). It does not assert anything and returns the inserted record's ID.
haveRecord('users', ['email' => 'jadb@cakephp.org', 'username' => 'jadb']);
grabRecord($model, $conditions = [])
This is a wrapper around the Cake\ORM\Table::find('first')
method.
grabRecord('users', ['id' => '1']);
seeRecord($model, $conditions = [])
This checks that the requested record does exist in the database.
seeRecord('users', ['username' => 'jadb']);
dontSeeRecord($model, $conditions = [])
This checks that the request record does not exist in the database.
dontSeeRecord('users', ['email' => 'jadb@cakephp.org']);
…
In your Cest
test case, write $fixutures
property:
s AwesomeCest
public $fixtures = [
'app.Users',
'app.Posts',
];
// ...
You can use $autoFixtures
, $dropTables
property, and loadFixtures()
method:
s AwesomeCest
public $autoFixtures = false;
public $dropTables = false;
public $fixtures = [
'app.Users',
'app.Posts',
];
public function tryYourSenario($I)
{
// load fixtures manually
$I->loadFixtures('Users');
// ...
}
expectedCakePHPVersion($ver, $operator = 'ge')
expectedCakePHPVersion('3.0.4');
amOnRoute($route, $params = [])
All the below forms are equivalent:
amOnRoute(['controller' => 'Posts', 'action' => 'add']);
amOnRoute('addPost'); // assuming there is a route named `addPost`
amOnAction($action, $params = [])
All the below forms are equivalent:
amOnAction('Posts@add');
amOnAction('Posts.add');
amOnAction('PostsController@add');
amOnAction('PostsController.add');
amOnAction('posts@add');
amOnAction('posts.add');
seeCurrentRouteIs($route, $params = [])
All the below forms are equivalent:
seeCurrentRouteIs(['controller' => 'Posts', 'action' => 'add']);
seeCurrentRouteIs('addPost'); // assuming there is a route named `addPost`
seeCurrentActionIs($action, $params = [])
All the below forms are equivalent:
seeCurrentActionIs('Posts@add');
seeCurrentActionIs('Posts.add');
seeCurrentActionIs('PostsController@add');
seeCurrentActionIs('PostsController.add');
seeCurrentActionIs('posts@add');
seeCurrentActionIs('posts.add');
haveInSession($key, $value = null)
haveInSession('redirect', Router::url(['_name' => 'dashboard']));
haveInSession(['redirect' => Router::url(['_name' => 'dashboard'])]);
seeInSession($key, $value = null)
seeInSession('redirect'); // only checks the key exists.
seeInSession('redirect', Router::url(['_name' => 'dashboard']));
seeInSession(['redirect', Router::url(['_name' => 'dashboard'])]);
dontSeeInSession($key, $value = null)
dontSeeInSession('redirect'); // only checks the key does not exist.
dontSeeInSession('redirect', Router::url(['_name' => 'dashboard']));
dontSeeInSession(['redirect', Router::url(['_name' => 'dashboard'])]);
…