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

CommentMapperTest::testFind()   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\Tests\Unit\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\Comment;
31
use OCA\Polls\Db\CommentMapper;
32
use OCA\Polls\Db\Poll;
33
use OCA\Polls\Db\PollMapper;
34
35
class CommentMapperTest extends UnitTestCase {
36
37
	/** @var IDBConnection */
38
	private $con;
39
40
	/** @var CommentMapper */
41
	private $commentMapper;
42
43
	/** @var PollMapper */
44
	private $pollMapper;
45
46
	/** @var array */
47
	private $polls = [];
48
49
	/** @var array */
50
	private $comments = [];
51
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	protected function setUp(): void {
56
		parent::setUp();
57
		$this->con = \OC::$server->getDatabaseConnection();
58
		$this->commentMapper = new CommentMapper($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
				$comment = $this->fm->instance('OCA\Polls\Db\Comment');
70
				$comment->setPollId($poll->getId());
71
				array_push($this->comments, $this->commentMapper->insert($comment));
72
			}
73
		}
74
		unset($poll);
75
	}
76
77
	 /**
78
 	 * testFind
79
 	 */
80
 	public function testFind() {
81
 		foreach ($this->comments as $comment) {
82
 			$this->assertInstanceOf(Comment::class, $this->commentMapper->find($comment->getId()));
83
 		}
84
 	}
85
86
	/**
87
	 * testFindByPoll
88
	 */
89
	public function testFindByPoll() {
90
		foreach ($this->polls as $poll) {
91
			$this->assertTrue(count($this->commentMapper->findByPoll($poll->getId())) > 0);
92
		}
93
	}
94
95
	/**
96
	 * testUpdate
97
	 */
98
	public function testUpdate() {
99
		foreach ($this->comments as &$comment) {
100
			$newComment = Faker::paragraph();
101
			$comment->setComment($newComment());
102
			$this->assertInstanceOf(Comment::class, $this->commentMapper->update($comment));
103
		}
104
		unset($comment);
105
	}
106
107
	/**
108
	 * testDelete
109
	 */
110
	public function testDelete() {
111
		foreach ($this->comments as $comment) {
112
			$this->assertInstanceOf(Comment::class, $this->commentMapper->delete($comment));
113
		}
114
	}
115
116
	/**
117
	 * tearDown
118
	 */
119
	public function tearDown(): void {
120
		parent::tearDown();
121
		foreach ($this->polls as $poll) {
122
			$this->pollMapper->delete($poll);
123
		}
124
	}
125
126
}
127