1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link https://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Transformer\Writer; |
15
|
|
|
|
16
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
17
|
|
|
use phpDocumentor\Descriptor\ApiSetDescriptor; |
18
|
|
|
use phpDocumentor\Descriptor\Collection as DescriptorCollection; |
19
|
|
|
use phpDocumentor\Descriptor\DocumentationSetDescriptor; |
20
|
|
|
use phpDocumentor\Descriptor\FileDescriptor; |
21
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
22
|
|
|
use phpDocumentor\Faker\Faker; |
23
|
|
|
use phpDocumentor\Transformer\Transformation; |
24
|
|
|
use Prophecy\Argument; |
25
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @coversDefaultClass \phpDocumentor\Transformer\Writer\Sourcecode |
29
|
|
|
* @covers ::__construct |
30
|
|
|
* @covers ::<private> |
31
|
|
|
*/ |
32
|
|
|
final class SourcecodeTest extends MockeryTestCase |
33
|
|
|
{ |
34
|
|
|
use Faker; |
35
|
|
|
use ProphecyTrait; |
36
|
|
|
|
37
|
|
|
/** @var Graph */ |
38
|
|
|
private $sourceCode; |
39
|
|
|
|
40
|
|
|
protected function setUp() : void |
41
|
|
|
{ |
42
|
|
|
$pathGenerator = $this->prophesize(PathGenerator::class); |
43
|
|
|
$pathGenerator->generate( |
44
|
|
|
Argument::type(FileDescriptor::class), |
45
|
|
|
Argument::type(Transformation::class) |
46
|
|
|
)->willReturn((string) $this->faker()->path()); |
|
|
|
|
47
|
|
|
$this->sourceCode = new Sourcecode( |
|
|
|
|
48
|
|
|
$pathGenerator->reveal() |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @covers ::transform |
54
|
|
|
*/ |
55
|
|
|
public function testNoInteractionWithTransformationWhenSourceShouldNotIncluded() : void |
56
|
|
|
{ |
57
|
|
|
$transformation = $this->prophesize(Transformation::class); |
58
|
|
|
$transformation->template()->shouldNotBeCalled(); |
59
|
|
|
|
60
|
|
|
$projecDescriptor = $this->giveProjectDescriptor($this->faker()->apiSetDescriptor()); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->sourceCode->transform($projecDescriptor, $transformation->reveal()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers ::transform |
67
|
|
|
*/ |
68
|
|
|
public function testNoInteractionWithTransformationWhenSourceIsIncluded() : void |
69
|
|
|
{ |
70
|
|
|
$transformation = $this->prophesize(Transformation::class); |
71
|
|
|
$transformation->template()->shouldBeCalled()->willReturn($this->faker()->template()); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$api = $this->faker()->apiSetDescriptor(); |
|
|
|
|
74
|
|
|
$api->getSettings()['include-source'] = true; |
75
|
|
|
$projecDescriptor = $this->giveProjectDescriptor($api); |
76
|
|
|
|
77
|
|
|
$this->sourceCode->transform($projecDescriptor, $transformation->reveal()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
private function giveProjectDescriptor(ApiSetDescriptor $apiDescriptor) : ProjectDescriptor |
81
|
|
|
{ |
82
|
|
|
$projecDescriptor = $this->faker()->projectDescriptor(); |
|
|
|
|
83
|
|
|
$projecDescriptor->setFiles( |
84
|
|
|
DescriptorCollection::fromClassString( |
85
|
|
|
DocumentationSetDescriptor::class, |
86
|
|
|
[$this->faker()->fileDescriptor()] |
|
|
|
|
87
|
|
|
) |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$versionDesciptor = $this->faker()->versionDescriptor([$apiDescriptor]); |
|
|
|
|
91
|
|
|
$projecDescriptor->getVersions()->add($versionDesciptor); |
92
|
|
|
|
93
|
|
|
return $projecDescriptor; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: