Completed
Pull Request — master (#3)
by Pavel
03:35
created

RpcTest::testMethodNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1.0019

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 11
loc 11
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
crap 1.0019
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 16.05.2016
6
 * Time: 13:44
7
 */
8
9
namespace Bankiru\Api\Rpc\Tests;
10
11
use Bankiru\Api\Rpc\Exception\InvalidMethodParametersException;
12
use Bankiru\Api\Rpc\Routing\Exception\MethodNotFoundException;
13
use Bankiru\Api\Rpc\Tests\Fixtures\Kernel;
14
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
16
17
class RpcTest extends WebTestCase
18
{
19
    public function getArgumentVariants()
20
    {
21
        return [
22
            'missing all'                         => [[], false],
23
            'missing array'                       => [['noDefault' => 1], false],
24
            'not an array'                        => [['noDefault' => 1, 'array' => 2], false],
25
            'correct'                             => [['noDefault' => 1, 'array' => ['test1' => 2, 'abc']], true],
26
            'correct 2'                           => [['noDefault' => 1, 'array' => ['test', 'test2']], true],
27
            'correct w explicit default override' => [
28
                ['default' => 'new_value', 'noDefault' => 1, 'array' => []],
29
                true,
30
            ],
31
        ];
32
    }
33
34
    /**
35
     * @dataProvider getArgumentVariants
36
     *
37
     * @param array $args
38
     * @param bool  $valid
39
     *
40
     * @throws InvalidMethodParametersException
41
     * @throws \Error
42
     */
43 6
    public function testController(array $args, $valid)
44
    {
45 6
        $client = self::createClient();
46
        try {
47 6
            $client->request(
48 6
                'POST',
49 6
                '/test/',
50 6
                array_replace(['method' => 'test/method',], $args)
51 6
            );
52 6
        } catch (InvalidMethodParametersException $e) {
53 3
            if ($valid) {
54
                throw $e;
55
            }
56
        }
57 6
    }
58
59
    /**
60
     * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
61
     */
62 1 View Code Duplication
    public function test404()
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...
63
    {
64 1
        $client = self::createClient();
65
66 1
        $client->request(
67 1
            'POST',
68 1
            '/not_found_endpoint/',
69 1
            array_replace(['method' => 'test/method',], ['arg' => 1])
70 1
        );
71
    }
72
73
    /**
74
     * @expectedException \Bankiru\Api\Rpc\Routing\Exception\MethodNotFoundException
75
     */
76 1 View Code Duplication
    public function testMethodNotFound()
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...
77
    {
78 1
        $client = self::createClient();
79
80 1
        $client->request(
81 1
            'POST',
82 1
            '/test/',
83 1
            array_replace(['method' => 'unknown/method'], ['arg' => 1])
84 1
        );
85
86
    }
87
88
    protected static function getKernelClass()
89
    {
90
        return Kernel::class;
91
    }
92
}
93