Test Setup Failed
Push — master ( 0c8b57...df0330 )
by Gabriel
08:06
created

DynamicTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 31.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 19
loc 60
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testSetMap() 0 8 1
A testGetVariableFromPart() 0 11 1
A testAssemble() 12 12 1
A testMatch() 7 7 1

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
namespace Nip\Router\Tests\Parsers;
4
5
use Nip\Router\Parsers\Dynamic;
6
use Nip\Router\Tests\AbstractTest;
7
8
/**
9
 * Test class for Nip_Route_Abstract.
10
 * Generated by PHPUnit on 2010-11-17 at 15:16:44.
11
 */
12
class DynamicTest extends AbstractTest
13
{
14
15
    /**
16
     * @var Dynamic
17
     */
18
    protected $object;
19
20
    /**
21
     * Sets up the fixture, for example, opens a network connection.
22
     * This method is called before a test is executed.
23
     */
24
    protected function setUp() : void
25
    {
26
        $this->object = new Dynamic();
27
    }
28
29
    public function testSetMap()
30
    {
31
        $map = 'shop/category_:url/:name';
32
        $this->object->setMap($map);
0 ignored issues
show
Documentation introduced by
$map is of type string, but the function expects a boolean.

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...
33
        static::assertEquals($map, $this->object->getMap());
34
        static::assertEquals(3, count($this->object->getParts()));
35
        static::assertEquals(['url', 'name'], $this->object->getVariables());
36
    }
37
38
    public function testGetVariableFromPart()
39
    {
40
        static::assertEquals(['url'], $this->object->getVariableFromPart(':url'));
41
        static::assertEquals(['url'], $this->object->getVariableFromPart('category_:url'));
42
        static::assertEquals(['category', 'url_shop'], $this->object->getVariableFromPart(':category:url_shop'));
43
        static::assertEquals(['category_main', 'url_shop'], $this->object->getVariableFromPart(':category_main:url_shop'));
44
        static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart(':category-:url_product'));
45
        static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart(':category-:url_product-test'));
46
        static::assertEquals(['category', 'url_product'], $this->object->getVariableFromPart('shop-:category-:url_product-test'));
47
        static::assertEquals(['category_main', 'url_product'], $this->object->getVariableFromPart('shop-:category_main-:url_product-test'));
48
    }
49
50
51 View Code Duplication
    public function testAssemble()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $params = [
54
            'url' => 'lorem',
55
            'name' => 'ipsum',
56
            'company' => 'dolo&rem',
57
        ];
58
        static::assertEquals('?url=lorem&name=ipsum&company=dolo%26rem', $this->object->assemble($params));
59
60
        $this->object->setMap('shop/category_:url/:name');
0 ignored issues
show
Documentation introduced by
'shop/category_:url/:name' is of type string, but the function expects a boolean.

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...
61
        static::assertEquals('shop/category_lorem/ipsum?company=dolo%26rem', $this->object->assemble($params));
62
    }
63
64 View Code Duplication
    public function testMatch()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $map = 'shop/category_:url/:name';
67
        $this->object->setMap($map);
0 ignored issues
show
Documentation introduced by
$map is of type string, but the function expects a boolean.

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...
68
        static::assertFalse($this->object->match('shop/category_cast/'));
69
        static::assertTrue($this->object->match('shop/category_cars/honda'));
70
    }
71
}
72