-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonSpec.php
77 lines (63 loc) · 1.74 KB
/
PersonSpec.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
<?php
declare(strict_types=1);
namespace spec\App;
use App\Person;
use PhpSpec\ObjectBehavior;
use Sushi\ValueObject\Exceptions\ValueObjectException;
class PersonSpec extends ObjectBehavior
{
private const NAME = 'foo';
private const AGE = 30;
public function let(): void
{
$this->beConstructedWith(self::NAME, self::AGE);
}
public function it_is_initializable()
{
$this->shouldHaveType(Person::class);
}
public function it_contains_data(): void
{
$this->name->shouldEqual(self::NAME);
$this->age->shouldEqual(self::AGE);
}
public function its_props_are_ro(): void
{
try {
$this->name = 'bar';
} catch (\Throwable $e) {
}
$this->name->shouldEqual(self::NAME);
}
public function it_has_set_method(): void
{
$newPerson = $this->set(age: 40);
$newPerson->age->shouldEqual(40);
$this->age->shouldEqual(self::AGE);
}
public function it_has_the_same_keys(): void
{
$this
->shouldThrow(ValueObjectException::class)
->during('set', ['otherName' => 'foo']);
}
public function it_can_be_compared(): void
{
$person1 = new Person('Thor', 25);
$person2 = new Person(self::NAME, self::AGE);
$this->isEqual($person1)->shouldEqual(false);
$this->isEqual($person2)->shouldEqual(true);
}
public function it_is_an_adult_person(): void
{
$this
->shouldThrow(\Throwable::class)
->during('set', ['age' => 12]);
}
public function its_name_is_not_too_short(): void
{
$this
->shouldThrow(\Throwable::class)
->during('set', ['name' => 'a']);
}
}