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\Poll; |
||
31 | use OCA\Polls\Db\PollMapper; |
||
32 | use OCA\Polls\Db\Vote; |
||
33 | use OCA\Polls\Db\VoteMapper; |
||
34 | use OCA\Polls\Db\Option; |
||
35 | use OCA\Polls\Db\OptionMapper; |
||
36 | |||
37 | class VoteMapperTest extends UnitTestCase { |
||
38 | |||
39 | /** @var IDBConnection */ |
||
40 | private $con; |
||
41 | /** @var VoteMapper */ |
||
42 | private $voteMapper; |
||
43 | /** @var PollMapper */ |
||
44 | private $pollMapper; |
||
45 | /** @var OptionMapper */ |
||
46 | private $optionMapper; |
||
47 | |||
48 | |||
49 | /** @var array */ |
||
50 | private $polls = []; |
||
51 | |||
52 | /** @var array */ |
||
53 | private $options = []; |
||
54 | |||
55 | /** @var array */ |
||
56 | private $votes = []; |
||
57 | |||
58 | /** |
||
59 | * {@inheritDoc} |
||
60 | */ |
||
61 | protected function setUp(): void { |
||
62 | parent::setUp(); |
||
63 | $this->con = \OC::$server->getDatabaseConnection(); |
||
64 | $this->voteMapper = new VoteMapper($this->con); |
||
65 | $this->pollMapper = new PollMapper($this->con); |
||
66 | $this->optionMapper = new OptionMapper($this->con); |
||
67 | |||
68 | $this->polls = [ |
||
69 | $this->fm->instance('OCA\Polls\Db\Poll') |
||
70 | ]; |
||
71 | |||
72 | foreach ($this->polls as &$poll) { |
||
73 | $poll = $this->pollMapper->insert($poll); |
||
74 | |||
75 | for ($optionsCount=0; $optionsCount < 2; $optionsCount++) { |
||
76 | $option = $this->fm->instance('OCA\Polls\Db\Option'); |
||
77 | $option->setPollId($poll->getId()); |
||
78 | array_push($this->options, $this->optionMapper->insert($option)); |
||
79 | $vote = $this->fm->instance('OCA\Polls\Db\Vote'); |
||
80 | $vote->setPollId($option->getPollId()); |
||
81 | $vote->setUserId('voter'); |
||
82 | $vote->setVoteOptionText($option->getPollOptionText()); |
||
83 | array_push($this->votes, $this->voteMapper->insert($vote)); |
||
84 | } |
||
85 | } |
||
86 | unset($poll); |
||
87 | } |
||
88 | |||
89 | |||
90 | /** |
||
91 | * testFindByPoll |
||
92 | */ |
||
93 | public function testFindByPoll() { |
||
94 | foreach ($this->polls as $poll) { |
||
95 | $this->assertTrue(count($this->voteMapper->findByPoll($poll->getId())) > 0); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * testFindByPollAndUser |
||
101 | */ |
||
102 | public function testFindByPollAndUser() { |
||
103 | foreach ($this->polls as $poll) { |
||
104 | $this->assertTrue(count($this->voteMapper->findByPollAndUser($poll->getId(), 'voter')) > 0); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * testFindSingleVote |
||
110 | */ |
||
111 | public function testFindSingleVote() { |
||
112 | foreach ($this->votes as $vote) { |
||
113 | $this->assertInstanceOf(Vote::class, $this->voteMapper->findSingleVote($vote->getPollId(), $vote->getVoteOptionText(), $vote->getUserId())); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * testParticipantsByPoll |
||
119 | */ |
||
120 | public function testParticipantsByPoll() { |
||
121 | foreach ($this->polls as $poll) { |
||
122 | $this->assertTrue(count($this->voteMapper->findParticipantsByPoll($poll->getId())) > 0); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * testParticipantsByPoll |
||
128 | */ |
||
129 | public function testFindParticipantsVotes() { |
||
130 | foreach ($this->votes as $vote) { |
||
131 | $this->assertTrue(count($this->voteMapper->findParticipantsVotes($vote->getPollId(), $vote->getUserId())) > 0); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * testUpdate |
||
137 | */ |
||
138 | public function testUpdate() { |
||
139 | foreach ($this->votes as &$vote) { |
||
140 | $vote->setVoteAnswer('no'); |
||
141 | $this->assertInstanceOf(Vote::class, $this->voteMapper->update($vote)); |
||
142 | } |
||
143 | unset($vote); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * testDeleteByPollAndUser |
||
148 | */ |
||
149 | public function testDeleteByPollAndUser() { |
||
150 | foreach ($this->polls as $poll) { |
||
151 | $this->assertNull($this->voteMapper->deleteByPollAndUser($poll->getId(), 'voter')); |
||
0 ignored issues
–
show
|
|||
152 | } |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * tearDown |
||
157 | */ |
||
158 | public function tearDown(): void { |
||
159 | parent::tearDown(); |
||
160 | foreach ($this->options as $option) { |
||
161 | $this->optionMapper->delete($option); |
||
162 | } |
||
163 | foreach ($this->polls as $poll) { |
||
164 | $this->pollMapper->delete($poll); |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.