Passed
Push — master ( 675316...81d3c7 )
by Steevan
02:00
created

AllowUnknownKeysTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testDefault() 0 7 1
A testAllowed() 0 9 1
A testNotAllowed() 0 8 1
A createOptionsResolver() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace steevanb\SymfonyOptionsResolver\Tests\OptionsResolver;
6
7
use PHPUnit\Framework\TestCase;
8
use steevanb\SymfonyOptionsResolver\OptionsResolver;
9
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
10
11
final class AllowUnknownKeysTest extends TestCase
12
{
13
    public function testDefault(): void
14
    {
15
        static::expectException(UndefinedOptionsException::class);
16
        $this
17
            ->createOptionsResolver()
18
            ->resolve(['foo' => 'bar', 'extraKey' => 'extraValue']);
19
    }
20
21
    public function testAllowed(): void
22
    {
23
        $this
24
            ->createOptionsResolver()
25
            ->setAllowUnknownKeys(true)
26
            ->resolve(['foo' => 'bar', 'extraKey' => 'extraValue']);
27
28
        static::addToAssertionCount(1);
29
    }
30
31
    public function testNotAllowed(): void
32
    {
33
        static::expectException(UndefinedOptionsException::class);
34
        $this
35
            ->createOptionsResolver()
36
            ->setAllowUnknownKeys(false)
37
            ->resolve(['foo' => 'bar', 'extraKey' => 'extraValue']);
38
    }
39
40
    private function createOptionsResolver(string $defaultValue = null): OptionsResolver
41
    {
42
        return (new OptionsResolver())
43
            ->configureOption('foo', ['string'], $defaultValue, ['bar']);
44
    }
45
}
46