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

createOptionsResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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