Skip to content

Instantly share code, notes, and snippets.

@JoelLarson
Forked from emeraldinspirations/sample.php
Last active August 15, 2017 03:09
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 JoelLarson/d762b13df87ebbd2b4e54a9a4535bd40 to your computer and use it in GitHub Desktop.
Save JoelLarson/d762b13df87ebbd2b4e54a9a4535bd40 to your computer and use it in GitHub Desktop.
Is random in test always bad?
<?php
class Demo
{
protected $Property;
public function getProperty()
{
return $this->Property;
}
public function setProperty($Value)
{
$this->Property = $Value;
}
}
class DemoTest extends TestCase
{
public function setUp()
{
$this->demo = new Demo();
}
public function testInvalidProperty() {
try {
$this->demo->setProperty(null);
} catch (\DomainException $e) {
return;
}
$this->throw('Demo property can not be set to null');
}
public function testProperty()
{
$this->demo->setProperty("demo_property");
$this->assertProperty($this->demo, "demo_property");
}
public function testComplicatedProperty()
{
$this->demo->setProperty(array('hello' => 'world'));
$this->assertProperty($this->demo, array('hello' => 'world'));
}
private function assertProperty($demo, $expected) {
$this->assertEquals($demo->getProperty(), $expected);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment