1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Component\Core\Model; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\Common\Collections\Collection; |
18
|
|
|
use Doctrine\Common\Comparable; |
19
|
|
|
use PhpSpec\ObjectBehavior; |
20
|
|
|
use Sylius\Component\Core\Model\ImageInterface; |
21
|
|
|
use Sylius\Component\Core\Model\ImagesAwareInterface; |
22
|
|
|
use Sylius\Component\Core\Model\Taxon; |
23
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
24
|
|
|
|
25
|
|
|
final class TaxonSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function it_is_a_taxon(): void |
28
|
|
|
{ |
29
|
|
|
$this->shouldImplement(TaxonInterface::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
function it_implements_an_image_aware_interface(): void |
33
|
|
|
{ |
34
|
|
|
$this->shouldImplement(ImagesAwareInterface::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_implements_doctrine_comparable(): void |
38
|
|
|
{ |
39
|
|
|
$this->shouldImplement(Comparable::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_initializes_an_image_collection_by_default(): void |
43
|
|
|
{ |
44
|
|
|
$this->getImages()->shouldHaveType(Collection::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_adds_an_image(ImageInterface $image): void |
48
|
|
|
{ |
49
|
|
|
$this->addImage($image); |
50
|
|
|
$this->hasImages()->shouldReturn(true); |
51
|
|
|
$this->hasImage($image)->shouldReturn(true); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_removes_an_image(ImageInterface $image): void |
55
|
|
|
{ |
56
|
|
|
$this->addImage($image); |
57
|
|
|
$this->removeImage($image); |
58
|
|
|
$this->hasImage($image)->shouldReturn(false); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function it_returns_images_by_type(ImageInterface $image): void |
62
|
|
|
{ |
63
|
|
|
$image->getType()->willReturn('thumbnail'); |
64
|
|
|
$image->setOwner($this)->shouldBeCalled(); |
65
|
|
|
|
66
|
|
|
$this->addImage($image); |
67
|
|
|
|
68
|
|
|
$this->getImagesByType('thumbnail')->shouldBeLike(new ArrayCollection([$image->getWrappedObject()])); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function it_is_comparable(): void |
72
|
|
|
{ |
73
|
|
|
$this->setCode('test'); |
74
|
|
|
|
75
|
|
|
$otherTaxon = new Taxon(); |
76
|
|
|
$otherTaxon->setCode('test'); |
77
|
|
|
$this->compareTo($otherTaxon)->shouldReturn(0); |
78
|
|
|
|
79
|
|
|
$otherTaxon->setCode('other'); |
80
|
|
|
$this->compareTo($otherTaxon)->shouldReturn(1); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|