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

AliasMapperTest::testFind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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