1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<?php
/**
* @author Tahaa Karim <tahaalibra@gmail.com>
*
* Mail
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Mail\Tests\Unit\Service;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Db\Alias;
use OCA\Mail\Db\AliasMapper;
use OCA\Mail\Service\AliasesService;
use PHPUnit_Framework_MockObject_MockObject;
class AliasesServiceTest extends TestCase {
/** @var AliasesService|PHPUnit_Framework_MockObject_MockObject */
private $service;
/** @var string */
private $user = 'herbert';
/** @var AliasMapper|PHPUnit_Framework_MockObject_MockObject */
private $mapper;
/** @var Alias|PHPUnit_Framework_MockObject_MockObject */
private $alias;
protected function setUp(): void {
parent::setUp();
$this->mapper = $this->createMock(AliasMapper::class);
$this->alias = $this->createMock(Alias::class);
$this->service = new AliasesService($this->mapper);
}
public function testFindAll() {
$accountId = 123;
$this->mapper->expects($this->once())
->method('findAll')
->with($accountId, $this->user)
->will($this->returnValue([$this->alias]));
$actual = $this->service->findAll($accountId, $this->user);
$expected = [
$this->alias
];
$this->assertEquals($expected, $actual);
}
public function testFind() {
$aliasId = 123;
$this->mapper->expects($this->once())
->method('find')
->with($aliasId, $this->user)
->will($this->returnValue($this->alias));
$actual = $this->service->find($aliasId, $this->user);
$expected = $this->alias;
$this->assertEquals($expected, $actual);
}
public function testCreate() {
$accountId = 123;
$alias = "alias@marvel.com";
$aliasName = "alias";
$aliasEntity = new Alias();
$aliasEntity->setAccountId($accountId);
$aliasEntity->setAlias($alias);
$aliasEntity->setName($aliasName);
$this->mapper->expects($this->once())
->method('insert')
->with($aliasEntity)
->will($this->returnValue($aliasEntity));
$result = $this->service->create($accountId, $alias, $aliasName);
$this->assertEquals(
[
'accountId' => $aliasEntity->getAccountId(),
'name' => $aliasEntity->getName(),
'alias' => $aliasEntity->getAlias(),
'id' => $aliasEntity->getId()
], [
'accountId' => $result->getAccountId(),
'name' => $result->getName(),
'alias' => $result->getAlias(),
'id' => $result->getId()
]
);
}
public function testDelete() {
$aliasId = 123;
$this->mapper->expects($this->once())
->method('find')
->with($aliasId, $this->user)
->will($this->returnValue($this->alias));
$this->mapper->expects($this->once())
->method('delete')
->with($this->alias);
$this->service->delete($aliasId, $this->user);
}
}
|