Passed
Push — master ( 17ea33...1a0634 )
by Steevan
01:30
created

OptionsResolverConfigureRequiredOptionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 41
loc 41
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testValid() 8 8 1
A testInvalidType() 7 7 1
A testInvalidAllowedValue() 7 7 1
A testRequiredOption() 7 7 1
A createOptionsResolver() 5 5 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
declare(strict_types=1);
4
5
namespace steevanb\SymfonyOptionsResolver\Tests;
6
7
use PHPUnit\Framework\TestCase;
8
use steevanb\SymfonyOptionsResolver\OptionsResolver;
9
use Symfony\Component\OptionsResolver\{
10
    Exception\InvalidOptionsException,
11
    Exception\MissingOptionsException
12
};
13
14 View Code Duplication
final class OptionsResolverConfigureRequiredOptionTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
15
{
16
    public function testValid(): void
17
    {
18
        $this
19
            ->createOptionsResolver()
20
            ->resolve(['foo' => 'bar']);
21
22
        static::addToAssertionCount(1);
23
    }
24
25
    public function testInvalidType(): void
26
    {
27
        $optionsResolver = $this->createOptionsResolver();
28
29
        static::expectException(InvalidOptionsException::class);
30
        $optionsResolver->resolve(['foo' => 1]);
31
    }
32
33
    public function testInvalidAllowedValue(): void
34
    {
35
        $optionsResolver = $this->createOptionsResolver();
36
37
        static::expectException(InvalidOptionsException::class);
38
        $optionsResolver->resolve(['foo' => 'baz']);
39
    }
40
41
    public function testRequiredOption(): void
42
    {
43
        $optionsResolver = $this->createOptionsResolver();
44
45
        static::expectException(MissingOptionsException::class);
46
        $optionsResolver->resolve([]);
47
    }
48
49
    private function createOptionsResolver(): OptionsResolver
50
    {
51
        return (new OptionsResolver())
52
            ->configureRequiredOption('foo', ['string'], ['bar']);
53
    }
54
}
55