1
|
|
|
<?php |
2
|
|
|
namespace AcMailerTest\Controller\Plugin; |
3
|
|
|
|
4
|
|
|
use AcMailer\Controller\Plugin\Factory\SendMailPluginAbstractFactory; |
5
|
|
|
use AcMailer\Controller\Plugin\SendMailPlugin; |
6
|
|
|
use AcMailer\Service\Factory\MailServiceAbstractFactory; |
7
|
|
|
use AcMailer\Service\MailServiceMock; |
8
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
9
|
|
|
use Zend\ServiceManager\ServiceManager; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class SendMailPluginFactoryTest |
13
|
|
|
* @author Alejandro Celaya Alastrué |
14
|
|
|
* @link http://www.alejandrocelaya.com |
15
|
|
|
*/ |
16
|
|
|
class SendMailPluginAbstractFactoryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var SendMailPluginAbstractFactory |
20
|
|
|
*/ |
21
|
|
|
private $factory; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->factory = new SendMailPluginAbstractFactory(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testCanCreateServiceWithInvalidName() |
29
|
|
|
{ |
30
|
|
|
$sm = $this->createServiceManager(); |
31
|
|
|
$this->assertFalse($this->factory->canCreate($sm, 'foo')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testCanCreateServiceWithBaseName() |
35
|
|
|
{ |
36
|
|
|
$sm = $this->createServiceManager(); |
37
|
|
|
$this->assertTrue($this->factory->canCreate($sm, 'sendMail')); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testCanCreateServiceWhenConcreteServiceIsNotDefined() |
41
|
|
|
{ |
42
|
|
|
$sm = $this->createServiceManager([ |
43
|
|
|
'acmailer_options' => [ |
44
|
|
|
'concrete' => [] |
45
|
|
|
] |
46
|
|
|
]); |
47
|
|
|
$this->assertTrue($this->factory->canCreate($sm, 'sendMailConcrete')); |
48
|
|
|
$this->assertFalse($this->factory->canCreate($sm, 'sendMailInvalid')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testCreateServiceWithName() |
52
|
|
|
{ |
53
|
|
|
$sm = $this->createServiceManager(); |
54
|
|
|
$mailServiceName = sprintf( |
55
|
|
|
'%s.%s.%s', |
56
|
|
|
MailServiceAbstractFactory::ACMAILER_PART, |
57
|
|
|
MailServiceAbstractFactory::SPECIFIC_PART, |
58
|
|
|
'concrete' |
59
|
|
|
); |
60
|
|
|
$sm->setService($mailServiceName, new MailServiceMock()); |
61
|
|
|
$this->assertInstanceOf(SendMailPlugin::class, $this->factory->__invoke($sm, 'sendMailConcrete')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function createServiceManager($config = []) |
65
|
|
|
{ |
66
|
|
|
$sm = new ServiceManager(); |
67
|
|
|
$sm->setService('Config', $config); |
68
|
|
|
|
69
|
|
|
return $sm; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|