1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/csv-token |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/csv-token/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/csv-token |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\CsvToken\Test\Unit\ValueParser; |
15
|
|
|
|
16
|
|
|
use Akamon\MockeryCallableMock\MockeryCallableMock; |
17
|
|
|
use Graze\CsvToken\Test\TestCase; |
18
|
|
|
use Graze\CsvToken\ValueParser\CallbackValueParser; |
19
|
|
|
use Mockery as m; |
20
|
|
|
|
21
|
|
|
class CallbackValueParserTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** @var MockeryCallableMock */ |
24
|
|
|
private $canParse; |
25
|
|
|
/** @var MockeryCallableMock */ |
26
|
|
|
private $parse; |
27
|
|
|
/** @var CallbackValueParser */ |
28
|
|
|
private $parser; |
29
|
|
|
|
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->canParse = new MockeryCallableMock(); |
33
|
|
|
$this->parse = new MockeryCallableMock(); |
34
|
|
|
$this->parser = new CallbackValueParser($this->canParse, $this->parse); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testCanParseCallback() |
38
|
|
|
{ |
39
|
|
|
$this->canParse->shouldBeCalled() |
40
|
|
|
->with('string') |
41
|
|
|
->andReturn(true, false); |
42
|
|
|
|
43
|
|
|
static::assertTrue($this->parser->canParseValue('string')); |
44
|
|
|
static::assertFalse($this->parser->canParseValue('string')); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testParseCallback() |
48
|
|
|
{ |
49
|
|
|
$this->parse->shouldBeCalled() |
50
|
|
|
->with('text') |
51
|
|
|
->andReturn('first', 'second'); |
52
|
|
|
|
53
|
|
|
static::assertEquals('first', $this->parser->parseValue('text')); |
54
|
|
|
static::assertEquals('second', $this->parser->parseValue('text')); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|