Completed
Push — master ( 9c5fdf...27a5d2 )
by John
7s
created

SwaggerSpecificationTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 87
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A canGetPathDefinitions() 0 11 1
A canGetResourceTypeDefinition() 0 7 1
A canFailToGetResourceTypeDefinition() 0 4 1
A getOperationDefinition() 0 10 1
A getOperationDefinitionHttpMethodIsCaseInsensitive() 0 4 1
A getOperationDefinitionWillFailOnUnknownHttpMethod() 0 4 1
A getOperationDefinitionWillFailOnUnknownPath() 0 4 1
A getPetStoreDocument() 0 6 1
1
<?php declare(strict_types = 1);
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\Document;
10
11
use KleijnWeb\SwaggerBundle\Document\DocumentRepository;
12
use KleijnWeb\SwaggerBundle\Document\Specification;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class SwaggerSpecificationTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @test
21
     */
22
    public function canGetPathDefinitions()
23
    {
24
        $actual = self::getPetStoreDocument()->getPaths();
25
        $this->assertinstanceOf('\stdClass', $actual);
26
27
        // Check a few attributes
28
        $this->assertObjectHasAttribute('/pet', $actual);
29
        $this->assertObjectHasAttribute('/pet/findByStatus', $actual);
30
        $this->assertObjectHasAttribute('/store/inventory', $actual);
31
        $this->assertObjectHasAttribute('/user', $actual);
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function canGetResourceTypeDefinition()
38
    {
39
        $actual = self::getPetStoreDocument()->getResourceDefinition('Pet');
40
        $this->assertinstanceOf('\stdClass', $actual);
41
        $this->assertObjectHasAttribute('properties', $actual);
42
        $this->assertObjectHasAttribute('id', $actual->properties);
43
    }
44
45
    /**
46
     * @test
47
     * @expectedException \InvalidArgumentException
48
     */
49
    public function canFailToGetResourceTypeDefinition()
50
    {
51
        self::getPetStoreDocument()->getResourceDefinition('Zebra');
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function getOperationDefinition()
58
    {
59
        $actual = self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'get');
0 ignored issues
show
Deprecated Code introduced by
The method KleijnWeb\SwaggerBundle\...etOperationDefinition() has been deprecated.

This method has been deprecated.

Loading history...
60
        $this->assertinstanceOf('\stdClass', $actual);
61
62
        // Check a few attributes
63
        $this->assertObjectHasAttribute('parameters', $actual);
64
        $this->assertObjectHasAttribute('responses', $actual);
65
        $this->assertObjectHasAttribute('security', $actual);
66
    }
67
68
    /**
69
     * @test
70
     */
71
    public function getOperationDefinitionHttpMethodIsCaseInsensitive()
72
    {
73
        self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'GET');
0 ignored issues
show
Deprecated Code introduced by
The method KleijnWeb\SwaggerBundle\...etOperationDefinition() has been deprecated.

This method has been deprecated.

Loading history...
74
    }
75
76
    /**
77
     * @expectedException \InvalidArgumentException
78
     * @test
79
     */
80
    public function getOperationDefinitionWillFailOnUnknownHttpMethod()
81
    {
82
        self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'post');
0 ignored issues
show
Deprecated Code introduced by
The method KleijnWeb\SwaggerBundle\...etOperationDefinition() has been deprecated.

This method has been deprecated.

Loading history...
83
    }
84
85
    /**
86
     * @expectedException \InvalidArgumentException
87
     * @test
88
     */
89
    public function getOperationDefinitionWillFailOnUnknownPath()
90
    {
91
        self::getPetStoreDocument()->getOperationDefinition('/this/is/total/bogus', 'post');
0 ignored issues
show
Deprecated Code introduced by
The method KleijnWeb\SwaggerBundle\...etOperationDefinition() has been deprecated.

This method has been deprecated.

Loading history...
92
    }
93
94
    /**
95
     * @return Specification
96
     */
97
    public static function getPetStoreDocument()
98
    {
99
        $repository = new DocumentRepository('src/Tests/Functional/PetStore');
100
101
        return $repository->get('app/swagger/petstore.yml');
102
    }
103
}
104