File: FactoryTest.php

package info (click to toggle)
phpdox 0.12.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 7,672 kB
  • sloc: xml: 80,724; php: 9,167; makefile: 13
file content (104 lines) | stat: -rw-r--r-- 3,272 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php declare(strict_types = 1);
namespace TheSeer\phpDox\Tests\Unit\DocBlock;

use TheSeer\fDOM\fDOMDocument;
use TheSeer\phpDox\DocBlock\Factory;
use TheSeer\phpDox\DocBlock\GenericParser;
use TheSeer\phpDox\DocBlock\InlineProcessor;
use TheSeer\phpDox\FactoryInterface;

/**
 * @covers \TheSeer\phpDox\DocBlock\Factory
 */
class FactoryTest extends \PHPUnit\Framework\TestCase {
    private $factory;

    /**/
    /* Dataprovider                                                      */
    /**/

    public static function addParserClassDataprovider() {
        return [
            'wrong annotation type' => [[], 'Gnu'],
            'wrong classname type'  => ['Tux', []],
        ];
    }

    protected function setUp(): void {
        $this->factory = new Factory();
    }

    /**
     * @covers \TheSeer\phpDox\DocBlock\Factory::addParserFactory
     */
    public function testAddParserFactory(): void {
        $mock = $this->createMock(FactoryInterface::class);
        $this->factory->addParserFactory('Tux', $mock);
        $this->assertAttributeContains($mock, 'parserMap', $this->factory);
    }

    /**
     * @expectedException \TheSeer\phpDox\DocBlock\FactoryException
     * @covers \TheSeer\phpDox\DocBlock\Factory::addParserFactory
     */
    public function testAddParserFactoryExpectingFactoryException(): void {
        $mock = $this->createMock(FactoryInterface::class);
        $this->factory->addParserFactory([], $mock);
    }

    /**
     * @covers \TheSeer\phpDox\DocBlock\Factory::addParserClass
     */
    public function testAddParserClass(): void {
        $this->factory->addParserClass('Tux', 'Gnu');
        $this->assertAttributeContains('Gnu', 'parserMap', $this->factory);
    }

    /**
     * @dataProvider addParserClassDataprovider
     * @expectedException \TheSeer\phpDox\DocBlock\FactoryException
     * @covers       \TheSeer\phpDox\DocBlock\Factory::addParserClass
     */
    public function testAddParserClassExpectingFactoryException($annotation, $classname): void {
        $this->factory->addParserClass($annotation, $classname);
    }

    /**
     * @covers \TheSeer\phpDox\DocBlock\Factory::getDocBlock
     *
     * @uses   \TheSeer\phpDox\DocBlock\DocBlock
     */
    public function testGetInstanceForDocBlock(): void {
        $factory = new Factory();
        $this->assertInstanceOf(
            'TheSeer\\phpDox\\DocBlock\\DocBlock',
            $factory->getDocBlock()
        );
    }

    /**
     * @covers \TheSeer\phpDox\DocBlock\Factory::getInlineProcessor
     *
     * @uses   \TheSeer\phpDox\DocBlock\InlineProcessor
     */
    public function testGetInstanceForInlineProcessor(): void {
        $factory = new Factory();
        $this->assertInstanceOf(
            InlineProcessor::class,
            $factory->getInlineProcessor(new fDOMDocument())
        );
    }

    /**
     * @covers \TheSeer\phpDox\DocBlock\Factory::getParserInstanceFor
     *
     * @uses   \TheSeer\phpDox\DocBlock\GenericParser
     */
    public function testGetParserInstanceForUnknownNameReturnsGenericParser(): void {
        $factory = new Factory();
        $this->assertInstanceOf(
            GenericParser::class,
            $factory->getParserInstanceFor('Unknown Name Parser')
        );
    }
}