Completed
Push — master ( 6ebd1c...df9bae )
by John
10:14
created

willAddVndErrorSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Tests\Dev\DocumentFixer;
10
11
use KleijnWeb\SwaggerBundle\Document\SwaggerDocument;
12
use KleijnWeb\SwaggerBundle\Dev\DocumentFixer\Fixers\SwaggerBundleResponseFixer;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class SwaggerBundleResponseFixerTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @test
21
     */
22
    public function willAddVndErrorSchema()
23
    {
24
        $fixer = new SwaggerBundleResponseFixer();
25
        $document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
26
        $fixer->fix($document);
27
28
        $definition = $document->getDefinition();
29
        $this->assertArrayHasKey('definitions', $definition);
30
        $this->assertArrayHasKey('VndError', $definition['definitions']);
31
        $this->assertArrayHasKey('type', $definition['definitions']['VndError']);
32
        $this->assertArrayHasKey('required', $definition['definitions']['VndError']);
33
        $this->assertArrayHasKey('properties', $definition['definitions']['VndError']);
34
    }
35
36
    /**
37
     * @test
38
     */
39 View Code Duplication
    public function willAddServerErrorResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        $fixer = new SwaggerBundleResponseFixer();
42
        $document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
43
        $fixer->fix($document);
44
45
        $definition = $document->getDefinition();
46
        $this->assertArrayHasKey('responses', $definition);
47
        $this->assertArrayHasKey('ServerError', $definition['responses']);
48
        $this->assertArrayHasKey('description', $definition['responses']['ServerError']);
49
        $this->assertArrayHasKey('schema', $definition['responses']['ServerError']);
50
        $this->assertArrayHasKey('$ref', $definition['responses']['ServerError']['schema']);
51
        $this->assertSame($definition['responses']['ServerError']['schema']['$ref'], '#/definitions/VndError');
52
    }
53
54
    /**
55
     * @test
56
     */
57 View Code Duplication
    public function willAddServerErrorResponseToOperations()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $fixer = new SwaggerBundleResponseFixer();
60
        $document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
61
        $fixer->fix($document);
62
63
        $operationDefinition = $document->getOperationDefinition('/', 'get');
64
        $responses = $operationDefinition['responses'];
65
        $this->assertArrayHasKey('500', $responses);
66
        $this->assertSame($responses['500']['schema']['$ref'], '#/responses/ServerError');
67
    }
68
69
    /**
70
     * @test
71
     */
72 View Code Duplication
    public function willAddInputErrorResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $fixer = new SwaggerBundleResponseFixer();
75
        $document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
76
        $fixer->fix($document);
77
78
        $definition = $document->getDefinition();
79
        $this->assertArrayHasKey('responses', $definition);
80
        $this->assertArrayHasKey('InputError', $definition['responses']);
81
        $this->assertArrayHasKey('description', $definition['responses']['InputError']);
82
        $this->assertArrayHasKey('schema', $definition['responses']['InputError']);
83
        $this->assertArrayHasKey('$ref', $definition['responses']['InputError']['schema']);
84
        $this->assertSame($definition['responses']['InputError']['schema']['$ref'], '#/definitions/VndError');
85
    }
86
87
    /**
88
     * @test
89
     */
90 View Code Duplication
    public function willAddInputErrorResponseToOperations()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        $fixer = new SwaggerBundleResponseFixer();
93
        $document = new SwaggerDocument(__DIR__ . '/assets/minimal.yml');
94
        $fixer->fix($document);
95
96
        $operationDefinition = $document->getOperationDefinition('/', 'get');
97
        $responses = $operationDefinition['responses'];
98
        $this->assertArrayHasKey('400', $responses);
99
        $this->assertSame($responses['400']['schema']['$ref'], '#/responses/InputError');
100
    }
101
}
102