Skip to content

Commit 1a06341

Browse files
committed
Add unit tests
1 parent 17ea336 commit 1a06341

9 files changed

+120
-18
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
build:
22
environment:
3+
# lib require with PHP 7.1 but PHPUnit require 7.2 and Scrutinizer use dev environment
34
php: 7.2
45
checks:
56
php:

bin/phpcs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ if [ $(which docker || false) ]; then
1111
else
1212
cd /var/steevanb/php-code-sniffs/vendor/steevanb/php-code-sniffs
1313
../../bin/phpcs \
14+
--bootstrap=/var/phpcs/phpcs.bootstrap.php \
1415
--standard=ruleset.xml \
1516
--report=steevanb\\PhpCodeSniffs\\Reports\\Steevanb \
1617
--warning-severity=0 \
17-
-s \
1818
--ignore=/var/phpcs/vendor/ \
1919
/var/phpcs
2020
fi

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
- Create `steevanb\SymfonyOptionsResolver\OptionsResolver`.
44
- Add `OptionsResolver::configureOption()`.
55
- Add `OptionsResolver::configureRequiredOption()`.
6+
- Add CirclecCI build
7+
- Add phpcs
8+
- Add phpstan
9+
- Add phpunit
10+
- Add Scrutinizer

phpcs.bootstrap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use steevanb\PhpCodeSniffs\Steevanb\Sniffs\Uses\GroupUsesSniff;
6+
7+
GroupUsesSniff::addSymfonyPrefixes();

phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ parameters:
22
level: 5
33
paths:
44
- src/
5-
- tests/
6-
ignoreErrors: []

src/OptionsResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function configureRequiredOption(string $name, array $allowedTypes, array
2929
protected function setAllowedTypesAndValues(string $name, array $allowedTypes, array $allowedValues): self
3030
{
3131
$this
32+
->setDefined($name)
3233
->setAllowedTypes($name, $allowedTypes)
3334
->setAllowedValues($name, $allowedValues);
3435

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
final class OptionsResolverConfigureOptionTest extends TestCase
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+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
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+
}

tests/OptionsResolverTest.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)