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

OptionsResolverConfigureOptionTest   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 testDefaultValue() 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\Exception\InvalidOptionsException;
10
11 View Code Duplication
final class OptionsResolverConfigureOptionTest 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...
12
{
13
    public function testValid(): void
14
    {
15
        $this
16
            ->createOptionsResolver()
17
            ->resolve(['foo' => 'bar']);
18
19
        static::addToAssertionCount(1);
20
    }
21
22
    public function testInvalidType(): void
23
    {
24
        $optionsResolver = $this->createOptionsResolver();
25
26
        static::expectException(InvalidOptionsException::class);
27
        $optionsResolver->resolve(['foo' => 1]);
28
    }
29
30
    public function testInvalidAllowedValue(): void
31
    {
32
        $optionsResolver = $this->createOptionsResolver();
33
34
        static::expectException(InvalidOptionsException::class);
35
        $optionsResolver->resolve(['foo' => 'baz']);
36
    }
37
38
    public function testDefaultValue(): void
39
    {
40
        $optionsResolver = $this->createOptionsResolver('bar');
41
        $optionsResolver->resolve([]);
42
43
        static::addToAssertionCount(1);
44
    }
45
46
    private function createOptionsResolver(string $defaultValue = null): OptionsResolver
47
    {
48
        return (new OptionsResolver())
49
            ->configureOption('foo', ['string'], ['bar'], $defaultValue);
50
    }
51
}
52