Issues (281)

Branch: master

src/Common/Tests/Mailer/ConfiguratorTest.php (1 issue)

1
<?php
2
3
namespace Common\Tests\Mailer;
4
5
use Common\Mailer\Configurator;
6
use PHPUnit\Framework\MockObject\MockObject;
0 ignored issues
show
The type PHPUnit\Framework\MockObject\MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Tests for our module settings
11
 */
12
class ConfiguratorTest extends TestCase
13
{
14
    public function testConfiguratorSetsMailTransportByDefault(): void
15
    {
16
        $modulesSettingsMock = $this->getModulesSettingsMock();
17
        $containerMock =
18
            $this->getContainerMock();
19
20
        $configurator = new Configurator(
21
            $modulesSettingsMock,
22
            $containerMock
23
        );
24
25
        // always return null: we have no modules settings set
26
        $modulesSettingsMock
27
            ->expects($this->exactly(6))
28
            ->method('get')
29
            ->will($this->returnValue(null))
30
        ;
31
32
        // we want our set method to be called with a Mail transport
33
        $containerMock
34
            ->expects($this->once())
35
            ->method('set')
36
            ->with(
37
                $this->equalTo('swiftmailer.transport'),
38
                $this->isInstanceOf('\Swift_SendmailTransport')
39
            )
40
        ;
41
42
        $configurator->onKernelRequest($this->getGetResponseEventMock());
43
    }
44
45
    public function testConfiguratorSetsSmtpTransport(): void
46
    {
47
        $modulesSettingsMock = $this->getModulesSettingsMock();
48
        $containerMock =
49
            $this->getContainerMock();
50
51
        $configurator = new Configurator(
52
            $modulesSettingsMock,
53
            $containerMock
54
        );
55
56
        // always return null: we have modules settings set for smtp
57
        $modulesSettingsMock
58
            ->expects($this->exactly(6))
59
            ->method('get')
60
            ->will($this->onConsecutiveCalls(
61
                'smtp',
62
                'test.server.com',
63
                25,
64
                '[email protected]',
65
                'testpass'
66
            ))
67
        ;
68
69
        // we want our set method to be called with a Smtp transport
70
        $containerMock
71
            ->expects($this->once())
72
            ->method('set')
73
            ->with(
74
                $this->equalTo('swiftmailer.transport'),
75
                $this->isInstanceOf('\Swift_SmtpTransport')
76
            )
77
        ;
78
79
        $configurator->onKernelRequest($this->getGetResponseEventMock());
80
    }
81
82
    private function getModulesSettingsMock(): MockObject
83
    {
84
        return $this->createMock('Common\ModulesSettings');
85
    }
86
87
    private function getContainerMock(): MockObject
88
    {
89
        return $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
90
            ->disableOriginalConstructor()
91
            ->getMock()
92
        ;
93
    }
94
95
    private function getGetResponseEventMock(): MockObject
96
    {
97
        return $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
98
            ->disableOriginalConstructor()
99
            ->getMock()
100
        ;
101
    }
102
}
103