Completed
Push — master ( 46a5be...d136cf )
by Kacper
03:49
created

PriorityCollectionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 59.38 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 19
loc 32
rs 10
c 1
b 0
f 1
wmc 3
lcom 1
cbo 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * XMPP Library
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Tests;
17
18
19
use Kadet\Xmpp\Utils\PriorityCollection;
20
21
class PriorityCollectionTest extends \PHPUnit_Framework_TestCase
22
{
23
    public function testPriorities()
24
    {
25
        $collection = new PriorityCollection();
26
        $collection->insert(0, 0);
27
        $collection->insert(1, 1);
28
        $collection->insert(-1, -1);
29
30
        $this->assertEquals([1, 0, -1], iterator_to_array($collection));
31
    }
32
33
    public function testRemoval()
34
    {
35
        $collection = new PriorityCollection();
36
        $collection->insert(0, 0);
37
        $collection->insert(-1, -1);
38
        $collection->insert(-1, 1);
39
        $collection->remove(-1);
40
41
        $this->assertEquals([0], iterator_to_array($collection));
42
    }
43
44
    public function testCount()
45
    {
46
        $collection = new PriorityCollection();
47
        $this->assertEquals(0, count($collection));
48
        $collection->insert(0, 0);
49
        $collection->insert(-1, -1);
50
        $this->assertEquals(2, count($collection));
51
    }
52
}
53