Completed
Push — master ( bb645e...4d0389 )
by Jaap
11:40 queued 08:50
created

RemoveSourcecodeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testRemovesSourceWhenDisabled() 0 12 2
A testRemovesSourceWhenSourceShouldBeIncluded() 0 13 2
A giveProjectDescriptor() 0 15 1
A testGetDescription() 0 6 1
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();
0 ignored issues
show
Bug introduced by
The method apiSetDescriptor does only exist in phpDocumentor\Faker\Provider, but not in Faker\Generator.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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();
0 ignored issues
show
Bug introduced by
The method apiSetDescriptor does only exist in phpDocumentor\Faker\Provider, but not in Faker\Generator.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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();
0 ignored issues
show
Bug introduced by
The method projectDescriptor does only exist in phpDocumentor\Faker\Provider, but not in Faker\Generator.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
69
        $projecDescriptor->setFiles(
70
            DescriptorCollection::fromClassString(
71
                DocumentationSetDescriptor::class,
72
                [$this->faker()->fileDescriptor()]
0 ignored issues
show
Bug introduced by
The method fileDescriptor does only exist in phpDocumentor\Faker\Provider, but not in Faker\Generator.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
            )
74
        );
75
76
        $versionDesciptor = $this->faker()->versionDescriptor([$apiDescriptor]);
0 ignored issues
show
Bug introduced by
The method versionDescriptor does only exist in phpDocumentor\Faker\Provider, but not in Faker\Generator.

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:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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