CatchableErrorActionTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_constructs_with_two_actions() 0 5 1
A test_execute_calls_first_action() 0 15 1
A test_execute_calls_second_action_if_first_throws_exception_and_add_exception_to_context() 0 24 1
A getActionMock() 0 4 1
A getContextMock() 0 4 1
1
<?php
2
3
namespace LightSaml\Tests\Action;
4
5
use LightSaml\Action\ActionInterface;
6
use LightSaml\Action\CatchableErrorAction;
7
use LightSaml\Context\AbstractContext;
8
use LightSaml\Context\ContextInterface;
9
use LightSaml\Context\Profile\ExceptionContext;
10
use LightSaml\Context\Profile\ProfileContext;
11
use LightSaml\Context\Profile\ProfileContexts;
12
use LightSaml\Tests\BaseTestCase;
13
14
class CatchableErrorActionTest extends BaseTestCase
15
{
16
    public function test_constructs_with_two_actions()
17
    {
18
        new CatchableErrorAction($this->getActionMock(), $this->getActionMock());
0 ignored issues
show
Documentation introduced by
$this->getActionMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Action\ActionInterface>.

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...
19
        $this->assertTrue(true);
20
    }
21
22
    public function test_execute_calls_first_action()
23
    {
24
        $mainAction =  new CatchableErrorAction(
25
            $firstAction = $this->getActionMock(),
0 ignored issues
show
Documentation introduced by
$firstAction = $this->getActionMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Action\ActionInterface>.

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...
26
            $secondAction = $this->getActionMock()
0 ignored issues
show
Documentation introduced by
$secondAction = $this->getActionMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Action\ActionInterface>.

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...
27
        );
28
        $context = $this->getContextMock();
29
        $firstAction->expects($this->once())
30
            ->method('execute')
31
            ->with($context);
32
        $secondAction->expects($this->never())
33
            ->method('execute');
34
35
        $mainAction->execute($context);
0 ignored issues
show
Documentation introduced by
$context is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Context\ContextInterface>.

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...
36
    }
37
38
    public function test_execute_calls_second_action_if_first_throws_exception_and_add_exception_to_context()
39
    {
40
        $mainAction =  new CatchableErrorAction(
41
            $firstAction = $this->getActionMock(),
0 ignored issues
show
Documentation introduced by
$firstAction = $this->getActionMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Action\ActionInterface>.

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...
42
            $secondAction = $this->getActionMock()
0 ignored issues
show
Documentation introduced by
$secondAction = $this->getActionMock() is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Action\ActionInterface>.

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...
43
        );
44
        $context = $this->getContextMock();
45
        $firstAction->expects($this->once())
46
            ->method('execute')
47
            ->with($context)
48
            ->willThrowException($exception = new \Exception());
49
        $secondAction->expects($this->once())
50
            ->method('execute')
51
            ->with($context)
52
        ;
53
54
        $mainAction->execute($context);
0 ignored issues
show
Documentation introduced by
$context is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LightSaml\Context\ContextInterface>.

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...
55
56
        /** @var ExceptionContext $exceptionContext */
57
        $exceptionContext = $context->getSubContext(ProfileContexts::EXCEPTION);
0 ignored issues
show
Bug introduced by
The method getSubContext() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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...
58
        $this->assertNotNull($exceptionContext);
59
        $this->assertInstanceOf(ExceptionContext::class, $exceptionContext);
60
        $this->assertSame($exception, $exceptionContext->getException());
61
    }
62
63
    /**
64
     * @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Action\ActionInterface
65
     */
66
    private function getActionMock()
67
    {
68
        return $this->getMockBuilder(ActionInterface::class)->getMock();
69
    }
70
71
    /**
72
     * @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Context\ContextInterface
73
     */
74
    private function getContextMock()
75
    {
76
        return $this->getMockForAbstractClass(AbstractContext::class);
77
    }
78
}
79