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.

BoardManagerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 118
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSaveBoard() 0 9 1
A testUpdateBoard() 0 10 1
A testDeleteBoard() 0 10 1
A testReassignTopicsToBoard() 0 20 1
A testReorderBoards() 0 59 1
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 BoardManagerTest extends TestBase
20
{
21
	public function testSaveBoard()
22
	{
23
		$this->purge();
24
		$board = $this->addNewBoard('NewBoardTest', 'Generic description', 1, null, false, false);
25
		$this->getBoardModel()->saveBoard($board);
26
		
27
		$this->assertTrue(is_numeric($board->getId()));
28
		$this->assertSame('NewBoardTest', $board->getName());
29
	}
30
31
	public function testUpdateBoard()
32
	{
33
		$this->purge();
34
		$board = $this->addNewBoard('UpdateBoardTest', 'Generic Description', 1, null, true, true);
35
		$board->setName('BoardTestUpdated');
36
		$this->getBoardModel()->updateBoard($board);
37
		
38
		$this->assertTrue(is_numeric($board->getId()));
39
		$this->assertEquals('BoardTestUpdated', $board->getName());
40
	}
41
42
	public function testDeleteBoard()
43
	{
44
		$this->purge();
45
		$board = $this->addNewBoard('DeleteBoardTest', 'Generic Description', 1, null, true, true);
46
		$boardId = $board->getId();
47
		$this->getBoardModel()->deleteBoard($board);
48
		$foundBoard = $this->getBoardModel()->findOneBoardById($boardId);
49
		
50
		$this->assertNull($foundBoard);
51
	}
52
53
	public function testReassignTopicsToBoard()
54
	{
55
		$this->purge();
56
		$forum = $this->addNewForum('testReassignTopicsToBoard');
57
		$categories = $this->addFixturesForCategories(array($forum));
58
		$boards = $this->addFixturesForBoards($categories);
59
		$topics = $this->addFixturesForTopics($boards);
0 ignored issues
show
Unused Code introduced by
$topics is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
		$board1 = $boards[0];
61
		$board2 = $boards[1];
62
		$topics = new ArrayCollection($board1->getTopics()->toArray());
63
		
64
		$this->assertCount(3, $board1->getTopics());
65
		$this->getBoardModel()->reassignTopicsToBoard($topics, null);
66
		$this->em->refresh($board1);
67
		$this->assertCount(0, $board1->getTopics());
68
		
69
		$this->getBoardModel()->reassignTopicsToBoard($topics, $board2);
70
		$this->em->refresh($board2);
71
		$this->assertCount(6, $board2->getTopics());
72
	}
73
74
	const REORDER_UP = 0;
75
	const REORDER_DOWN = 1;
76
77
	public function testReorderBoards()
78
	{
79
		$this->purge();
80
		$forum = $this->addNewForum('testReorderBoards');
81
		$categories = $this->addFixturesForCategories(array($forum));
82
		$this->addFixturesForBoards($categories);
83
		
84
		$category = $categories[count($categories) - 1];
85
		$this->em->refresh($category);
86
		$boards = $category->getBoards();
87
		$this->assertCount(3, $boards);
88
89
		// 123 - Initial order.
90
		$this->assertSame('test_board_1', $boards[0]->getName());
91
		$this->assertSame('test_board_2', $boards[1]->getName());
92
		$this->assertSame('test_board_3', $boards[2]->getName());
93
		
94
		// 123 -> 213
95
		$this->getBoardModel()->reorderBoards($boards, $boards[0], $this::REORDER_DOWN);
96
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
97
		$this->assertSame('test_board_2', $boards[0]->getName());
98
		$this->assertSame('test_board_1', $boards[1]->getName());
99
		$this->assertSame('test_board_3', $boards[2]->getName());
100
101
		// 213 -> 231
102
		$this->getBoardModel()->reorderBoards($boards, $boards[1], $this::REORDER_DOWN);
0 ignored issues
show
Documentation introduced by
$boards is of type object<Doctrine\Common\C...ctions\ArrayCollection>, but the function expects a array.

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...
103
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
104
		$this->assertSame('test_board_2', $boards[0]->getName());
105
		$this->assertSame('test_board_3', $boards[1]->getName());
106
		$this->assertSame('test_board_1', $boards[2]->getName());
107
108
		// 231 -> 123
109
		$this->getBoardModel()->reorderBoards($boards, $boards[2], $this::REORDER_DOWN);
0 ignored issues
show
Documentation introduced by
$boards is of type object<Doctrine\Common\C...ctions\ArrayCollection>, but the function expects a array.

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...
110
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
111
		$this->assertSame('test_board_1', $boards[0]->getName());
112
		$this->assertSame('test_board_2', $boards[1]->getName());
113
		$this->assertSame('test_board_3', $boards[2]->getName());
114
		
115
		// 123 <- 231
116
		$this->getBoardModel()->reorderBoards($boards, $boards[0], $this::REORDER_UP);
0 ignored issues
show
Documentation introduced by
$boards is of type object<Doctrine\Common\C...ctions\ArrayCollection>, but the function expects a array.

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
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
118
		$this->assertSame('test_board_2', $boards[0]->getName());
119
		$this->assertSame('test_board_3', $boards[1]->getName());
120
		$this->assertSame('test_board_1', $boards[2]->getName());
121
		
122
		// 231 <- 213
123
		$this->getBoardModel()->reorderBoards($boards, $boards[2], $this::REORDER_UP);
0 ignored issues
show
Documentation introduced by
$boards is of type object<Doctrine\Common\C...ctions\ArrayCollection>, but the function expects a array.

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...
124
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
125
		$this->assertSame('test_board_2', $boards[0]->getName());
126
		$this->assertSame('test_board_1', $boards[1]->getName());
127
		$this->assertSame('test_board_3', $boards[2]->getName());
128
		
129
		// 213 <- 123
130
		$this->getBoardModel()->reorderBoards($boards, $boards[1], $this::REORDER_UP);
0 ignored issues
show
Documentation introduced by
$boards is of type object<Doctrine\Common\C...ctions\ArrayCollection>, but the function expects a array.

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...
131
		$boards = $this->getBoardModel()->findAllBoardsForCategoryById($category->getId());
132
		$this->assertSame('test_board_1', $boards[0]->getName());
133
		$this->assertSame('test_board_2', $boards[1]->getName());
134
		$this->assertSame('test_board_3', $boards[2]->getName());
135
	}
136
}