Passed
Pull Request — master (#1270)
by René
03:41
created

OptionMapperTest::testDelete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php declare(strict_types=1);
2
/**
3
 * @copyright Copyright (c) 2017 Kai Schröer <[email protected]>
4
 *
5
 * @author Kai Schröer <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Db;
25
26
use League\FactoryMuffin\Faker\Facade as Faker;
27
use OCP\IDBConnection;
28
use OCA\Polls\Tests\Unit\UnitTestCase;
29
30
use OCA\Polls\Db\Poll;
31
use OCA\Polls\Db\PollMapper;
32
use OCA\Polls\Db\Option;
33
use OCA\Polls\Db\OptionMapper;
34
35
class OptionMapperTest extends UnitTestCase {
36
37
	/** @var IDBConnection */
38
	private $con;
39
40
	/** @var OptionMapper */
41
	private $optionMapper;
42
43
	/** @var PollMapper */
44
	private $pollMapper;
45
46
	/** @var array */
47
	private $polls = [];
48
49
	/** @var array */
50
	private $options = [];
51
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	protected function setUp(): void {
56
		parent::setUp();
57
		$this->con = \OC::$server->getDatabaseConnection();
58
		$this->optionMapper = new OptionMapper($this->con);
59
		$this->pollMapper = new PollMapper($this->con);
60
61
		$this->polls = [
62
			$this->fm->instance('OCA\Polls\Db\Poll')
63
		];
64
65
		foreach ($this->polls as &$poll) {
66
			$poll = $this->pollMapper->insert($poll);
67
68
			for ($count=0; $count < 2; $count++) {
69
				$option = $this->fm->instance('OCA\Polls\Db\Option');
70
				$option->setPollId($poll->getId());
71
				array_push($this->options, $this->optionMapper->insert($option));
72
			}
73
		}
74
		unset($poll);
75
	}
76
77
	/**
78
	 * testFind
79
	 */
80
	public function testFind() {
81
		foreach ($this->options as $option) {
82
			$this->assertInstanceOf(Option::class, $this->optionMapper->find($option->getId()));
83
		}
84
	}
85
86
	/**
87
	 * testFindByPoll
88
	 */
89
	public function testFindByPoll() {
90
		foreach ($this->polls as $poll) {
91
			$this->assertTrue(count($this->optionMapper->findByPoll($poll->getId())) > 0);
92
		}
93
	}
94
95
	/**
96
	 * testUpdate
97
	 * includes testFind
98
	 */
99
	public function testUpdate() {
100
		foreach ($this->options as &$option) {
101
			$option->setPollOptionText('Changed option');
102
			$this->assertInstanceOf(Option::class, $this->optionMapper->update($option));
103
		}
104
	}
105
106
	/**
107
	 * testDelete
108
	 */
109
	public function testDelete() {
110
		foreach ($this->options as $option) {
111
			$this->assertInstanceOf(Option::class, $this->optionMapper->delete($option));
112
		}
113
	}
114
115
	/**
116
	 * tearDown
117
	 */
118
	public function tearDown(): void {
119
		parent::tearDown();
120
		foreach ($this->polls as $poll) {
121
			$this->pollMapper->delete($poll);
122
		}
123
	}
124
}
125