Skip to content

Instantly share code, notes, and snippets.

@gskema
Last active February 21, 2017 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gskema/db9bbfdcb492ff9d444b023693056568 to your computer and use it in GitHub Desktop.
Save gskema/db9bbfdcb492ff9d444b023693056568 to your computer and use it in GitHub Desktop.
PHPUnit object method testing pattern/snippet/boilerplate
<?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