TestRequestParser::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PostmanGeneratorBundle package.
5
 *
6
 * (c) Vincent Chalamon <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PostmanGeneratorBundle\RequestParser;
13
14
use PostmanGeneratorBundle\Model\Request;
15
use PostmanGeneratorBundle\Model\Test;
16
17
class TestRequestParser implements RequestParserInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 5
    public function parse(Request $request)
23
    {
24 5
        switch ($request->getMethod()) {
25 5
            case 'POST':
26 1
                $request->addTest(new Test('Successful POST request', 'responseCode.code === 201 || responseCode.code === 202'));
27 1
                $request->addTest(new Test('Content-Type is correct', 'postman.getResponseHeader("Content-Type") === "application/ld+json"'));
28 1
                break;
29 4
            case 'PUT':
30 4
            case 'PATCH':
31 4
            case 'GET':
32 3
                $request->addTest(new Test(sprintf('Successful %s request', $request->getMethod()), 'responseCode.code === 200'));
33 3
                $request->addTest(new Test('Content-Type is correct', 'postman.getResponseHeader("Content-Type") === "application/ld+json"'));
34 3
                break;
35 1
            case 'DELETE':
36 1
                $request->addTest(new Test('Successful DELETE request', 'responseCode.code === 204'));
37 1
                break;
38 5
        }
39 5
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function supports(Request $request)
45
    {
46 1
        return true;
47
    }
48
}
49