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\Subscription; |
||
33 | use OCA\Polls\Db\SubscriptionMapper; |
||
34 | |||
35 | class SubscriptionMapperTest extends UnitTestCase { |
||
36 | |||
37 | /** @var IDBConnection */ |
||
38 | private $con; |
||
39 | |||
40 | /** @var SubscriptionMapper */ |
||
41 | private $subscriptionMapper; |
||
42 | |||
43 | /** @var PollMapper */ |
||
44 | private $pollMapper; |
||
45 | |||
46 | /** @var array */ |
||
47 | private $polls = []; |
||
48 | |||
49 | /** @var array */ |
||
50 | private $subscriptions = []; |
||
51 | |||
52 | /** @var array */ |
||
53 | private $users = []; |
||
54 | |||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | protected function setUp(): void { |
||
60 | parent::setUp(); |
||
61 | $this->con = \OC::$server->getDatabaseConnection(); |
||
62 | $this->subscriptionMapper = new SubscriptionMapper($this->con); |
||
63 | $this->pollMapper = new PollMapper($this->con); |
||
64 | |||
65 | $this->polls = [ |
||
66 | $this->fm->instance('OCA\Polls\Db\Poll') |
||
67 | ]; |
||
68 | |||
69 | foreach ($this->polls as &$poll) { |
||
70 | $poll = $this->pollMapper->insert($poll); |
||
71 | |||
72 | for ($count=0; $count < 2; $count++) { |
||
73 | $subscription = $this->fm->instance('OCA\Polls\Db\Subscription'); |
||
74 | $subscription->setPollId($poll->getId()); |
||
75 | array_push($this->subscriptions, $this->subscriptionMapper->insert($subscription)); |
||
76 | } |
||
77 | $this->users[$poll->getId()] = $subscription->getUserId(); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
78 | } |
||
79 | unset($poll); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * testFindAllByPoll |
||
84 | */ |
||
85 | public function testFindAllByPoll() { |
||
86 | foreach ($this->polls as $poll) { |
||
87 | $this->assertTrue(count($this->subscriptionMapper->findAllByPoll($poll->getId())) > 0); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * testfindByPollAndUser |
||
93 | */ |
||
94 | public function testfindByPollAndUser() { |
||
95 | foreach ($this->polls as $poll) { |
||
96 | $this->assertInstanceOf(Subscription::class, $this->subscriptionMapper->findByPollAndUser($poll->getId(), $this->users[$poll->getId()])); |
||
97 | } |
||
98 | } |
||
99 | /** |
||
100 | * testUnsubscribe |
||
101 | */ |
||
102 | public function testUnsubscribe() { |
||
103 | foreach ($this->polls as $poll) { |
||
104 | $this->assertNull($this->subscriptionMapper->unsubscribe($poll->getId(), $this->users[$poll->getId()])); |
||
0 ignored issues
–
show
Are you sure the usage of
$this->subscriptionMappe...>users[$poll->getId()]) targeting OCA\Polls\Db\SubscriptionMapper::unsubscribe() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
105 | } |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * tearDown |
||
110 | */ |
||
111 | public function tearDown(): void { |
||
112 | parent::tearDown(); |
||
113 | foreach ($this->polls as $poll) { |
||
114 | $this->pollMapper->delete($poll); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | } |
||
119 |