Last active
February 21, 2017 10:23
-
-
Save gskema/db9bbfdcb492ff9d444b023693056568 to your computer and use it in GitHub Desktop.
PHPUnit object method testing pattern/snippet/boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Object1 | |
{ | |
protected $property1; | |
public function __construct($property1) | |
{ | |
$this->property1 = $property1; | |
} | |
public function setProperty1($property1) | |
{ | |
$this->property1 = $property1; | |
} | |
} | |
class Object1Test extends \PHPUnit_Framework_TestCase | |
{ | |
public function dataTestSetProperty1() | |
{ | |
$cases = []; | |
// Case #0 | |
$cases[] = [ | |
new Object1('value1'), | |
['value2'], | |
new Object1('value2') | |
]; | |
} | |
/** | |
* @dataProvider dataTestSetProperty1 | |
*/ | |
public function testSetProperty1( | |
Object $givenObject, | |
array $givenArguments, | |
Object $expectedObject | |
) { | |
$givenObject->setProperty1(...$givenArguments); | |
$actualObject = $givenObject; | |
$this->assertEquals($expectedObject, $actualObject); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment