[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