WorkflowActionsResourceMetadataFactoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 16
c 1
b 1
f 0
dl 0
loc 34
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadata() 0 22 1
A testCreateOperation() 0 5 1
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\Metadata;
13
14
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
15
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
16
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...
17
use Wesnick\WorkflowBundle\Controller\DefaultTransitionController;
18
use Wesnick\WorkflowBundle\Metadata\WorkflowActionsResourceMetadataFactory;
19
use Wesnick\WorkflowBundle\Model\WorkflowDTO;
20
use Wesnick\WorkflowBundle\Tests\Fixtures\ArticleWithWorkflow;
21
22
/**
23
 * @group unit
24
 */
25
class WorkflowActionsResourceMetadataFactoryTest extends TestCase
26
{
27
    /**
28
     * @dataProvider getMetadata
29
     */
30
    public function testCreateOperation(ResourceMetadata $before, ResourceMetadata $after)
31
    {
32
        $decoratedProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
33
        $decoratedProphecy->create(ArticleWithWorkflow::class)->shouldBeCalled()->willReturn($before);
34
        $this->assertEquals($after, (new WorkflowActionsResourceMetadataFactory($decoratedProphecy->reveal()))->create(ArticleWithWorkflow::class));
35
    }
36
37
    public function getMetadata()
38
    {
39
        $operations = ['patch' => [
40
            'method' => 'PATCH',
41
            'controller' => DefaultTransitionController::class,
42
            'input' => ['class' => WorkflowDTO::class, 'name' => 'WorkflowDTO'],
43
        ]];
44
        $attributes = ['denormalization_context' => ['groups' => ['workflowAction:output']]];
45
46
        return [
47
            // Item operations
48
            [
49
                new ResourceMetadata(null, null, null, null, [], null, [], []),
50
                new ResourceMetadata(null, null, null, $operations, [], $attributes, [], []),
51
            ],
52
            [
53
                new ResourceMetadata(null, null, null, ['patch' => []], [], null, [], []),
54
                new ResourceMetadata(null, null, null, $operations, [], $attributes, [], []),
55
            ],
56
            [
57
                new ResourceMetadata(null, null, null, [], [], ['denormalization_context' => ['groups' => ['workflowAction:output']]], [], []),
58
                new ResourceMetadata(null, null, null, $operations, [], $attributes, [], []),
59
            ],
60
        ];
61
    }
62
}
63