Completed
Push — master ( bc4f39...bfef40 )
by Mantas
03:23
created

testParseLineExceptionMatcherFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * (c) Mantas Varatiejus <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace MVar\Apache2LogParser\Tests;
11
12
use MVar\Apache2LogParser\AbstractLineParser;
13
14
class AbstractLineParserTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * Creates and returns instance of AbstractLineParser mock.
18
     *
19
     * @return \PHPUnit_Framework_MockObject_MockObject|AbstractLineParser
20
     */
21
    protected function getParser()
22
    {
23
        $mock = $this->getMock(
24
            '\\MVar\\Apache2LogParser\\AbstractLineParser',
25
            ['prepareParsedData', 'getPattern']
26
        );
27
28
        return $mock;
29
    }
30
31
    /**
32
     * Test for parseLine() in case of exception when passed incorrect argument.
33
     *
34
     * @expectedException \MVar\Apache2LogParser\Exception\ParserException
35
     * @expectedExceptionMessage must be a string
36
     */
37
    public function testParseLineExceptionArgument()
38
    {
39
        $parser = $this->getParser();
40
        $parser->parseLine([123, 456]);
0 ignored issues
show
Documentation introduced by
array(123, 456) is of type array<integer,integer,{"...nteger","1":"integer"}>, but the function expects a string.

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...
Bug introduced by
The method parseLine does only exist in MVar\Apache2LogParser\AbstractLineParser, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
41
    }
42
43
    /**
44
     * Test for parseLine() in case of exception when matcher fails.
45
     *
46
     * @expectedException \MVar\Apache2LogParser\Exception\ParserException
47
     * @expectedExceptionMessage Matcher failure
48
     */
49
    public function testParseLineExceptionMatcherFailure()
50
    {
51
        $parser = $this->getParser();
52
        $parser->expects($this->once())->method('getPattern')->willReturn('invalid_regexp_pattern');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in MVar\Apache2LogParser\AbstractLineParser.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
53
54
        $parser->parseLine('test string');
0 ignored issues
show
Bug introduced by
The method parseLine does only exist in MVar\Apache2LogParser\AbstractLineParser, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
    }
56
57
    /**
58
     * Test for parseLine() in case of exception when no matches were found.
59
     *
60
     * @expectedException \MVar\Apache2LogParser\Exception\NoMatchesException
61
     * @expectedExceptionMessage line does not match
62
     */
63
    public function testParseLineExceptionNoMatches()
64
    {
65
        $parser = $this->getParser();
66
        $parser->expects($this->once())->method('getPattern')->willReturn('/\d+/');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in MVar\Apache2LogParser\AbstractLineParser.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
67
68
        $parser->parseLine('test string');
0 ignored issues
show
Bug introduced by
The method parseLine does only exist in MVar\Apache2LogParser\AbstractLineParser, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
69
    }
70
71
    /**
72
     * Test for parseLine().
73
     */
74
    public function testParseLine()
75
    {
76
        $parser = $this->getParser();
77
        $parser->expects($this->once())->method('getPattern')->willReturn('/.*/');
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in MVar\Apache2LogParser\AbstractLineParser.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
78
79
        $parser->parseLine('test string');
0 ignored issues
show
Bug introduced by
The method parseLine does only exist in MVar\Apache2LogParser\AbstractLineParser, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
80
    }
81
}
82