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\Compiler\Pass; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Descriptor\ApiSetDescriptor; |
17
|
|
|
use phpDocumentor\Descriptor\Collection as DescriptorCollection; |
18
|
|
|
use phpDocumentor\Descriptor\DocumentationSetDescriptor; |
19
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
20
|
|
|
use phpDocumentor\Faker\Faker; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @coversDefaultClass \phpDocumentor\Compiler\Pass\RemoveSourcecode |
26
|
|
|
* @covers ::<private> |
27
|
|
|
*/ |
28
|
|
|
final class RemoveSourcecodeTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
use Faker; |
31
|
|
|
use ProphecyTrait; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @covers ::execute |
35
|
|
|
*/ |
36
|
|
|
public function testRemovesSourceWhenDisabled() : void |
37
|
|
|
{ |
38
|
|
|
$apiSetDescriptor = $this->faker()->apiSetDescriptor(); |
|
|
|
|
39
|
|
|
$projectDescriptor = $this->giveProjectDescriptor($apiSetDescriptor); |
40
|
|
|
$fixture = new RemoveSourcecode(); |
41
|
|
|
|
42
|
|
|
$fixture->execute($projectDescriptor); |
43
|
|
|
|
44
|
|
|
foreach ($projectDescriptor->getFiles() as $file) { |
45
|
|
|
self::assertNull($file->getSource()); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers ::execute |
51
|
|
|
*/ |
52
|
|
|
public function testRemovesSourceWhenSourceShouldBeIncluded() : void |
53
|
|
|
{ |
54
|
|
|
$apiSetDescriptor = $this->faker()->apiSetDescriptor(); |
|
|
|
|
55
|
|
|
$apiSetDescriptor->getSettings()['include-source'] = true; |
56
|
|
|
$projectDescriptor = $this->giveProjectDescriptor($apiSetDescriptor); |
57
|
|
|
$fixture = new RemoveSourcecode(); |
58
|
|
|
|
59
|
|
|
$fixture->execute($projectDescriptor); |
60
|
|
|
|
61
|
|
|
foreach ($projectDescriptor->getFiles() as $file) { |
62
|
|
|
self::assertNotNull($file->getSource()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function giveProjectDescriptor(ApiSetDescriptor $apiDescriptor) : ProjectDescriptor |
67
|
|
|
{ |
68
|
|
|
$projecDescriptor = $this->faker()->projectDescriptor(); |
|
|
|
|
69
|
|
|
$projecDescriptor->setFiles( |
70
|
|
|
DescriptorCollection::fromClassString( |
71
|
|
|
DocumentationSetDescriptor::class, |
72
|
|
|
[$this->faker()->fileDescriptor()] |
|
|
|
|
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$versionDesciptor = $this->faker()->versionDescriptor([$apiDescriptor]); |
|
|
|
|
77
|
|
|
$projecDescriptor->getVersions()->add($versionDesciptor); |
78
|
|
|
|
79
|
|
|
return $projecDescriptor; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @covers ::getDescription |
84
|
|
|
*/ |
85
|
|
|
public function testGetDescription() : void |
86
|
|
|
{ |
87
|
|
|
$pass = new RemoveSourcecode(); |
88
|
|
|
|
89
|
|
|
self::assertSame('Removing sourcecode from file descriptors', $pass->getDescription()); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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: