|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Yproximite\Api\Message\Article; |
|
4
|
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
|
6
|
|
|
|
|
7
|
|
|
use Yproximite\Api\Model\Article\Category; |
|
8
|
|
|
use Yproximite\Api\Model\Article\CategoryTranslation; |
|
9
|
|
|
use Yproximite\Api\Message\Article\CategoryPatchMessage; |
|
10
|
|
|
use Yproximite\Api\Message\Article\CategoryTranslationMessage; |
|
11
|
|
|
|
|
12
|
|
|
class CategoryPatchMessageSpec extends ObjectBehavior |
|
13
|
|
|
{ |
|
14
|
|
|
function it_is_initializable() |
|
15
|
|
|
{ |
|
16
|
|
|
$this->shouldHaveType(CategoryPatchMessage::class); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
View Code Duplication |
function it_should_build() |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
$translation = new CategoryTranslationMessage(); |
|
22
|
|
|
$translation->setLocale('en'); |
|
23
|
|
|
$translation->setTitle('English title'); |
|
24
|
|
|
$translation->setDescription('English description'); |
|
25
|
|
|
|
|
26
|
|
|
$this->setParentRootId(11); |
|
27
|
|
|
$this->setEnabled(true); |
|
28
|
|
|
$this->addTranslation($translation); |
|
29
|
|
|
|
|
30
|
|
|
$transData = [ |
|
31
|
|
|
'title' => 'English title', |
|
32
|
|
|
'description' => 'English description', |
|
33
|
|
|
]; |
|
34
|
|
|
|
|
35
|
|
|
$data = [ |
|
36
|
|
|
'parentRootId' => 11, |
|
37
|
|
|
'enabled' => true, |
|
38
|
|
|
'translations' => ['en' => $transData], |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
$this->build()->shouldReturn($data); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_should_create_from_category( |
|
45
|
|
|
Category $category, |
|
46
|
|
|
CategoryTranslation $translation |
|
47
|
|
|
) { |
|
48
|
|
|
$translation->getLocale()->willReturn('en'); |
|
49
|
|
|
$translation->getTitle()->willReturn('English title'); |
|
50
|
|
|
$translation->getDescription()->willReturn('English description'); |
|
51
|
|
|
|
|
52
|
|
|
$category->getId()->willReturn(1); |
|
53
|
|
|
$category->isEnabled()->willReturn(true); |
|
54
|
|
|
$category->getTranslations()->willReturn([$translation]); |
|
55
|
|
|
|
|
56
|
|
|
$transMessage = new CategoryTranslationMessage(); |
|
57
|
|
|
$transMessage->setLocale('en'); |
|
58
|
|
|
$transMessage->setTitle('English title'); |
|
59
|
|
|
$transMessage->setDescription('English description'); |
|
60
|
|
|
|
|
61
|
|
|
$message = new CategoryPatchMessage(); |
|
62
|
|
|
$message->setId(1); |
|
63
|
|
|
$message->setEnabled(true); |
|
64
|
|
|
$message->addTranslation($transMessage); |
|
65
|
|
|
|
|
66
|
|
|
$this::createFromCategory($category)->shouldBeLike($message); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.