GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SubscriptionManagerTest::testSubscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 15
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the CCDNForum ForumBundle
5
 *
6
 * (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/>
7
 *
8
 * Available on github <http://www.github.com/codeconsortium/>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace CCDNForum\ForumBundle\Tests\Manager;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use CCDNForum\ForumBundle\Tests\TestBase;
18
19
class SubscriptionManagerTest extends TestBase
20
{
21
    public function testSubscribe()
22
    {
23
		$this->purge();
24
		$users = $this->addFixturesForUsers();
25
		$forums = $this->addFixturesForForums();
26
		$categories = $this->addFixturesForCategories($forums);
27
		$boards = $this->addFixturesForBoards($categories);
28
		$topics = $this->addFixturesForTopics($boards);
29
		$this->addFixturesForPosts($topics, $users['tom']);
30
		$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']);
31
	    $subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId());
32
		
33
		$this->assertTrue($subscriptionFound->isSubscribed());
34
		$this->assertInternalType('integer', $subscriptionFound->getId());
35
    }
36
37
    public function testUnsubscribe()
38
    {
39
		$this->purge();
40
		$users = $this->addFixturesForUsers();
41
		$forums = $this->addFixturesForForums();
42
		$categories = $this->addFixturesForCategories($forums);
43
		$boards = $this->addFixturesForBoards($categories);
44
		$topics = $this->addFixturesForTopics($boards);
45
		$this->addFixturesForPosts($topics, $users['tom']);
46
		$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']);
47
		$this->getSubscriptionModel()->unsubscribe($topics[0], $users['tom']->getId());
48
	    $subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId());
49
		
50
		$this->assertFalse($subscriptionFound->isSubscribed());
51
		$this->assertInternalType('integer', $subscriptionFound->getId());
52
    }
53
	
54
	public function testMarkAsRead()
55
	{
56
		$this->purge();
57
		$users = $this->addFixturesForUsers();
58
		$forums = $this->addFixturesForForums();
59
		$categories = $this->addFixturesForCategories($forums);
60
		$boards = $this->addFixturesForBoards($categories);
61
		$topics = $this->addFixturesForTopics($boards);
62
		$this->addFixturesForPosts($topics, $users['tom']);
63
		$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']);
64
	    $subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId());
65
		$this->getSubscriptionModel()->markAsRead($subscriptionFound);
66
		$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($users['tom']->getId(), true);
67
		
68
		foreach ($subscriptionsFound as $subscription) {
69
			if ($subscription->getTopic()->getId() == $topics[0]->getId()) {
70
				$this->assertTrue($subscription->isSubscribed());
71
				$this->assertTrue($subscription->isRead());
72
				$this->assertInternalType('integer', $subscription->getId());
73
			}
74
		}
75
	}
76
77
	public function testMarkAsUnread()
78
	{
79
		$this->purge();
80
		$users = $this->addFixturesForUsers();
81
		$forums = $this->addFixturesForForums();
82
		$categories = $this->addFixturesForCategories($forums);
83
		$boards = $this->addFixturesForBoards($categories);
84
		$topics = $this->addFixturesForTopics($boards);
85
		$this->addFixturesForPosts($topics, $users['tom']);
86
		$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']);
87
	    $subscriptionFound = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId());
88
		$this->getSubscriptionModel()->markAsUnread($subscriptionFound);
89
		$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForUserById($users['tom']->getId(), true);
90
		
91
		foreach ($subscriptionsFound as $subscription) {
92
			if ($subscription->getTopic()->getId() == $topics[0]->getId()) {
93
				$this->assertTrue($subscription->isSubscribed());
94
				$this->assertFalse($subscription->isRead());
95
				$this->assertInternalType('integer', $subscription->getId());
96
			}
97
		}
98
	}
99
	
100
    public function testMarkTheseAsUnread()
101
	{
102
		$this->purge();
103
		$users = $this->addFixturesForUsers();
104
		$forums = $this->addFixturesForForums();
105
		$categories = $this->addFixturesForCategories($forums);
106
		$boards = $this->addFixturesForBoards($categories);
107
		$topics = $this->addFixturesForTopics($boards);
108
		$this->addFixturesForPosts($topics, $users['tom']);
109
		$this->getSubscriptionModel()->subscribe($topics[0], $users['tom']);
110
		$this->getSubscriptionModel()->subscribe($topics[0], $users['dick']);
111
		$this->getSubscriptionModel()->subscribe($topics[0], $users['harry']);
112
		$subscriptions = array();
113
	    $subscriptions[0] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['tom']->getId());
114
	    $subscriptions[1] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['dick']->getId());
115
	    $subscriptions[2] = $this->getSubscriptionModel()->findOneSubscriptionForTopicByIdAndUserById($topics[0]->getId(), $users['harry']->getId());
116
		$this->getSubscriptionModel()->markTheseAsUnread($subscriptions, $users['dick']);
0 ignored issues
show
Documentation introduced by
$subscriptions is of type array<integer,object<CCD...ntity\\Subscription>"}>, but the function expects a object<Doctrine\Common\C...ctions\ArrayCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
117
		$subscriptionsFound = $this->getSubscriptionModel()->findAllSubscriptionsForTopicById($topics[0]->getId(), true);
0 ignored issues
show
Unused Code introduced by
The call to SubscriptionModel::findA...criptionsForTopicById() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more 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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
118
		
119
		foreach ($subscriptionsFound as $subscription) {
120
			if ($subscription->getTopic()->getId() == $topics[0]->getId()) {
121
				$this->assertTrue($subscription->isSubscribed());
122
				$this->assertInternalType('integer', $subscription->getId());
123
				
124
				if ($subscription->getOwnedBy()->getId() == $users['dick']->getId()) {
125
					$this->assertTrue($subscription->isRead());
126
				} else {
127
					$this->assertFalse($subscription->isRead());
128
				}
129
			}
130
		}
131
	}
132
}