-
Notifications
You must be signed in to change notification settings - Fork 4
/
DummyObjectTest.php
68 lines (58 loc) · 1.88 KB
/
DummyObjectTest.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
59
60
61
62
63
64
65
66
67
68
<?php
class DummyObjectTest extends PHPUnit_Framework_TestCase
{
/**
* The Test Method names describe the different ways to produce
* a Dummy Object (or just a Dummy value).
*/
public function testNullOrStringsCanBeUsedAsADummyIfThereAreNoTypeHints()
{
$sut = new MostDynamicSut(null);
$sut = new MostDynamicSut('this should not be called');
}
public function testNullCanBeUsedAsADummyIfItsTheDefaultForTypeHint()
{
// I prefer an explicit parameter; also there may be other parameters after that
$sut = new TypeHintedWithDefaultSut(null);
}
public function testAnInlineClassCanBeUsedToInstantiateADummyObject()
{
$sut = new FullyDefensiveSut(new DummyIterator);
}
public function testADynamicallyGeneratedDummyObjectCanBeBuiltByPHPUnit()
{
$dummy = $this->getMock('Iterator');
$sut = new FullyDefensiveSut($dummy);
}
public function testPHPUnitCanOverrideTheConstructorOfADummy()
{
$dummy = $this->getMockBuilder('ArrayIterator')
->disableOriginalConstructor()
->getMock();
$sut = new FullyDefensiveSut($dummy);
}
public function testPHPUnitCanCheckThatTheDummyMethodsAreNeverCalled()
{
// often if someone calls it, lack of return value (null) causes explosion anyway.but if it's a void...
$dummy = $this->getMock('Iterator');
$dummy->expects($this->never())
->method('current');
$sut = new FullyDefensiveSut($dummy);
}
}
class MostDynamicSut
{
public function __construct($iterator) { }
}
class TypeHintedWithDefaultSut
{
public function __construct(Iterator $iterator = null) { }
}
class FullyDefensiveSut
{
public function __construct(Iterator $iterator) { }
}
class DummyIterator extends ArrayIterator
{
public function __construct() {}
}