|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace spec\Odiseo\SyliusVendorPlugin\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Odiseo\SyliusVendorPlugin\Entity\Vendor; |
|
8
|
|
|
use Odiseo\SyliusVendorPlugin\Entity\VendorInterface; |
|
9
|
|
|
use PhpSpec\ObjectBehavior; |
|
10
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
11
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
12
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
|
13
|
|
|
use Sylius\Component\Resource\Model\SlugAwareInterface; |
|
14
|
|
|
use Sylius\Component\Resource\Model\TimestampableInterface; |
|
15
|
|
|
use Sylius\Component\Resource\Model\ToggleableInterface; |
|
16
|
|
|
use Sylius\Component\Resource\Model\TranslatableInterface; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
|
18
|
|
|
|
|
19
|
|
|
final class VendorSpec extends ObjectBehavior |
|
20
|
|
|
{ |
|
21
|
|
|
function it_is_initializable() |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$this->shouldHaveType(Vendor::class); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
function it_implements_vendor_interface(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->shouldImplement(VendorInterface::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_implements_translatable_interface(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldImplement(TranslatableInterface::class); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_implements_toggleable_interface(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldImplement(ToggleableInterface::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_implements_resource_interface(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldImplement(ResourceInterface::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_implements_slug_aware_interface(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->shouldImplement(SlugAwareInterface::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function it_implements_timestamplable_interface(): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->shouldImplement(TimestampableInterface::class); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
function it_has_no_id_by_default(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->getId()->shouldReturn(null); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function it_has_no_name_by_default(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->getName()->shouldReturn(null); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
function it_is_timestampable(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$dateTime = new \DateTime(); |
|
69
|
|
|
$this->setCreatedAt($dateTime); |
|
|
|
|
|
|
70
|
|
|
$this->getCreatedAt()->shouldReturn($dateTime); |
|
|
|
|
|
|
71
|
|
|
$this->setUpdatedAt($dateTime); |
|
|
|
|
|
|
72
|
|
|
$this->getUpdatedAt()->shouldReturn($dateTime); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
function it_toggles(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->enable(); |
|
|
|
|
|
|
78
|
|
|
$this->isEnabled()->shouldReturn(true); |
|
|
|
|
|
|
79
|
|
|
$this->disable(); |
|
|
|
|
|
|
80
|
|
|
$this->isEnabled()->shouldReturn(false); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
function it_allows_access_via_properties(): void |
|
84
|
|
|
{ |
|
85
|
|
|
$this->setName('Vendor'); |
|
|
|
|
|
|
86
|
|
|
$this->getName()->shouldReturn('Vendor'); |
|
87
|
|
|
$this->setSlug('vendor'); |
|
|
|
|
|
|
88
|
|
|
$this->getSlug()->shouldReturn('vendor'); |
|
|
|
|
|
|
89
|
|
|
$this->setEmail('[email protected]'); |
|
|
|
|
|
|
90
|
|
|
$this->getEmail()->shouldReturn('[email protected]'); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
$file = new File(__DIR__ . '/VendorSpec.php'); |
|
93
|
|
|
$this->setLogoFile($file); |
|
|
|
|
|
|
94
|
|
|
$this->getLogoFile()->shouldReturn($file); |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
$this->setLogoName('Odiseo logo'); |
|
|
|
|
|
|
97
|
|
|
$this->getLogoName()->shouldReturn('Odiseo logo'); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
function it_associates_channels(ChannelInterface $channel): void |
|
101
|
|
|
{ |
|
102
|
|
|
$this->getChannels()->shouldHaveCount(0); |
|
|
|
|
|
|
103
|
|
|
$this->addChannel($channel); |
|
|
|
|
|
|
104
|
|
|
$this->getChannels()->shouldHaveCount(1); |
|
105
|
|
|
$this->removeChannel($channel); |
|
|
|
|
|
|
106
|
|
|
$this->getChannels()->shouldHaveCount(0); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function it_associates_products(ProductInterface $product): void |
|
110
|
|
|
{ |
|
111
|
|
|
$this->getProducts()->shouldHaveCount(0); |
|
|
|
|
|
|
112
|
|
|
$this->addProduct($product); |
|
|
|
|
|
|
113
|
|
|
$this->getProducts()->shouldHaveCount(1); |
|
114
|
|
|
$this->removeProduct($product); |
|
|
|
|
|
|
115
|
|
|
$this->getProducts()->shouldHaveCount(0); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.