1
|
|
|
<?php declare(strict_types=1); |
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
|
|
|
* @author Mike van Riel <[email protected]> |
10
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
12
|
|
|
* @link http://phpdoc.org |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Parser; |
16
|
|
|
|
17
|
|
|
use phpDocumentor\Parser\FileFactory; |
18
|
|
|
use phpDocumentor\Parser\Middleware\EmittingMiddleware; |
19
|
|
|
use phpDocumentor\Reflection\Php\NodesFactory; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @coversDefaultClass \phpDocumentor\Parser\FileFactory |
24
|
|
|
* @covers ::<private> |
25
|
|
|
*/ |
26
|
|
|
final class FileFactoryTest extends TestCase |
27
|
|
|
{ |
28
|
|
|
public function testIfFileFactoryIsCreatedUsingAnArray() |
29
|
|
|
{ |
30
|
|
|
FileFactory::createInstance( |
31
|
|
|
NodesFactory::createInstance(), |
32
|
|
|
new \ArrayObject([new EmittingMiddleware()]) |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
// if we reach this point then the FileFactory did not fail to instantiate and the middlewares |
36
|
|
|
// have been successfully registered. The ChainFactory inside the FileFactory will throw an |
37
|
|
|
// exception if it is unable to interpret the ArrayObject and EmittingMiddleware |
38
|
|
|
$this->assertTrue(true); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testIfFileFactoryFailsWhenPassingAnInvalidMiddlewareType() |
42
|
|
|
{ |
43
|
|
|
// technically we are testing behaviour of the ChainFactory; however, because this is the inverse of the |
44
|
|
|
// previous test we now verify that an error should indeed be thrown and we do not run the risk of silent |
45
|
|
|
// test failures just because the previous test did not fail |
46
|
|
|
$this->expectException(\InvalidArgumentException::class); |
47
|
|
|
$this->expectExceptionMessage('Middleware must be an instance of phpDocumentor\Reflection\Middleware\Middleware but stdClass was given'); |
48
|
|
|
|
49
|
|
|
FileFactory::createInstance( |
50
|
|
|
NodesFactory::createInstance(), |
51
|
|
|
new \ArrayObject([new \stdClass()]) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|