TransportFactoryTest::testCreateServiceWithFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

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 14
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\Factory\Service;
43
44
use Roave\EmailTemplates\Factory\Service\Exception\InvalidArgumentException as InvalidArgumentException;
45
use PHPUnit_Framework_TestCase;
46
use Roave\EmailTemplates\Factory\Service\Exception\ConfigurationException;
47
use Roave\EmailTemplates\Factory\Service\TransportFactory;
48
use Zend\ServiceManager\ServiceLocatorInterface;
49
50
/**
51
 * Class TransportFactoryTest
52
 *
53
 * @coversDefaultClass \Roave\EmailTemplates\Factory\Service\TransportFactory
54
 */
55
class TransportFactoryTest extends PHPUnit_Framework_TestCase
56
{
57
    /**
58
     * @var TransportFactory
59
     */
60
    protected $factory;
61
62
    public function setUp()
63
    {
64
        $this->factory = new TransportFactory();
65
    }
66
67
    /**
68
     * @covers ::createService
69
     */
70
    public function testCreateServiceWithSmtp()
71
    {
72
        $config = [
73
            'roave' => [
74
                'email_templates' => [
75
                    'transport' => [
76
                        'type'    => 'smtp',
77
                        'options' => []
78
                    ]
79
                ]
80
            ]
81
        ];
82
83
        $sl = $this->createMock(ServiceLocatorInterface::class);
84
        $sl
85
            ->expects($this->once())
86
            ->method('get')
87
            ->with('Config')
88
            ->will($this->returnValue($config));
89
90
        $this->factory->createService($sl);
91
    }
92
93
    /**
94
     * @covers ::createService
95
     */
96
    public function testCreateServiceWithFile()
97
    {
98
        $config = [
99
            'roave' => [
100
                'email_templates' => [
101
                    'transport' => [
102
                        'type'    => 'file',
103
                        'options' => []
104
                    ]
105
                ]
106
            ]
107
        ];
108
109
        $sl = $this->createMock(ServiceLocatorInterface::class);
110
        $sl
111
            ->expects($this->once())
112
            ->method('get')
113
            ->with('Config')
114
            ->will($this->returnValue($config));
115
116
        $this->factory->createService($sl);
117
    }
118
119
    /**
120
     * @covers ::createService
121
     */
122
    public function testCreateServiceWithSendmail()
123
    {
124
        $config = [
125
            'roave' => [
126
                'email_templates' => [
127
                    'transport' => [
128
                        'type'    => 'sendmail',
129
                        'options' => []
130
                    ]
131
                ]
132
            ]
133
        ];
134
135
        $sl = $this->createMock(ServiceLocatorInterface::class);
136
        $sl
137
            ->expects($this->once())
138
            ->method('get')
139
            ->with('Config')
140
            ->will($this->returnValue($config));
141
142
        $this->factory->createService($sl);
143
    }
144
145
    /**
146
     * @covers ::createService
147
     */
148
    public function testCreateServiceWithMissingTransport()
149
    {
150
        $this->setExpectedException(ConfigurationException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
151
        $config = [
152
            'roave' => [
153
                'email_templates' => [
154
155
                ]
156
            ]
157
        ];
158
159
        $sl = $this->createMock(ServiceLocatorInterface::class);
160
        $sl
161
            ->expects($this->once())
162
            ->method('get')
163
            ->with('Config')
164
            ->will($this->returnValue($config));
165
166
        $this->factory->createService($sl);
167
    }
168
169
    /**
170
     * @covers ::createService
171
     */
172
    public function testCreateServiceWithIncorrectTransport()
173
    {
174
        $this->setExpectedException(InvalidArgumentException::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
175
        $config = [
176
            'roave' => [
177
                'email_templates' => [
178
                    'transport' => [
179
                        'type'    => 'nerdtrain',
180
                        'options' => []
181
                    ]
182
                ]
183
            ]
184
        ];
185
186
        $sl = $this->createMock(ServiceLocatorInterface::class);
187
        $sl
188
            ->expects($this->once())
189
            ->method('get')
190
            ->with('Config')
191
            ->will($this->returnValue($config));
192
193
        $this->factory->createService($sl);
194
    }
195
}
196