Skip to content

Instantly share code, notes, and snippets.

@baileylo
Last active August 29, 2015 13:56
Show Gist options
  • Save baileylo/8945380 to your computer and use it in GitHub Desktop.
Save baileylo/8945380 to your computer and use it in GitHub Desktop.
Thinking about unit tests and how you think about your functions and how you write your tests.
<?php
class Foo
{
private $bar;
public function setBar($bar)
{
$this->bar = $bar;
}
public function getBar()
{
return $this->bar;
}
}
class FooTest extends PHPUnit_Framework_TestCase
{
protected $foo;
public function setUp()
{
$this->foo = new Foo();
}
public function testSetBarUpdatesBarAttribute()
{
$this->foo->setBar('logan');
$this->assertAttributeEquals('logan', 'bar', $this->foo);
}
public function testSetBarSetsReturnValueOfGetBar()
{
$this->foo->setBar('logan');
$this->assertEquals('logan', $this->foo->getBar());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment