Completed
Push — master ( 0446fa...04d0ad )
by Jaap
32s queued 11s
created

SourceTest::testSourceReturnsDsn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Configuration;
6
7
use BadMethodCallException;
8
use phpDocumentor\Faker\Faker;
9
use phpDocumentor\Path;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * @coversDefaultClass \phpDocumentor\Configuration\Source
14
 */
15
final class SourceTest extends TestCase
16
{
17
    use Faker;
18
19
    /**
20
     * @uses \phpDocumentor\Dsn
21
     *
22
     * @covers ::__construct
23
     * @covers ::dsn
24
     */
25
    public function testSourceReturnsDsn() : void
26
    {
27
        $dsn = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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...
28
        $source = new Source($dsn, []);
29
30
        self::assertSame($dsn, $source->dsn());
31
    }
32
33
    /**
34
     * @uses \phpDocumentor\Dsn
35
     *
36
     * @covers ::__construct
37
     * @covers ::dsn
38
     * @covers ::withDsn
39
     */
40
    public function testWithDsnReturnsNewInstanceOfSource() : void
41
    {
42
        $dsn = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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...
43
        $source = new Source($dsn, []);
44
45
        $newSource = $source->withDsn($dsn);
46
47
        self::assertEquals($newSource, $source);
48
        self::assertNotSame($newSource, $source);
49
    }
50
51
    /**
52
     * @uses \phpDocumentor\Dsn
53
     *
54
     * @covers ::__construct
55
     * @covers ::dsn
56
     * @covers ::withDsn
57
     */
58
    public function testWithDsnReturnsSetsNewDsn() : void
59
    {
60
        $dsn = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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
        $source = new Source($dsn, []);
62
63
        $newDsn = $this->faker()->dsn();
64
        $newSource = $source->withDsn($newDsn);
65
66
        self::assertSame($newDsn, $newSource->dsn());
67
        self::assertSame($dsn, $source->dsn());
68
    }
69
70
    /**
71
     * @covers ::__construct
72
     * @covers ::offsetGet
73
     */
74
    public function testSourceImplementsArrayAccess() : void
75
    {
76
        $dsn = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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
        $paths = [
78
            $this->faker->path(),
79
            $this->faker->path(),
80
        ];
81
82
        $source = new Source($dsn, $paths);
83
84
        self::assertSame($dsn, $source['dsn']);
85
        self::assertSame($paths, $source['paths']);
86
    }
87
88
    /**
89
     * @covers ::__construct
90
     * @covers ::offsetSet
91
     */
92
    public function testSourceArrayAccessIsImmutableCannotSet() : void
93
    {
94
        $this->expectException(BadMethodCallException::class);
95
        $dsn   = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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...
96
        $paths = [
97
            $this->faker->path(),
98
            $this->faker->path(),
99
        ];
100
101
        $source = new Source($dsn, $paths);
102
103
        $source['paths'] = [];
104
    }
105
106
    /**
107
     * @covers ::__construct
108
     * @covers ::offsetUnset
109
     */
110
    public function testSourceArrayAccessIsImmutableCannotUnset() : void
111
    {
112
        $this->expectException(BadMethodCallException::class);
113
        $dsn   = $this->faker()->dsn();
0 ignored issues
show
Bug introduced by
The method dsn 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...
114
        $paths = [
115
            $this->faker->path(),
116
            $this->faker->path(),
117
        ];
118
119
        $source = new Source($dsn, $paths);
120
121
        unset($source['paths']);
122
    }
123
124
    /**
125
     * @dataProvider pathProvider
126
     * @covers ::__construct
127
     * @covers ::globPatterns
128
     * @covers ::<private>
129
     */
130
    public function testSourceGlobPathsNormalizesPaths(Path $input, string $glob) : void
131
    {
132
        $source = new Source($this->faker()->dsn(), [$input]);
0 ignored issues
show
Bug introduced by
The method dsn 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...
133
134
        self::assertEquals([$glob], $source->globPatterns());
135
    }
136
137
    public function pathProvider() : array
138
    {
139
        return [
140
            [
141
                new Path('src'),
142
                '/src/**/*',
143
            ],
144
            [
145
                new Path('.'),
146
                '/**/*',
147
            ],
148
            [
149
                new Path('./src'),
150
                '/src/**/*',
151
            ],
152
            [
153
                new Path('/src/*'),
154
                '/src/*',
155
            ],
156
            [
157
                new Path('src/dir/test.php'),
158
                '/src/dir/test.php',
159
            ],
160
        ];
161
    }
162
}
163