Skip to content

Commit 9ddb596

Browse files
committed
Add a new exception for invalid argument to replace a phpunit exception who is become an abstract class without the method we are using
1 parent 4635a8f commit 9ddb596

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

.github/workflows/quality.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3
8+
- uses: shivammathur/setup-php@v2
9+
with:
10+
php-version: '8.2'
11+
coverage: none
812
- name: Cs-Fixer
913
run: |
1014
wget -q https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
@@ -31,7 +35,7 @@ jobs:
3135
args: --prefer-dist
3236
php_version: '8.2'
3337
- name: Run tests & generate Coverage
34-
run: bin/phpunit --configuration=phpunit.xml tests --coverage-html var/coverage --whitelist=src
38+
run: bin/phpunit --configuration=phpunit.xml tests --coverage-html var/coverage
3539
- name: Store coverage files
3640
uses: actions/upload-artifact@v3
3741
with:

.github/workflows/rector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
- uses: "ramsey/composer-install@v2"
2626

27-
- run: vendor/bin/rector --ansi
27+
- run: bin/rector --ansi
2828

2929
-
3030
# commit only to core contributors who have repository access

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"extra": {
4646
"branch-alias": {
47-
"dev-main": "0.4.x-dev"
47+
"dev-main": "0.5.x-dev"
4848
}
4949
}
5050
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Constraint/Builder/BuilderProducesCodeThat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
namespace Kiboko\Component\PHPUnitExtension\Constraint\Builder;
66

7+
use Kiboko\Component\PHPUnitExtension\Constraint\Builder\Exception\InvalidArgumentException;
78
use PhpParser\Builder;
89
use PhpParser\Node;
910
use PhpParser\PrettyPrinter;
1011
use PHPUnit\Framework\Constraint\UnaryOperator;
11-
use PHPUnit\Framework\InvalidArgumentException;
1212

1313
final class BuilderProducesCodeThat extends UnaryOperator
1414
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace Kiboko\Component\PHPUnitExtension\Constraint\Builder\Exception;
14+
15+
use PHPUnit\Framework\InvalidArgumentException as BaseInvalidArgumentException;
16+
17+
final class InvalidArgumentException extends BaseInvalidArgumentException
18+
{
19+
public static function create(int $argument, string $type): self
20+
{
21+
$stack = debug_backtrace();
22+
$function = $stack[1]['function'];
23+
24+
if (isset($stack[1]['class'])) {
25+
$function = sprintf('%s::%s', $stack[1]['class'], $stack[1]['function']);
26+
}
27+
28+
return new self(
29+
sprintf(
30+
'Argument #%d of %s() must be %s %s',
31+
$argument,
32+
$function,
33+
\in_array(lcfirst($type)[0], ['a', 'e', 'i', 'o', 'u'], true) ? 'an' : 'a',
34+
$type
35+
)
36+
);
37+
}
38+
39+
private function __construct(string $message = '', int $code = 0, \Exception $previous = null)
40+
{
41+
parent::__construct($message, $code, $previous);
42+
}
43+
}

0 commit comments

Comments
 (0)