-
Notifications
You must be signed in to change notification settings - Fork 4
/
LiteralValueTest.php
58 lines (53 loc) · 1.87 KB
/
LiteralValueTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class LiteralValueTest extends PHPUnit_Framework_TestCase
{
const POSITIVE = 1;
const NEGATIVE = -1;
public function setUp()
{
$this->sut = new SUT();
}
/**
* The most basic of the tests.
*/
public function testALiteralValueIsUsedForExpectationAndInput()
{
$this->assertEquals(5, $this->sut->sum(2, 3));
}
/**
* If we change the result from 1 and -1 to "+1" or to an object,
* we will have a way to quickly change this test. It's normal refactoring.
*/
public function testASymbolicConstantIsExtractedToAvoidDuplicatingAValue()
{
$this->assertEquals(self::POSITIVE, $this->sut->sign(0));
$this->assertEquals(self::POSITIVE, $this->sut->sign(1));
$this->assertEquals(self::POSITIVE, $this->sut->sign(2));
$this->assertEquals(self::POSITIVE, $this->sut->sign(10));
$this->assertEquals(self::NEGATIVE, $this->sut->sign(-1));
$this->assertEquals(self::NEGATIVE, $this->sut->sign(-2));
$this->assertEquals(self::NEGATIVE, $this->sut->sign(-10));
}
/**
* Describing cars that have to be deleted as old and rusty is simpler
* for the mind RAM of the reader that using A, B and C. Choosing
* Self-Describing Values is an art that I have only started exploring.
*/
public function testASelfDescribingValueIsUsedToMakeTheTestMoreReadable()
{
$this->sut->addVehicle('Old rusty car', 1980);
$this->sut->addVehicle('Bus', 2000);
$this->sut->addVehicle('Ferrari', 2010);
$this->sut->deleteVehiclesUpTo(1990);
// another Literal Value
$this->assertEquals(2, $this->sut->getVehiclesCount());
}
}
/**
* Since we only want to describe the test code in this sample,
* we use this catch-all SUT which accepts any call.
*/
class SUT
{
public function __call($method, $arguments) {}
}