Skip to content

Commit 053bf31

Browse files
committed
Adding configuration exception class
1 parent 7ba5183 commit 053bf31

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace spec\FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception;
6+
7+
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception\ConfigurationException;
8+
use InvalidArgumentException;
9+
use PhpSpec\ObjectBehavior;
10+
11+
/**
12+
* @author Ignace Nyamagana Butera
13+
*/
14+
class ConfigurationExceptionSpec extends ObjectBehavior
15+
{
16+
public function it_is_initializable(): void
17+
{
18+
$this->shouldBeAnInstanceOf(InvalidArgumentException::class);
19+
$this->shouldHaveType(ConfigurationException::class);
20+
}
21+
}

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace spec\FriendsOfPhpSpec\PhpSpec\CodeCoverage\Listener;
66

7+
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception\ConfigurationException;
78
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Listener\CodeCoverageListener;
8-
use InvalidArgumentException;
99
use PhpSpec\Console\ConsoleIO;
1010
use PhpSpec\Event\SuiteEvent;
1111
use PhpSpec\ObjectBehavior;
@@ -14,8 +14,6 @@
1414
use SebastianBergmann\CodeCoverage\Filter;
1515
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
1616
use stdClass;
17-
use Throwable;
18-
use TypeError;
1917

2018
/**
2119
* Disabled due to tests breaking as php-code-coverage marked their classes
@@ -40,7 +38,7 @@ public function it_can_process_all_directory_filtering_options(SuiteEvent $event
4038
]);
4139

4240
$this
43-
->shouldNotThrow(TypeError::class)
41+
->shouldNotThrow(ConfigurationException::class)
4442
->during('beforeSuite', [$event]);
4543
}
4644

@@ -58,7 +56,7 @@ public function it_will_ignore_unknown_directory_filtering_options(SuiteEvent $e
5856
]);
5957

6058
$this
61-
->shouldNotThrow(Throwable::class)
59+
->shouldNotThrow(ConfigurationException::class)
6260
->during('beforeSuite', [$event]);
6361
}
6462

@@ -71,7 +69,7 @@ public function it_will_throw_if_the_directory_filter_option_type_is_not_support
7169
]);
7270

7371
$this
74-
->shouldThrow(TypeError::class)
72+
->shouldThrow(ConfigurationException::class)
7573
->during('beforeSuite', [$event]);
7674
}
7775

@@ -84,7 +82,7 @@ public function it_will_throw_if_the_directory_parameter_is_missing(SuiteEvent $
8482
]);
8583

8684
$this
87-
->shouldThrow(InvalidArgumentException::class)
85+
->shouldThrow(ConfigurationException::class)
8886
->during('beforeSuite', [$event]);
8987
}
9088

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception;
6+
7+
use InvalidArgumentException;
8+
9+
class ConfigurationException extends InvalidArgumentException
10+
{
11+
}

src/Listener/CodeCoverageListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414

1515
namespace FriendsOfPhpSpec\PhpSpec\CodeCoverage\Listener;
1616

17-
use InvalidArgumentException;
17+
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception\ConfigurationException;
1818
use PhpSpec\Console\ConsoleIO;
1919
use PhpSpec\Event\ExampleEvent;
2020
use PhpSpec\Event\SuiteEvent;
2121
use SebastianBergmann\CodeCoverage\CodeCoverage;
2222
use SebastianBergmann\CodeCoverage\Report;
2323
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
24-
use TypeError;
2524

2625
use function gettype;
2726
use function is_array;
@@ -203,14 +202,14 @@ protected function filterDirectoryParams($option): array
203202
}
204203

205204
if (!is_array($option)) {
206-
throw new TypeError(sprintf(
205+
throw new ConfigurationException(sprintf(
207206
'Directory filtering options must be a string or an associated array, %s given instead.',
208207
gettype($option)
209208
));
210209
}
211210

212211
if (!isset($option['directory'])) {
213-
throw new InvalidArgumentException('Missing required directory path.');
212+
throw new ConfigurationException('Missing required directory path.');
214213
}
215214

216215
return [

0 commit comments

Comments
 (0)