Completed
Push — master ( 386146...a2d301 )
by John
07:40
created

SwaggerDocumentTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 30.88 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 3
dl 21
loc 68
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A canGetPathDefinitions() 11 11 1
A getOperationDefinition() 10 10 1
A getOperationDefinitionHttpMethodIsCaseInsensitive() 0 4 1
A getOperationDefinitionWillFailOnUnknownHttpMethod() 0 4 1
A getOperationDefinitionWillFailOnUnknownPath() 0 4 1
A getPetStoreDocument() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Document;
10
11
use KleijnWeb\SwaggerBundle\Document\DocumentRepository;
12
use KleijnWeb\SwaggerBundle\Document\SwaggerDocument;
13
use org\bovigo\vfs\vfsStream;
14
use org\bovigo\vfs\vfsStreamDirectory;
15
use org\bovigo\vfs\vfsStreamWrapper;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class SwaggerDocumentTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @test
24
     */
25 View Code Duplication
    public function canGetPathDefinitions()
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...
26
    {
27
        $actual = self::getPetStoreDocument()->getPathDefinitions();
28
        $this->assertInternalType('object', $actual);
29
30
        // Check a few attributes
31
        $this->assertObjectHasAttribute('/pet', $actual);
32
        $this->assertObjectHasAttribute('/pet/findByStatus', $actual);
33
        $this->assertObjectHasAttribute('/store/inventory', $actual);
34
        $this->assertObjectHasAttribute('/user', $actual);
35
    }
36
37
    /**
38
     * @test
39
     */
40 View Code Duplication
    public function getOperationDefinition()
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...
41
    {
42
        $actual = self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'get');
43
        $this->assertInternalType('object', $actual);
44
45
        // Check a few attributes
46
        $this->assertObjectHasAttribute('parameters', $actual);
47
        $this->assertObjectHasAttribute('responses', $actual);
48
        $this->assertObjectHasAttribute('security', $actual);
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function getOperationDefinitionHttpMethodIsCaseInsensitive()
55
    {
56
        self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'GET');
57
    }
58
59
60
    /**
61
     * @expectedException \InvalidArgumentException
62
     * @test
63
     */
64
    public function getOperationDefinitionWillFailOnUnknownHttpMethod()
65
    {
66
        self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'post');
67
    }
68
69
    /**
70
     * @expectedException \InvalidArgumentException
71
     * @test
72
     */
73
    public function getOperationDefinitionWillFailOnUnknownPath()
74
    {
75
        self::getPetStoreDocument()->getOperationDefinition('/this/is/total/bogus', 'post');
76
    }
77
78
    /**
79
     * @return SwaggerDocument
80
     */
81
    public static function getPetStoreDocument()
82
    {
83
        $repository = new DocumentRepository('src/Tests/Functional/PetStore');
84
85
        return $repository->get('app/swagger/petstore.yml');
86
    }
87
}
88