Commands
The project comes with its own set of custom Codeception commands.
The commands provide functionalities to quickly scaffold different types of tests. Any other codecept command remains intact and available.

Adding the commands to an existing project

The commands are added to the main Codeception configuration file, codeception.yml, when scaffolding a project via the codecept init wp-browser command.
They can be added to any existing project adding, or editing, the commands section of the configuration file:
1
extensions:
2
commands:
3
- "Codeception\\Command\\GenerateWPUnit"
4
- "Codeception\\Command\\GenerateWPRestApi"
5
- "Codeception\\Command\\GenerateWPRestController"
6
- "Codeception\\Command\\GenerateWPRestPostTypeController"
7
- "Codeception\\Command\\GenerateWPAjax"
8
- "Codeception\\Command\\GenerateWPCanonical"
9
- "Codeception\\Command\\GenerateWPXMLRPC"
Copied!

Generation commands

The library provides commands to quickly scaffold integration test cases for specific types of WordPress components, see levels of testing for more information.
The tests are almost identical to the ones you could write in a PHPUnit based Core suite with the exception of extending the Codeception\TestCase\WPTestCase test case.

generate:wpunit

Generates a test case extending the \Codeception\TestCase\WPTestCase class using the
1
codecept generate:wpunit suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wprest

Generates a test case extending the \Codeception\TestCase\WPRestApiTestCase class using the
1
codecept generate:wprest suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPRestApiTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wprestcontroller

Generates a test case extending the \Codeception\TestCase\WPRestControllerTestCase class using the
1
codecept generate:wprest suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPRestControllerTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wprestposttypecontroller

Generates a test case extending the \Codeception\TestCase\WPRestPostTypeControllerTestCase class using the
1
codecept generate:wprest suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPRestPostTypeControllerTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wpajax

Generates a test case extending the \Codeception\TestCase\WPAjaxTestCase class using the
1
codecept generate:wpajax suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPAjaxTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wpxmlrpc

Generates a test case extending the \Codeception\TestCase\WPXMLRPCTestCase class using the
1
codecept generate:wpxmlrpc suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPXMLRPCTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!

generate:wpcanonical

Generates a test case extending the \Codeception\TestCase\WPCanonicalTestCase class using the
1
codecept generate:wpcanonical suite SomeClass
Copied!
The command will generate a skeleton test case like
1
<?php
2
3
class SomeClassTest extends \Codeception\TestCase\WPCanonicalTestCase
4
{
5
public function setUp()
6
{
7
parent::setUp();
8
}
9
10
public function tearDown()
11
{
12
parent::tearDown();
13
}
14
15
// tests
16
public function testMe()
17
{
18
}
19
20
}
Copied!
Last modified 2yr ago