DefaultTransitionControllerTest::test__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 4
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) 2019, Wesley O. Nichols
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Wesnick\WorkflowBundle\Tests\Controller;
13
14
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Prophecy\Argument;
0 ignored issues
show
Bug introduced by
The type Prophecy\Argument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
17
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
18
use Symfony\Component\Workflow\Registry;
19
use Symfony\Component\Workflow\Tests\WorkflowBuilderTrait;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Workfl...ts\WorkflowBuilderTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\Workflow\Workflow;
21
use Wesnick\WorkflowBundle\Controller\DefaultTransitionController;
22
use Wesnick\WorkflowBundle\Model\WorkflowDTO;
23
24
/**
25
 * Class DefaultTransitionControllerTest.
26
 */
27
class DefaultTransitionControllerTest extends TestCase
28
{
29
    use WorkflowBuilderTrait;
30
31
    public function testInvalidSubjectThrowsException()
32
    {
33
        $definition = $this->createComplexWorkflowDefinition();
34
        $workflow = new Workflow($definition, new MultipleStateMarkingStore());
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Workfl...ltipleStateMarkingStore has been deprecated: since Symfony 4.3, use MethodMarkingStore instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

34
        $workflow = new Workflow($definition, /** @scrutinizer ignore-deprecated */ new MultipleStateMarkingStore());
Loading history...
35
36
        $registry = $this->createRegistry($workflow);
37
        $controller = new DefaultTransitionController($registry->reveal());
38
39
        $this->expectException(BadRequestHttpException::class);
40
        $this->expectExceptionMessage('Expected object for workflow "workflow", got array');
41
        $controller(new WorkflowDTO(), [], 'workflow', 'transition');
42
    }
43
44
    /**
45
     * @dataProvider workflowProvider
46
     */
47
    public function test__invoke($workflow, $subject, $transition, bool $success)
48
    {
49
        $registry = $this->createRegistry($workflow, $success);
0 ignored issues
show
Unused Code introduced by
The call to Wesnick\WorkflowBundle\T...rTest::createRegistry() has too many arguments starting with $success. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        /** @scrutinizer ignore-call */ 
50
        $registry = $this->createRegistry($workflow, $success);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
50
        $controller = new DefaultTransitionController($registry->reveal());
51
52
        if (!$success) {
53
            $this->expectException(BadRequestHttpException::class);
54
            $this->expectExceptionMessage(sprintf('Transition "%s" in Workflow "workflow" is not available.', $transition));
55
        }
56
57
        $result = $controller(new WorkflowDTO(), $subject, 'workflow', $transition);
58
59
        $this->assertSame($subject, $result);
60
        $this->assertFalse($workflow->can($subject, $transition));
61
    }
62
63
    public function workflowProvider()
64
    {
65
        $definition = $this->createComplexWorkflowDefinition();
66
        $workflow = new Workflow($definition, new MultipleStateMarkingStore());
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Workfl...ltipleStateMarkingStore has been deprecated: since Symfony 4.3, use MethodMarkingStore instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

66
        $workflow = new Workflow($definition, /** @scrutinizer ignore-deprecated */ new MultipleStateMarkingStore());
Loading history...
67
68
        $subject = new \stdClass();
69
        $subject->marking = null;
70
        yield [$workflow, $subject, 't1', true];
71
72
        $subject = new \stdClass();
73
        $subject->marking = null;
74
        yield [$workflow, $subject, 't2', false];
75
76
        $subject = new \stdClass();
77
        $subject->marking = ['b' => 1];
78
        yield [$workflow, $subject, 't1', false];
79
80
        $subject = new \stdClass();
81
        $subject->marking = ['b' => 1];
82
        yield [$workflow, $subject, 't2', false];
83
84
        $subject = new \stdClass();
85
        $subject->marking = ['b' => 1, 'c' => 1];
86
        yield [$workflow, $subject, 't1', false];
87
88
        $subject = new \stdClass();
89
        $subject->marking = ['b' => 1, 'c' => 1];
90
        yield [$workflow, $subject, 't2', true];
91
92
        $subject = new \stdClass();
93
        $subject->marking = ['f' => 1];
94
        yield [$workflow, $subject, 't5', false];
95
96
        $subject = new \stdClass();
97
        $subject->marking = ['f' => 1];
98
        yield [$workflow, $subject, 't6', true];
99
    }
100
101
    private function createRegistry(Workflow $workflow)
102
    {
103
        $registry = $this->prophesize(Registry::class);
104
        $registry->get(Argument::type(\stdClass::class), Argument::type('string'))
105
            ->willReturn($workflow)
106
        ;
107
108
        return $registry;
109
    }
110
}
111