Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-acme-cache.php Secret
Created Mar 29, 2018

Embed
What would you like to do?
[PHP] Writing Unit Tests with PHPUnit, Part 1: The Set Up
<?php
class AcmeCache
{
private $duration;
public function __construct()
{
$this->duration = 43200;
}
public function setDuration($duration)
{
$this->duration = $duration;
}
public function getDuration()
{
return $this->duration;
}
// More cache code omitted...
}
<?php
use PHPUnit\Framework\TestCase;
class AcmeCacheTest extends TestCase
{
protected $cache;
protected function setUp()
{
$this->cache = new AcmeCache();
}
public function testDefaultDuration()
{
$this->assertTrue($this->cache->getDuration() === 43200);
}
public function testNewDuration()
{
$this->cache->setDuration(1000);
$this->assertFalse($this->cache->getDuration() === 43200);
$this->assertTrue($this->cache->getDuration() === 1000);
}
// More to come...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.