Passed
Pull Request — master (#1269)
by René
03:09
created

LogMapperTest::testFindByPoll()   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
c 0
b 0
f 0
dl 0
loc 3
rs 10
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 OCA\Polls\Db\Log;
27
use OCA\Polls\Db\LogMapper;
28
use OCA\Polls\Db\Poll;
29
use OCA\Polls\Db\PollMapper;
30
use OCA\Polls\Tests\Unit\UnitTestCase;
31
use OCP\IDBConnection;
32
use League\FactoryMuffin\Faker\Facade as Faker;
33
34
class LogMapperTest extends UnitTestCase {
35
36
	/** @var IDBConnection */
37
	private $con;
38
39
	/** @var LogMapper */
40
	private $logMapper;
41
42
	/** @var PollMapper */
43
	private $pollMapper;
44
45
	/** @var array */
46
	private $polls;
47
48
	/** @var array */
49
	private $logs;
50
51
	/** @var array */
52
	private $pollsById;
53
54
	/** @var array */
55
	private $logsById;
56
57
	/**
58
	 * {@inheritDoc}
59
	 */
60
	protected function setUp(): void {
61
		parent::setUp();
62
		$this->con = \OC::$server->getDatabaseConnection();
63
		$this->logMapper = new LogMapper($this->con);
64
		$this->pollMapper = new PollMapper($this->con);
65
66
		$this->polls = [];
67
		$this->logs = [];
68
69
		$this->polls = [
70
			$this->fm->instance('OCA\Polls\Db\Poll')
71
		];
72
73
		foreach ($this->polls as $poll) {
74
			$entry = $this->pollMapper->insert($poll);
75
			$entry->resetUpdatedFields();
76
			$this->pollsById[$entry->getId()] = $entry;
77
		}
78
		foreach ($this->pollsById as $id => $polls) {
79
			for ($count=0; $count < 2; $count++) {
80
				$log = $this->fm->instance('OCA\Polls\Db\Log');
81
				$log->setPollId($id);
82
				array_push($this->logs, $log);
83
			}
84
		}
85
86
		foreach ($this->logs as $log) {
87
			$entry = $this->logMapper->insert($log);
88
			$entry->resetUpdatedFields();
89
			$this->logsById[$entry->getId()] = $entry;
90
		}
91
92
93
	}
94
95
	/**
96
	 * Find the previously created entries from the database.
97
	 */
98
	public function testFindByPoll() {
99
		foreach ($this->pollsById as $id => $poll) {
100
			$this->assertTrue(count($this->logMapper->findByPoll($id)) > 0);
0 ignored issues
show
Bug introduced by
The method findByPoll() does not exist on OCA\Polls\Db\LogMapper. Did you maybe mean findByPollId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
			$this->assertTrue(count($this->logMapper->/** @scrutinizer ignore-call */ findByPoll($id)) > 0);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
101
		}
102
	}
103
104
	/**
105
	 * Find the previously created entries from the database.
106
	 */
107
	public function testFindUnprocessed() {
108
		$this->assertTrue(count($this->logMapper->findUnprocessed()) > 0);
109
	}
110
111
	/**
112
	 * Find the previously created entries from the database.
113
	 */
114
	public function testFindUnprocessedPolls() {
115
		$this->assertTrue(count($this->logMapper->findUnprocessedPolls()) > 0);
116
	}
117
118
	/**
119
	 * Find the previously created entries from the database.
120
	 */
121
	public function testGetLastRecord() {
122
		$this->assertInstanceOf(Log::class, $this->logMapper->getLastRecord());
0 ignored issues
show
Bug introduced by
The call to OCA\Polls\Db\LogMapper::getLastRecord() has too few arguments starting with pollId. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

122
		$this->assertInstanceOf(Log::class, $this->logMapper->/** @scrutinizer ignore-call */ getLastRecord());

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
123
	}
124
125
	/**
126
	 * Delete the previously created entries from the database.
127
	 */
128
	public function testDelete() {
129
		foreach ($this->logsById as $id => $log) {
130
			$found = $this->logMapper->find($id);
0 ignored issues
show
Bug introduced by
The method find() does not exist on OCA\Polls\Db\LogMapper. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

130
			/** @scrutinizer ignore-call */ 
131
   $found = $this->logMapper->find($id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
131
			$this->assertInstanceOf(Log::class, $this->logMapper->delete($found));
132
		}
133
	}
134
135
	public function tearDown(): void {
136
		parent::tearDown();
137
		foreach ($this->polls as $poll) {
138
			$this->pollMapper->delete($poll);
139
		}
140
	}
141
142
}
143