Completed
Push — master ( 031f19...3fe677 )
by John
02:56
created

ResponseFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 9
dl 0
loc 45
rs 10

4 Methods

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