, (*1)
PHPUnitWrapper / phpunit-wrapper
PHPUnit wrapper - wraps the functionality of phpunit with easy to use plain & simple English
, (*2)
Note: Your existing standard PHPUnit tests will not fail, they will continue to work fine
, (*3)
Installation via Composer
"require" : {
"EddieJaoude\PHPUnitWrapper" : "0.*"
}
Usage
Instead of extending \PHPUnit_Framework_TestCase
, extend \EddieJaoude\PHPUnitWrapper\Assert
., (*4)
The Assert class extends PHPUnit, therefore you get all the previous functionality & your previous unit tests will not fail., (*5)
Assert Equals
Standard PHPUnit
$this->assertEquals($expected, $actual);
// or with custom message
$this->assertEquals($expected, $actual, $message);
PHPUnit Wrapper
$this->expectedValue('abc')
->equals('abc');
// or with custom message
$this->expectedValue('abc')
->setMessage('Failure, these are not equal!') // optional
->equals('abc');
Assert NOT Equals
Standard PHPUnit
$this->assertNotEquals($expected, $actual, $message);
PHPUnit Wrapper
$this->expectedValue('abc')
->notEquals('abcd');
Contains
Standard PHPUnit
$this->assertContains($needle, $haystack);
// or with custom message
$this->assertContains($needle, $haystack, $message);
PHPUnit Wrapper
$this->expectedValue($needle)
->existsIn($haystack);
$this->expectedValue('b')
->existsIn(
array('a', 'b', 'c')
);
// or with custom message
$this->expectedValue('b')
->setMessage('Failure, does not exist!') // optional
->existsIn(
array('a', 'b', 'c')
);
NOT Contains
Standard PHPUnit
$this->assertNotContains($needle, $haystack);
// or with custom message
$this->assertNotContains($needle, $haystack, $message);
PHPUnit Wrapper
$this->expectedValue($needle)
->notExistsIn($haystack);
$this->expectedValue('b')
->notExistsIn(
array('a', 'c')
);
// or with custom message
$this->expectedValue('b')
->setMessage('Failure, does exist!') // optional
->notExistsIn(
array('a', 'c')
);
Complete usage simple Example
<?php
namespace EddieJaoude\PHPUnitWrapperTest;
use EddieJaoude\PHPUnitWrapper\Assert;
/**
* Class ExampleTest
*
* @package EddieJaoude\PHPUnitWrapperTest
*/
class ExampleTest extends Assert
{
/*
* Example of 'assert' & 'equals'
*/
public function testAssertEquals()
{
$this->expectedValue('abc')
->equals('abc');
}
/*
* Example of 'assert' & 'equals'
*/
public function testAssertNotEquals()
{
$this->expectedValue('abc')
->notEquals('abcd');
}
}
Contribution
Fork, Pull Request - with Tests
& Updated README with examples
please, (*6)
Suggestions / Ideas
Please create an Issue
, (*7)