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

Parser::testEmptyStringContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

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 9
nc 1
nop 0
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\Parser as SUT;
15
use Bee4\RobotsTxt as LUT;
16
17
/**
18
 * Parser unit test
19
 */
20
class Parser extends atoum
21
{
22 View Code Duplication
    public function testEmptyStringContent()
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...
23
    {
24
        $this
25
            ->given($rules = SUT::parse(""))
26
            ->when($rule = $rules->get(LUT\Rules::DEFAULT_UA))
27
            ->then
28
                ->object($rules)
29
                    ->isInstanceOf('Bee4\RobotsTxt\Rules')
30
                ->object($rule)
31
                    ->isInstanceOf('Bee4\RobotsTxt\Rule');
32
    }
33
34 View Code Duplication
    public function testEmptyContentInstance()
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...
35
    {
36
        $this
37
            ->given(
38
                $content = new LUT\Content(""),
39
                $rules = SUT::parse($content)
40
            )
41
            ->when($rule = $rules->get(LUT\Rules::DEFAULT_UA))
42
            ->then
43
                ->object($rules)
44
                    ->isInstanceOf('Bee4\RobotsTxt\Rules')
45
                ->object($rule)
46
                    ->isInstanceOf('Bee4\RobotsTxt\Rule');
47
    }
48
49
    public function testInvalidContentException()
50
    {
51
        $this->exception(function () {
52
            SUT::parse(new \stdClass);
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a string|object<Bee4\RobotsTxt\Content>.

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...
53
        })
54
            ->isInstanceOf('Bee4\RobotsTxt\Exception\InvalidContentException');
55
    }
56
57
    public function testDuplicateRuleException()
58
    {
59
        $robot = <<<ROBOTS
60
User-Agent: *
61
Allow: /
62
63
User-Agent: *
64
Disallow: /toto
65
ROBOTS;
66
67
        $this
68
            ->given($content = new LUT\Content($robot))
69
            ->exception(function () use ($content) {
70
                SUT::parse($content);
71
            })
72
                ->isInstanceOf('Bee4\RobotsTxt\Exception\DuplicateRuleException');
73
    }
74
75
    public function testParse()
76
    {
77
        $robot = <<<ROBOTS
78
User-Agent: *
79
Allow: /
80
81
User-Agent: Google
82
Disallow: /toto
83
ROBOTS;
84
85
        $this
86
            ->given($rules = SUT::parse($robot))
87
            ->then
88
                ->sizeOf($rules)
89
                    ->isEqualTo(2)
90
                ->boolean($rules->match('*', '/page'))
91
                    ->isTrue()
92
                ->boolean($rules->match('Google', '/page'))
93
                    ->isTrue()
94
                ->boolean($rules->match('Google', '/toto/page'))
95
                    ->isFalse();
96
    }
97
}
98