-
Notifications
You must be signed in to change notification settings - Fork 6
/
ModelTest.php
97 lines (82 loc) · 2.76 KB
/
ModelTest.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace Magomogo\Persisted\Test\Person;
use Mockery as m;
use Magomogo\Persisted\Test\ObjectMother;
class ModelTest extends \PHPUnit_Framework_TestCase
{
public function testCreatingANewPerson()
{
$person = new Model(new Properties);
}
public function testReadItsPropertiesToImplementSomeBusinessLogic()
{
$this->assertEquals(
'Mr. John Doe',
self::person()->politeTitle()
);
}
public function testStateCanBeChangedByAMessage()
{
$person = self::person();
$person->phoneNumberIsChanged('335-65-66');
$this->assertContains('Phone: 335-65-66', $person->contactInfo());
}
public function testHasAccessToCreditCardModel()
{
$this->assertEquals('VISA, 9500 **** **** 0001', self::person()->paymentInfo());
}
public function testBehaviorWhenNoCreditCard()
{
$this->assertNull(self::personWithoutCreditCard()->paymentInfo());
$this->assertFalse(self::personWithoutCreditCard()->ableToPay());
}
public function testCanBeSavedIntoAPropertyContainer()
{
$container = m::mock();
$container->shouldReceive('saveProperties')
->with(m::on(function($p) use ($container) {$p->persisted(15, $container); return true;}))
->andReturnUsing(function($p) {return $p;})
->once();
$container->shouldIgnoreMissing();
$id = self::person()->save($container);
$this->assertEquals(15, $id);
}
public function testCanBeTaggedWithAKeymarker()
{
$person = self::person();
$person->tag(ObjectMother\Keymarker::friend());
$person->tag(ObjectMother\Keymarker::IT());
$this->assertEquals('Friend, IT', $person->taggedAs());
}
//----------------------------------------------------------------------------------------------------------------------
private static function person()
{
return new Model(self::johnDoeProperties());
}
private static function johnDoeProperties()
{
return new Properties(
array(
'title' => 'Mr.',
'firstName' => 'John',
'lastName' => 'Doe',
'email' => '[email protected]',
'phone' => '+7923-117-2801',
'creditCard' => ObjectMother\CreditCard::datatransTesting()
)
);
}
private static function personWithoutCreditCard()
{
return new Model(new Properties(
array(
'title' => 'Mr.',
'firstName' => 'John',
'lastName' => 'Doe',
'email' => '[email protected]',
'phone' => '+7923-117-2801',
'creditCard' => null
)
));
}
}