Completed
Pull Request — master (#52)
by John
06:05
created

willUseFirst2xxStatusCodeFromDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
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\Response;
10
11
use KleijnWeb\SwaggerBundle\Document\DocumentRepository;
12
use KleijnWeb\SwaggerBundle\Response\ResponseFactory;
13
use KleijnWeb\SwaggerBundle\Serializer\ArraySerializer;
14
use KleijnWeb\SwaggerBundle\Serializer\SerializerAdapter;
15
use Symfony\Component\HttpFoundation\Request;
16
17
/**
18
 * @author John Kleijn <[email protected]>
19
 */
20
class ResponseFactoryTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @test
24
     */
25
    public function willUseFirst2xxStatusCodeFromDocument()
26
    {
27
        $this->assertEquals(201, $this->createResponse([], '/pet', 'POST')->getStatusCode());
28
    }
29
30
    /**
31
     * @test
32
     */
33
    public function willUse204ForNullResponsesWhenFoundInDocument()
34
    {
35
        $this->assertEquals(204, $this->createResponse(null, '/pet/{id}', 'DELETE')->getStatusCode());
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function willNotUse204ForNullResponsesWhenNotInDocument()
42
    {
43
        $this->assertNotEquals(204, $this->createResponse(null, '/pet/{id}', 'PUT')->getStatusCode());
44
    }
45
46
    /**
47
     * @param mixed $data
48
     * @param string $path
49
     * @param string $method
50
     *
51
     * @return \Symfony\Component\HttpFoundation\Response
52
     */
53
    private function createResponse($data, $path, $method)
54
    {
55
        $serializer = new SerializerAdapter(new ArraySerializer());
56
        $factory = new ResponseFactory(new DocumentRepository(), $serializer);
57
        $request = new Request();
58
        $request->server->set('REQUEST_METHOD', $method);
59
        $request->attributes->set('_definition', 'src/Tests/Functional/PetStore/app/swagger/composite.yml');
60
        $request->attributes->set('_swagger_path', $path);
61
62
        return $factory->createResponse($request, $data);
63
    }
64
}
65