validationSubjectProvider()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 13
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 19
rs 9.8333
1
<?php
2
3
namespace Wesnick\WorkflowBundle\Tests\Validation;
4
5
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...
6
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
7
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...
8
use Symfony\Component\Workflow\Transition;
9
use Symfony\Component\Workflow\Workflow;
10
use Wesnick\WorkflowBundle\Tests\Fixtures\ArticleWithWorkflow;
11
use Wesnick\WorkflowBundle\Tests\Fixtures\StateProviderWithWorkflow;
12
use Wesnick\WorkflowBundle\Validation\ChainedWorkflowValidationStrategy;
13
use Wesnick\WorkflowBundle\Validation\ValidationStateProviderStrategy;
14
use Wesnick\WorkflowBundle\Validation\WorkflowValidationStrategy;
15
16
class ChainedWorkflowValidationStrategyTest extends TestCase
17
{
18
    use WorkflowBuilderTrait;
19
20
    /**
21
     * @dataProvider validationSubjectProvider
22
     */
23
    public function testGetValidationGroupsForSubject($subject, Workflow $workflow, Transition $transition, array $result)
24
    {
25
        $strategy = new ChainedWorkflowValidationStrategy([
26
            new WorkflowValidationStrategy(),
27
            new ValidationStateProviderStrategy()
28
        ]);
29
30
        $groups = $strategy->getValidationGroupsForSubject($subject, $workflow, $transition);
31
        $this->assertEquals($result, $groups);
32
    }
33
34
    public function validationSubjectProvider()
35
    {
36
        $definition = $this->createComplexWorkflowDefinition();
37
        $transitions = $definition->getTransitions();
38
        $getTransitionByName = function ($name) use ($transitions) {
39
            foreach ($transitions as $transition) {
40
                if ($transition->getName() === $name) {
41
                    return $transition;
42
                }
43
            }
44
        };
45
        $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

45
        $workflow = new Workflow($definition, /** @scrutinizer ignore-deprecated */ new MultipleStateMarkingStore());
Loading history...
46
47
        yield [new ArticleWithWorkflow(), $workflow, $getTransitionByName('t1'), ['Default', 'unnamed', 'unnamed_b', 'unnamed_c']];
48
        yield [new ArticleWithWorkflow(), $workflow, $getTransitionByName('t2'), ['Default', 'unnamed', 'unnamed_d']];
49
        yield [new StateProviderWithWorkflow('blue'), $workflow, $getTransitionByName('t1'), ['Default', 'unnamed', 'unnamed_b', 'unnamed_c', 'b_blue', 'c_blue']];
50
        yield [new StateProviderWithWorkflow('red'), $workflow, $getTransitionByName('t1'), ['Default', 'unnamed', 'unnamed_b', 'unnamed_c', 'b_red', 'c_red']];
51
        yield [new StateProviderWithWorkflow('red'), $workflow, $getTransitionByName('t2'), ['Default', 'unnamed', 'unnamed_d', 'd_red']];
52
        yield [new StateProviderWithWorkflow('green'), $workflow, $getTransitionByName('t2'), ['Default', 'unnamed', 'unnamed_d', 'd_green']];
53
    }
54
}
55