Completed
Pull Request — master (#3)
by Pavel
09:01
created

RpcTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 27.63 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 1
cbo 3
dl 21
loc 76
ccs 24
cts 39
cp 0.6153
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getArgumentVariants() 0 14 1
A testController() 0 15 3
A test404() 10 10 1
A testMethodNotFound() 11 11 1
A getKernelClass() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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