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

AliasMapperTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 21.82 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 5
c 2
b 1
f 1
lcom 1
cbo 2
dl 12
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 5 1
A testFind() 0 14 1
A tearDown() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @author Tahaa Karim <[email protected]>
5
 *
6
 * ownCloud - 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\Db;
23
24
use OC\AppFramework\Db\Db;
25
26
class AliasMapperTest extends \PHPUnit_Framework_TestCase {
27
28
	/**
29
	 * @var AliasMapper
30
	 */
31
	private $mapper;
32
33
	/**
34
	 * @var \OC\DB\Connection
35
	 */
36
	private $db;
37
38
	/**
39
	 * @var Alias
40
	 */
41
	private $alias;
42
43
	/**
44
	 * Initialize Mapper
45
	 */
46
	public function setup(){
47
		$db = \OC::$server->getDatabaseConnection();
48
		$this->db = new Db($db);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \OC\AppFramework\Db\Db($db) of type object<OC\AppFramework\Db\Db> is incompatible with the declared type object<OC\DB\Connection> of property $db.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
		$this->mapper = new AliasMapper($this->db);
50
	}
51
52
	public function testFind(){
53
54
		$this->alias = new Alias();
55
		$this->alias->setAccountId(1);
56
		$this->alias->setAlias('[email protected]');
57
		$this->alias->setName('alias');
58
59
		/** @var Alias $b */
60
		$b = $this->mapper->insert($this->alias);
61
62
		$result = $this->mapper->find($b->getId(), 'user12345');
63
64
		$this->assertEquals($b, $result);
65
	}
66
67 View Code Duplication
	protected function tearDown() {
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...
68
		parent::tearDown();
69
70
		$sql = 'DELETE FROM *PREFIX*mail_aliases WHERE `id` = ?';
71
		$stmt = $this->db->prepare($sql);
72
		if (!empty($this->alias)) {
73
			$stmt->execute([$this->alias->getId()]);
74
		}
75
		if (!empty($this->address2)) {
76
			$stmt->execute([$this->alias->getId()]);
77
		}
78
	}
79
80
}
81