1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of phpDocumentor. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @copyright 2010-2016 Mike van Riel<[email protected]> |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Application\ReadModel\Mapper\Project; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\Application\ReadModel\Mapper\Project\Interpret; |
18
|
|
|
use phpDocumentor\DomainModel\ReadModel\Mapper\Project\Interpret as InterpretInterface; |
19
|
|
|
use phpDocumentor\DomainModel\ReadModel\Mapper\Project\Interpreter; |
20
|
|
|
use phpDocumentor\Reflection\Php\File as FileType; |
21
|
|
|
use phpDocumentor\Reflection\Php\Trait_ as TraitType; |
22
|
|
|
use phpDocumentor\Reflection\Fqsen as FqsenType; |
23
|
|
|
use phpDocumentor\Reflection\Types\Context; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class FileTest |
27
|
|
|
* @coversDefaultClass phpDocumentor\Application\ReadModel\Mapper\Project\FileTraits |
28
|
|
|
*/ |
29
|
|
|
class FileTraitsTest extends \PHPUnit_Framework_TestCase |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @covers ::__invoke() |
33
|
|
|
* @covers ::convertItems() |
34
|
|
|
* @covers ::convertItem() |
35
|
|
|
*/ |
36
|
|
|
public function testInterpretThisCommand() |
37
|
|
|
{ |
38
|
|
|
$fileType = new FileType( |
39
|
|
|
'ecdc2862f54ccb495a53c469e83d45ff', |
40
|
|
|
'my/subdirectory/file.php', |
41
|
|
|
'the source of the file' |
42
|
|
|
); |
43
|
|
|
$fileType->addTrait(new TraitType(new FqsenType('\MyTrait'))); |
44
|
|
|
$context = new Context('Namespace'); |
45
|
|
|
$command = new Interpret($fileType, $context); |
46
|
|
|
$reducerStub = new ReducerStub(); |
47
|
|
|
|
48
|
|
|
$interpreter = new Interpreter( |
49
|
|
|
[ |
50
|
|
|
new FileTraits(), |
51
|
|
|
$reducerStub |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
$command = $command->usingInterpreter($interpreter); |
55
|
|
|
|
56
|
|
|
$fileTraits = new FileTraits(); |
57
|
|
|
|
58
|
|
|
$state = $fileTraits($command, null); |
59
|
|
|
|
60
|
|
|
$expectedState = ['traits' => ['MyTrait' => null]]; |
61
|
|
|
|
62
|
|
|
$this->assertSame($reducerStub->isCalled, 3); |
63
|
|
|
$this->assertSame($expectedState, $state); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @covers ::__invoke() |
68
|
|
|
*/ |
69
|
|
|
public function testDontInterpretWithANonFileSubject() |
70
|
|
|
{ |
71
|
|
|
$command = m::mock(InterpretInterface::class); |
72
|
|
|
$command->shouldReceive('subject')->once()->andReturn(new \stdClass()); |
73
|
|
|
$command->shouldReceive('interpreter->next')->once()->with($command, null); |
74
|
|
|
$fileTraits = new FileTraits(); |
75
|
|
|
|
76
|
|
|
$fileTraits($command, null); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|