Passed
Push — master ( 7a29a8...8313d7 )
by Michael
01:59
created

InstallCommandTest::createMongoMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/* Copyright (C) 2017 Michael Giesler
3
 *
4
 * This file is part of Dembelo.
5
 *
6
 * Dembelo is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Dembelo is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License 3 for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License 3
17
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/**
21
 * @package DembeloMain
22
 */
23
24
namespace DembeloMain\Tests\Command;
25
26
use Apoutchika\LoremIpsumBundle\Services\LoremIpsum;
27
use DembeloMain\Model\Repository\LicenseeRepositoryInterface;
28
use DembeloMain\Model\Repository\TextNodeRepositoryInterface;
29
use DembeloMain\Model\Repository\TopicRepositoryInterface;
30
use DembeloMain\Model\Repository\UserRepositoryInterface;
31
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
32
use PHPUnit\Framework\TestCase;
33
use DembeloMain\Command\InstallCommand;
34
use Symfony\Component\Console\Tester\CommandTester;
35
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
36
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
37
38
/**
39
 * Class DefaultControllerTest
40
 */
41
class InstallCommandTest extends TestCase
42
{
43
    /**
44
     * @var InstallCommand
45
     */
46
    private $command;
47
48
    /**
49
     * @var CommandTester
50
     */
51
    private $commandTester;
52
53
    /**
54
     * @var UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
55
     */
56
    private $userRepositoryMock;
57
58
    /**
59
     * @var PasswordEncoderInterface|\PHPUnit_Framework_MockObject_MockObject
60
     */
61
    private $passwordEncoderMock;
62
63
    /**
64
     * @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject
65
     */
66
    private $mongoMock;
67
68
    /**
69
     * @var TopicRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
70
     */
71
    private $topicRepositoryMock;
72
73
    /**
74
     * @var TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
75
     */
76
    private $textnodeRepositoryMock;
77
78
    /**
79
     * @var LicenseeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
80
     */
81
    private $licenseeRepositoryMock;
82
83
    /**
84
     * @var string
85
     */
86
    private $topicDummyImageDirectory = '/tmp/topicDummyImages/';
87
88
    /**
89
     * @var string
90
     */
91
    private $topicImageDirectory = '/tmp/topicImages/';
92
93
    /**
94
     * @var LoremIpsum|\PHPUnit_Framework_MockObject_MockObject
95
     */
96
    private $loremIpsumMock;
97
98
    /**
99
     * @return void
100
     */
101
    protected function setUp(): void
102
    {
103
        $this->mongoMock = $this->createMongoMock();
104
        $this->topicRepositoryMock = $this->createTopicRepositoryMock();
105
        $this->textnodeRepositoryMock = $this->createTextnodeRepositoryMock();
106
        $this->licenseeRepositoryMock = $this->createLicenseeRepositoryMock();
107
        $this->userRepositoryMock = $this->createUserRepositoryMock();
108
        $this->loremIpsumMock = $this->createLoremIpsumMock();
109
        $this->passwordEncoderMock = $this->createPasswordEncoderMock();
110
111
        $this->command = new InstallCommand(
112
            $this->mongoMock,
113
            $this->topicRepositoryMock,
114
            $this->textnodeRepositoryMock,
115
            $this->licenseeRepositoryMock,
116
            $this->userRepositoryMock,
117
            $this->loremIpsumMock,
118
            $this->passwordEncoderMock,
119
            $this->topicDummyImageDirectory,
120
            $this->topicImageDirectory
121
        );
122
        $this->commandTester = new CommandTester($this->command);
123
    }
124
125
    /**
126
     * tests the install
127
     * @return void
128
     */
129
    public function testRunConfigure(): void
130
    {
131
        $returnValue = $this->commandTester->execute([]);
132
133
        // the output of the command in the console
134
        $output = $this->commandTester->getDisplay();
135
        $this->assertEquals('admin user installed'."\n".'Default users installed'."\n", $output);
136
        $this->assertEquals(0, $returnValue);
137
    }
138
139
    /**
140
     * @return UserRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
141
     */
142 View Code Duplication
    private function createUserRepositoryMock(): UserRepositoryInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
143
    {
144
        $methods = [
145
            'findOneByEmail',
146
            'find',
147
            'findByEmail',
148
            'findAll',
149
            'save',
150
            'findBy',
151
            'findOneBy',
152
            'getClassName',
153
        ];
154
155
        return $this->getMockBuilder(UserRepositoryInterface::class)->setMethods($methods)->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getMockBui...ds($methods)->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...UserRepositoryInterface.
Loading history...
156
    }
157
158
    /**
159
     * @return BasePasswordEncoder|\PHPUnit_Framework_MockObject_MockObject
160
     */
161
    private function createPasswordEncoderMock(): BasePasswordEncoder
162
    {
163
        $methods = [
164
            'encodePassword',
165
            'isPasswordValid',
166
        ];
167
        $mock = $this->getMockBuilder(BasePasswordEncoder::class)->setMethods($methods)->getMock();
168
169
        $mock->expects($this->any())
170
            ->method('encodePassword')
171
            ->willReturn('encodedPassword');
172
173
        return $mock;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $mock returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Symfony\Component\Securi...der\BasePasswordEncoder.
Loading history...
174
    }
175
176
    /**
177
     * @return ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject
178
     */
179
    private function createMongoMock(): ManagerRegistry
180
    {
181
        return $this->createMock(ManagerRegistry::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...ManagerRegistry::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Doctrine\Bundle\MongoDBBundle\ManagerRegistry.
Loading history...
182
    }
183
184
    /**
185
     * @return TopicRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
186
     */
187
    private function createTopicRepositoryMock(): TopicRepositoryInterface
188
    {
189
        return $this->createMock(TopicRepositoryInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...sitoryInterface::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...opicRepositoryInterface.
Loading history...
190
    }
191
192
    /**
193
     * @return TextNodeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
194
     */
195
    private function createTextnodeRepositoryMock(): TextNodeRepositoryInterface
196
    {
197
        return $this->createMock(TextNodeRepositoryInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...sitoryInterface::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...NodeRepositoryInterface.
Loading history...
198
    }
199
200
    /**
201
     * @return LicenseeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
202
     */
203
    private function createLicenseeRepositoryMock(): LicenseeRepositoryInterface
204
    {
205
        return $this->createMock(LicenseeRepositoryInterface::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...sitoryInterface::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...nseeRepositoryInterface.
Loading history...
206
    }
207
208
    /**
209
     * @return LoremIpsum|\PHPUnit_Framework_MockObject_MockObject
210
     */
211
    private function createLoremIpsumMock(): LoremIpsum
212
    {
213
        return $this->createMock(LoremIpsum::class);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createMock...ices\LoremIpsum::class) returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return Apoutchika\LoremIpsumBundle\Services\LoremIpsum.
Loading history...
214
    }
215
}
216