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]); |
|
|
|
|
20
|
|
|
static::assertTrue($parser->hasValueParser($valueParser)); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function testAddingAParser() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
/** @var ValueParserInterface|MockInterface $valueParser */ |
26
|
|
|
$valueParser = m::mock(ValueParserInterface::class); |
27
|
|
|
|
28
|
|
|
$parser = new Parser(); |
29
|
|
|
static::assertFalse($parser->hasValueParser($valueParser)); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$parser->addValueParser($valueParser); |
|
|
|
|
32
|
|
|
static::assertTrue($parser->hasValueParser($valueParser)); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testRemovingAParser() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
/** @var ValueParserInterface|MockInterface $valueParser */ |
38
|
|
|
$valueParser = m::mock(ValueParserInterface::class); |
39
|
|
|
|
40
|
|
|
$parser = new Parser([$valueParser]); |
|
|
|
|
41
|
|
|
|
42
|
|
|
static::assertTrue($parser->hasValueParser($valueParser)); |
|
|
|
|
43
|
|
|
$parser->removeValueParser($valueParser); |
|
|
|
|
44
|
|
|
static::assertFalse($parser->hasValueParser($valueParser)); |
|
|
|
|
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
|
|
|
|
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: