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

testNoInteractionWithTransformationWhenSourceIsIncluded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
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());
0 ignored issues
show
Bug introduced by
The method path 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...
47
        $this->sourceCode = new Sourcecode(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \phpDocumentor\Trans...athGenerator->reveal()) of type object<phpDocumentor\Tra...rmer\Writer\Sourcecode> is incompatible with the declared type object<phpDocumentor\Transformer\Writer\Graph> of property $sourceCode.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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());
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...
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());
0 ignored issues
show
Bug introduced by
The method template 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...
72
73
        $api = $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...
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();
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...
83
        $projecDescriptor->setFiles(
84
            DescriptorCollection::fromClassString(
85
                DocumentationSetDescriptor::class,
86
                [$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...
87
            )
88
        );
89
90
        $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...
91
        $projecDescriptor->getVersions()->add($versionDesciptor);
92
93
        return $projecDescriptor;
94
    }
95
}
96