Completed
Push — develop ( 183c36...cfc9ab )
by Stéphane
02:42
created

Expression::testContained()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 11
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
/**
3
 * This file is part of the beebot package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2016
8
 * @author    Stephane HULARD <[email protected]>
9
 */
10
11
namespace Bee4\RobotsTxt\Test\Units;
12
13
use mageekguy\atoum;
14
use Bee4\RobotsTxt\Expression as SUT;
15
16
/**
17
 * Expression unit test
18
 */
19
class Expression extends atoum
20
{
21
    public function patternDataProvider()
22
    {
23
        return [
24
            ['/page-1.html', '\/page\-1\.html.*'],
25
            ['/page-1.html$', '\/page\-1\.html'],
26
            ['/page*/dossier.html', '\/page.*\/dossier\.html.*'],
27
            ['/page*/dossier.html$', '\/page.*\/dossier\.html'],
28
            ['/page+1$', '\/page\+1'],
29
            ['/page+1?query=toto$', '\/page\+1\?query\=toto'],
30
            ['/page+1?query[0]=foo&query[1]=bar$', '\/page\+1\?query\[0\]\=foo&query\[1\]\=bar'],
31
        ];
32
    }
33
34
    /**
35
     * @dataProvider patternDataProvider
36
     */
37
    public function testPattern($exp, $pattern)
38
    {
39
        $this
40
            ->given($sut = new SUT($exp))
41
            ->then
42
                ->string($sut->getRaw())
43
                    ->isEqualTo($exp)
44
                ->castToString($sut)
45
                    ->isEqualTo($pattern);
46
    }
47
48
    public function containsDataProvider()
49
    {
50
        return [
51
            ['/page-1', '/page-1/dossier.html', true],
52
            ['/page-1$', '/page-1/dossier.html', false],
53
            ['/page*', '/page-1/dossier.html', true],
54
            ['/page*', '/page*/dossier.html', true],
55
        ];
56
    }
57
58
    /**
59
     * @dataProvider containsDataProvider
60
     */
61 View Code Duplication
    public function testContains($exp, $exp2, $contains)
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...
62
    {
63
        $this
64
            ->given(
65
                $sut = new SUT($exp),
66
                $sut2 = new SUT($exp2)
67
            )
68
            ->then
69
                ->boolean($sut->contains($sut2))
70
                    ->isEqualTo($contains);
71
    }
72
73
    /**
74
     * @dataProvider containsDataProvider
75
     */
76 View Code Duplication
    public function testContained($exp, $exp2, $contained)
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...
77
    {
78
        $this
79
            ->given(
80
                $sut = new SUT($exp),
81
                $sut2 = new SUT($exp2)
82
            )
83
            ->then
84
                ->boolean($sut2->contained($sut))
85
                    ->isEqualTo($contained);
86
    }
87
}
88