Completed
Pull Request — master (#94)
by John
02:54
created

GenericDataApiTest::canGetStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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\Functional;
10
11
use KleijnWeb\SwaggerBundle\Test\ApiTestCase;
12
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 * @group functional
17
 */
18
class GenericDataApiTest extends WebTestCase
19
{
20
    use ApiTestCase;
21
22
    /**
23
     * @var string
24
     */
25
    protected $env = 'basic';
26
27
    /**
28
     * @test
29
     */
30 View Code Duplication
    public function canPost()
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...
31
    {
32
        $content = [
33
            'foo'  => 'bar',
34
            'blah' => ['foobar']
35
        ];
36
37
        $responseData = $this->post('/data/v1/entity/foo', $content);
38
39
        $this->assertInternalType('int', $responseData->id);
40
        $this->assertSame($content['foo'], $responseData->foo);
41
        $this->assertSame($content['blah'], $responseData->blah);
42
        $this->assertSame('foo', $responseData->type);
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function canGetStatus()
49
    {
50
        $responseData = $this->get('/data/v1/entity/status');
51
52
        $this->assertSame('ok', $responseData->overall);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function canFindUsingDateTimeQuery()
59
    {
60
        $responseData = $this->get('/data/v1/entity/bar', ['lastModified' => (new \DateTime)->format(\DateTime::W3C)]);
61
62
        $this->assertSame(2, $responseData[0]->id);
63
        $this->assertSame('bar', $responseData[0]->foo);
64
        $this->assertSame('bar', $responseData[0]->type);
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function canFindByCriteria()
71
    {
72
        $criteria     = [
73
            (object)[
74
                'fieldName' => 'x',
75
                'operator'  => 'eq',
76
                'value'     => 'y'
77
            ],
78
79
            (object)[
80
                'fieldName' => 'a',
81
                'operator'  => 'eq',
82
                'value'     => 'b'
83
            ]
84
        ];
85
        $responseData = $this->post('/data/v1/entity/bar/findByCriteria', $criteria);
86
87
        $this->assertSame(3, $responseData[0]->id);
88
        $this->assertSame('bar', $responseData[0]->foo);
89
        $this->assertSame('bar', $responseData[0]->type);
90
91
        $this->assertSame(4, $responseData[1]->id);
92
    }
93
94
    /**
95
     * @test
96
     */
97
    public function canGet()
98
    {
99
        $responseData = $this->get('/data/v1/entity/bar/555');
100
101
        $this->assertSame(555, $responseData->id);
102
        $this->assertSame('bar', $responseData->foo);
103
        $this->assertSame('bar', $responseData->type);
104
    }
105
106
    /**
107
     * @test
108
     */
109
    public function canDelete()
110
    {
111
        $this->assertSame(null, $this->delete('/data/v1/entity/foo/1'));
112
    }
113
114
    /**
115
     * @test
116
     */
117 View Code Duplication
    public function canPut()
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...
118
    {
119
        $content = [
120
            'foo'  => 'bar',
121
            'blah' => ['foobar']
122
        ];
123
124
        $responseData = $this->put('/data/v1/entity/foo/999', $content);
125
126
        $this->assertSame(999, $responseData->id);
127
        $this->assertSame($content['foo'], $responseData->foo);
128
        $this->assertSame($content['blah'], $responseData->blah);
129
        $this->assertSame('foo', $responseData->type);
130
    }
131
}
132