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

setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 9
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\Generator;
10
11
use JMS\Serializer\SerializerBuilder;
12
use KleijnWeb\SwaggerBundle\Tests\Dev\Document\SwaggerDocumentTest;
13
use KleijnWeb\SwaggerBundle\Dev\Generator\ResourceGenerator;
14
use KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\PetStoreBundle;
15
16
/**
17
 * @author John Kleijn <[email protected]>
18
 */
19
class ResourceGeneratorJmsSerializerCompatibilityTest extends \PHPUnit_Framework_TestCase
20
{
21
    protected function setUp()
22
    {
23
        $bundle = new PetStoreBundle();
24
        $document = SwaggerDocumentTest::getPetStoreDocument();
25
        $generator = new ResourceGenerator();
26
        $generator->setSkeletonDirs('src/Dev/Resources/skeleton');
0 ignored issues
show
Documentation introduced by
'src/Dev/Resources/skeleton' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        $generator->generate($bundle, $document, 'Model\Jms');
28
29
        require_once $bundle->getPath() . '/Model/Jms/Pet.php';
30
        require_once $bundle->getPath() . '/Model/Jms/Tag.php';
31
        require_once $bundle->getPath() . '/Model/Jms/Category.php';
32
    }
33
34
    /**
35
     * @test
36
     */
37 View Code Duplication
    public function canSerializeAPet()
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...
38
    {
39
        $pet = new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Pet();
40
        $pet
41
            ->setId(1234567)
42
            ->setName('doggie')
43
            ->setPhotourls(['/a/b/c', '/d/e/f'])
44
            ->setTags([
45
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Tag())->setName('purebreeds'),
46
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Tag())->setName('puppies')
47
            ])
48
            ->setCategory(
49
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Category())->setName('Dogs')
50
            );
51
52
        $serializer = SerializerBuilder::create()->build();
53
        $actual = json_decode($serializer->serialize($pet, 'json'), true);
54
        $expected = [
55
            'id'         => 1234567,
56
            'category'   => ['name' => 'Dogs'],
57
            'name'       => 'doggie',
58
            'photo_urls' => ['/a/b/c', '/d/e/f'],
59
            'tags'       => [
60
                ['name' => 'purebreeds'],
61
                ['name' => 'puppies'],
62
            ]
63
64
        ];
65
        $this->assertSame($expected, $actual);
66
    }
67
68
    /**
69
     * @test
70
     */
71 View Code Duplication
    public function canDeserializeAPet()
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...
72
    {
73
        $data = [
74
            'id'         => 1234567,
75
            'category'   => ['name' => 'Dogs'],
76
            'name'       => 'doggie',
77
            'photo_urls' => ['/a/b/c', '/d/e/f'],
78
            'tags'       => [
79
                ['name' => 'purebreeds'],
80
                ['name' => 'puppies'],
81
            ]
82
        ];
83
84
        $serializer = SerializerBuilder::create()->build();
85
        $actual = $serializer->deserialize(
86
            json_encode($data),
87
            'KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Pet',
88
            'json'
89
        );
90
91
        $expected = new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Pet();
92
        $expected
93
            ->setId(1234567)
94
            ->setName('doggie')
95
            ->setPhotourls(['/a/b/c', '/d/e/f'])
96
            ->setTags([
97
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Tag())->setName('purebreeds'),
98
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Tag())->setName('puppies')
99
            ])
100
            ->setCategory(
101
                (new \KleijnWeb\SwaggerBundle\Tests\Functional\PetStore\Model\Jms\Category())->setName('Dogs')
102
            );
103
104
        $this->assertEquals($expected, $actual);
105
    }
106
}
107