Testing PHP with Codeception

Post on 13-Apr-2017

81 views 0 download

Transcript of Testing PHP with Codeception

Testing PHP with

Codeception

Test Driven Developmenta Primer

Test before you code.

Tests should be easy to write.

If they’re not easy to write, it’s not the test. It’s the code.

Test Driven Developmenta Primer

Unit test Integration test UI test

TYPES OF TESTS

Codeception

What is Codeception?

Codeception is a PHP testing framework.

What is Codeception?

It has good support for PHP frameworks likeSymphony, Laravel, etc.

#!/bin/sh # Install via composer

composer require "codeception/codeception" alias codecept='./vendor/bin/codecept'

Installation

#!/bin/sh # Install via composer

codecept bootstrap --empty

Setup

// Unit Test Example // ExampleTest.php

<?php public function testUserReturnsRightFullName() { $firstName = “John Paul”; $lastName = “Ada” $fullName = “John Paul Ada”; $user = new User(“John Paul”, “Ada”); $this->assertTrue($user->getFullName() == $fullName);

}

Unit tests

// Acceptance Test Example // WelcomeCept.php

<?php $I = new AcceptanceTester($scenario); $I->wantTo(‘Ensure that home page works.’); $I->amOnPage(‘/‘); $I->see(‘Welcome’);

Acceptance tests

#!/bin/sh # Running codeception

codecept run

Run on LOCAL Run on CI SERVER

Output

fin.