Completed
Push — master ( e8fccd...9c2126 )
by Harry
02:44
created

testParserIteratesSoNothingShouldHappenIfThereIsNoRequestForData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Graze\CsvToken\Test\Unit;
4
5
use Graze\CsvToken\Parser;
6
use Graze\CsvToken\Test\TestCase;
7
use Graze\CsvToken\ValueParser\ValueParserInterface;
8
use Iterator;
9
use Mockery as m;
10
use Mockery\MockInterface;
11
12
class ParserTest extends TestCase
13
{
14
    public function testConstructorValueParsers()
15
    {
16
        /** @var ValueParserInterface|MockInterface $valueParser */
17
        $valueParser = m::mock(ValueParserInterface::class);
18
19
        $parser = new Parser([$valueParser]);
0 ignored issues
show
Documentation introduced by
array($valueParser) is of type array<integer,object<Gra...kery\\MockInterface>"}>, but the function expects a array<integer,object<Gra...\ValueParserInterface>>.

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...
20
        static::assertTrue($parser->hasValueParser($valueParser));
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 17 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::hasValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
21
    }
22
23 View Code Duplication
    public function testAddingAParser()
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...
24
    {
25
        /** @var ValueParserInterface|MockInterface $valueParser */
26
        $valueParser = m::mock(ValueParserInterface::class);
27
28
        $parser = new Parser();
29
        static::assertFalse($parser->hasValueParser($valueParser));
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 26 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::hasValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
30
31
        $parser->addValueParser($valueParser);
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 26 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::addValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
32
        static::assertTrue($parser->hasValueParser($valueParser));
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 26 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::hasValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
33
    }
34
35 View Code Duplication
    public function testRemovingAParser()
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...
36
    {
37
        /** @var ValueParserInterface|MockInterface $valueParser */
38
        $valueParser = m::mock(ValueParserInterface::class);
39
40
        $parser = new Parser([$valueParser]);
0 ignored issues
show
Documentation introduced by
array($valueParser) is of type array<integer,object<Gra...kery\\MockInterface>"}>, but the function expects a array<integer,object<Gra...\ValueParserInterface>>.

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...
41
42
        static::assertTrue($parser->hasValueParser($valueParser));
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 38 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::hasValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
        $parser->removeValueParser($valueParser);
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 38 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::removeValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
44
        static::assertFalse($parser->hasValueParser($valueParser));
0 ignored issues
show
Bug introduced by
It seems like $valueParser defined by \Mockery::mock(\Graze\Cs...ParserInterface::class) on line 38 can also be of type object<Mockery\MockInterface>; however, Graze\CsvToken\Parser::hasValueParser() does only seem to accept object<Graze\CsvToken\Va...r\ValueParserInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
45
    }
46
47
    public function testParserIteratesSoNothingShouldHappenIfThereIsNoRequestForData()
48
    {
49
        $parser = new Parser();
50
51
        $tokens = m::mock(Iterator::class);
52
53
        $output = $parser->parse($tokens);
54
55
        static::assertInstanceOf(Iterator::class, $output);
56
    }
57
}
58