Completed
Push — develop ( ad187c...f818a7 )
by Jaap
09:04
created

FileConstantsTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 12

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testInterpretThisCommand() 0 28 1
A testDontInterpretWithANonFileSubject() 0 9 1
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\DocBlock;
21
use phpDocumentor\Reflection\Php\File as FileType;
22
use phpDocumentor\Reflection\Php\Constant as ConstantType;
23
use phpDocumentor\Reflection\Fqsen as FqsenType;
24
use phpDocumentor\Reflection\Types\Context;
25
26
/**
27
 * Class FileTest
28
 * @coversDefaultClass phpDocumentor\Application\ReadModel\Mapper\Project\FileConstants
29
 */
30
class FileConstantsTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @covers ::__invoke()
34
     * @covers ::convertItems()
35
     * @covers ::convertItem()
36
     */
37
    public function testInterpretThisCommand()
38
    {
39
        $fileType = new FileType(
40
            'ecdc2862f54ccb495a53c469e83d45ff',
41
            'my/subdirectory/file.php',
42
            'the source of the file'
43
        );
44
        $fileType->addConstant(new ConstantType(new FqsenType('\namespace\class::myConstant')));
45
        $context = new Context('Namespace');
46
        $command = new Interpret($fileType, $context);
47
        $reducerStub = new ReducerStub();
48
49
        $interpreter = new Interpreter(
50
            [
51
                new FileConstants(),
52
                $reducerStub
53
            ]
54
        );
55
        $command = $command->usingInterpreter($interpreter);
56
57
        $fileConstants = new FileConstants();
58
59
        $state = $fileConstants($command, null);
60
        $expectedState = ['constants' => ['myConstant' => 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
        $fileConstants = new FileConstants();
75
76
        $fileConstants($command, null);
77
    }
78
}
79