UpdateTemplateParametersListenerTest::testUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2014 Roave, LLC.
4
 * All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 *   * Redistributions of source code must retain the above copyright
11
 *     notice, this list of conditions and the following disclaimer.
12
 *
13
 *   * Redistributions in binary form must reproduce the above copyright
14
 *     notice, this list of conditions and the following disclaimer in
15
 *     the documentation and/or other materials provided with the
16
 *     distribution.
17
 *
18
 *   * Neither the names of the copyright holders nor the names of the
19
 *     contributors may be used to endorse or promote products derived
20
 *     from this software without specific prior written permission.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
 * POSSIBILITY OF SUCH DAMAGE.
34
 *
35
 * @author    Antoine Hedgecock
36
 * @author    Jonas Rosenlind
37
 *
38
 * @copyright 2014 Roave, LLC
39
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
40
 */
41
42
namespace EmailTemplatesTest\Service\Template\Listener;
43
44
use PHPUnit_Framework_TestCase;
45
use Roave\EmailTemplates\Entity\TemplateEntity;
46
use Roave\EmailTemplates\Options\TemplateServiceOptions;
47
use Roave\EmailTemplates\Repository\TemplateRepositoryInterface;
48
use Roave\EmailTemplates\Service\Template\Listener\UpdateTemplateParametersListener;
49
use Roave\EmailTemplates\Service\TemplateService;
50
use Roave\EmailTemplates\Service\TemplateServiceInterface;
51
use Zend\EventManager\Event;
52
use Zend\EventManager\EventManagerInterface;
53
54
/**
55
 * Class UpdateTemplateParametersListenerTest
56
 *
57
 * @coversDefaultClass \Roave\EmailTemplates\Service\Template\Listener\UpdateTemplateParametersListener
58
 * @covers ::<!public>
59
 *
60
 * @group service
61
 */
62
class UpdateTemplateParametersListenerTest extends PHPUnit_Framework_TestCase
63
{
64
    /**
65
     * @var \PHPUnit_Framework_MockObject_MockObject
66
     */
67
    protected $templateRepository;
68
69
    /**
70
     * @var TemplateServiceOptions
71
     */
72
    protected $options;
73
74
    /**
75
     * @var UpdateTemplateParametersListener
76
     */
77
    protected $template;
78
79
    /**
80
     * @covers ::__construct
81
     */
82
    public function setUp()
83
    {
84
        $this->options            = new TemplateServiceOptions();
85
        $this->templateRepository = $this->createMock(TemplateRepositoryInterface::class);
86
87
        $this->template = new UpdateTemplateParametersListener($this->templateRepository, $this->options);
88
    }
89
90
    /**
91
     * @covers ::attach
92
     */
93
    public function testAttach()
94
    {
95
        $events = $this->createMock(EventManagerInterface::class);
96
        $events
97
            ->expects($this->once())
98
            ->method('attach')
99
            ->with(TemplateService::EVENT_RENDER, [$this->template, 'update']);
100
101
        $this->template->attach($events);
102
    }
103
104
    /**
105
     * @covers ::update
106
     */
107
    public function testUpdateIfStatement()
108
    {
109
        $template = new TemplateEntity();
110
        $template->setId(1337);
111
        $template->setUpdateParameters(false);
112
113
        $service = $this->createMock(TemplateServiceInterface::class);
114
        $event   = new Event(TemplateService::EVENT_RENDER, $service, ['template' => $template, 'parameters' => []]);
115
116
        $this->template->update($event);
117
    }
118
119
    /**
120
     * @covers ::update
121
     */
122
    public function testUpdate()
123
    {
124
        $template = new TemplateEntity();
125
        $template->setId(1337);
126
        $template->setUpdateParameters(true);
127
128
        $service = $this->createMock(TemplateServiceInterface::class);
129
        $service
130
            ->expects($this->once())
131
            ->method('update')
132
            ->with(['parameters' => [], 'updateParams' => false]);
133
134
        $event = new Event(TemplateService::EVENT_RENDER, $service, ['template' => $template, 'parameters' => []]);
135
136
        $this->templateRepository
137
            ->expects($this->once())
138
            ->method('getById')
139
            ->with($template->getId())
140
            ->will($this->returnValue([$template]));
141
142
        $this->template->update($event);
143
    }
144
}
145