Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

testCanUseCryptoKeysFromConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\Hello\Tests\Oauth\ServiceProvider\Traits;
4
5
use ByTIC\Hello\HelloServiceProvider;
6
use ByTIC\Hello\Tests\AbstractTest;
7
use ByTIC\Hello\Utility\ConfigHelper;
8
use Mockery as m;
9
use Nip\Container\Container;
10
11
/**
12
 * Class CryptKeysTraitTest
13
 * @package ByTIC\Hello\Tests\Oauth\ServiceProvider\Traits
14
 */
15
class CryptKeysTraitTest extends AbstractTest
16
{
17
18
    public function testCanUseCryptoKeysFromConfig()
19
    {
20
        $config = m::mock(ConfigHelper::class)->makePartial();
21
        $config->shouldReceive('get')
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, but not in Mockery\HigherOrderMessage.

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...
22
//            ->with('private_key', null)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
            ->andReturn('-----BEGIN RSA PRIVATE KEY-----\nconfig\n-----END RSA PRIVATE KEY-----');
24
25
        $provider = new HelloServiceProvider();
26
        $provider->setContainer(new Container());
27
28
        ConfigHelper::setConfig($config);
0 ignored issues
show
Documentation introduced by
$config is of type object<Mockery\Mock>, but the function expects a object<Nip\Config\Config>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
30
        // Call protected makeCryptKey method
31
        $cryptKey = (function () {
32
            return $this->makeCryptKey('private');
0 ignored issues
show
Bug introduced by
The method makeCryptKey() does not seem to exist on object<ByTIC\Hello\Tests...its\CryptKeysTraitTest>.

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...
33
        })->call($provider);
34
35
        static::assertSame(
36
            "-----BEGIN RSA PRIVATE KEY-----\nconfig\n-----END RSA PRIVATE KEY-----",
37
            file_get_contents($cryptKey->getKeyPath())
38
        );
39
    }
40
}