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 |
|
|
|
|
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
|
|
|
|
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.