-
-
Save tommcfarlin/248c7741273e6be414c1f98c11085fe7 to your computer and use it in GitHub Desktop.
[PHP] Writing Unit Tests with PHPUnit, Part 1: The Set Up
This file contains 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 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... | |
} |
This file contains 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 | |
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