1. Go to this page and download the library: Download codeception/specify library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
codeception / specify example snippets
public function testValidation()
{
$this->assertInstanceOf('Model', $this->user);
$this->specify('username is his->specify('username is too long', function() {
$this->user->username = 'toolooooongnaaaaaaameeee';
$this->assertFalse($this->user->validate(['username']));
});
}
public function testValidation()
{
$this->describe('user', function () {
$this->it('should have a name', function() {
$this->user->username = null;
$this->assertFalse($this->user->validate(['username']));
});
});
// you can use chained methods for better readability:
$this->describe('user')
->should('be ok with valid name', function() {
$this->user->username = 'davert';
$this->assertTrue($this->user->validate(['username']));
})
->shouldNot('have long name', function() {
$this->user->username = 'toolooooongnaaaaaaameeee';
$this->assertFalse($this->user->validate(['username']));
})
// empty codeblocks are marked as Incomplete tests
->it('should be ok with valid name')
;
}
public function testValidation()
{
$this->specify('username is too long', function() {
$this->user->username = 'toolooooongnaaaaaaameeee';
expect_not($this->user->validate(['username']));
});
$this->specify('username is ok', function() {
$this->user->username = 'davert';
expect_that($this->user->validate(['username']));
});
}
class UserTest extends PHPUnit\Framework\TestCase
{
use Codeception\Specify;
/** @specify */
protected $user; // is cloned inside specify blocks
public function setUp(): void
{
$this->user = new User;
}
public function testValidation()
{
$this->user->name = 'davert';
$this->specify('i can change my name', function() {
$this->user->name = 'jon';
$this->assertEquals('jon', $this->user->name);
});
// user name is 'davert' again
$this->assertEquals('davert', $this->user->name);
}
}
$this->specify('failing but test goes on', function() {
$this->fail('bye');
});
$this->assertTrue(true);
// Assertions: 2, Failures: 1
$config = $this->createMock(Config::class);
$config->expects($this->once())->method('init');
$config->init();
// success: $config->init() was executed
$this->specify('this should not fail', function () {
$config = $this->createMock(Config::class);
$config->expects($this->never())->method('init')->willReturn(null);
// success: $config->init() is never executed
});