Completed
Pull Request — master (#1623)
by
unknown
05:57
created

AliasesServiceTest::testFind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

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