Completed
Push — master ( 580007...3ce141 )
by
unknown
9s
created

testAvailableVersionIsNotShownWhenSameAsCurrent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace BringYourOwnIdeas\UpdateChecker\Tests\Extensions;
4
5
use BringYourOwnIdeas\UpdateChecker\Extensions\ComposerUpdateExtension;
6
use Package;
7
use PHPUnit_Framework_TestCase;
8
use SapphireTest;
9
10
/**
11
 * @mixin PHPUnit_Framework_TestCase
12
 */
13
class ComposerUpdateExtensionTest extends SapphireTest
14
{
15
    protected static $fixture_file = 'ComposerUpdateExtensionTest.yml';
16
17
    protected $requiredExtensions = [
18
        Package::class => [
19
            ComposerUpdateExtension::class,
20
        ],
21
    ];
22
23
    public function testAvailableVersionIsNotShownWhenSameAsCurrent()
24
    {
25
        /** @var Package|ComposerUpdateExtension $package */
26
        $package = $this->objFromFixture(Package::class, 'up_to_date');
27
        $this->assertEmpty($package->getAvailableVersion());
0 ignored issues
show
Bug introduced by
The method getAvailableVersion does only exist in BringYourOwnIdeas\Update...ComposerUpdateExtension, but not in Package.

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...
Bug introduced by
The method assertEmpty() does not seem to exist on object<BringYourOwnIdeas...serUpdateExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
    }
29
30
    public function testAvailableVersionIsShown()
31
    {
32
        /** @var Package|ComposerUpdateExtension $package */
33
        $package = $this->objFromFixture(Package::class, 'has_available_update');
34
        $this->assertSame('1.2.1', $package->getAvailableVersion());
0 ignored issues
show
Bug introduced by
The method getAvailableVersion does only exist in BringYourOwnIdeas\Update...ComposerUpdateExtension, but not in Package.

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...
Bug introduced by
The method assertSame() does not seem to exist on object<BringYourOwnIdeas...serUpdateExtensionTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
    }
36
}
37