Skip to content

Commit 9400cbc

Browse files
committed
fix(package): minor fix
1 parent e000f25 commit 9400cbc

File tree

8 files changed

+68
-41
lines changed

8 files changed

+68
-41
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
/vendor/
22
/composer.lock
33
/test/report-junit.xml
4-
/test/phpunit.cache.xml

phpcs.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
<arg name="basepath" value="."/>
88
<arg name="extensions" value="php"/>
99
<arg name="report" value="full"/>
10-
<arg name="ignore" value="vendor"/>
1110
<arg value="psv"/>
1211
<config name="ignore_warnings_on_exit" value="1"/>
12+
<arg name="cache" value="./test/caches/phpcs.cache"/>
13+
<arg name="ignore" value="vendor,test/caches"/>
1314

1415
<!-- Target -->
1516
<file>./src</file>

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ parameters:
33
paths:
44
- ./src
55
- ./test
6+
tmpDir: ./test/caches/phpstan.cache
7+
excludePaths:
8+
analyseAndScan:
9+
- ./test/caches/phpstan.cache
610
bootstrapFiles:
711
- ./test/phpstan/runkit7.stub.php
812
ignoreErrors:

src/Phpunit/MockedFunction.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
namespace QratorLabs\Smocky\Phpunit;
66

77
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
8+
use PHPUnit\Framework\MockObject\Generator\Generator;
9+
use PHPUnit\Framework\MockObject\MockObject;
810
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
911
use PHPUnit\Framework\TestCase;
1012
use QratorLabs\Smocky\EmptyClass;
1113
use QratorLabs\Smocky\Functions\MockedFunction as GenericMockedFunction;
1214
use ReflectionException;
1315

16+
use function assert;
17+
1418
class MockedFunction
1519
{
1620
/** @var GenericMockedFunction */
@@ -48,14 +52,26 @@ static function (...$args) use (&$mockObject, &$method) {
4852
}
4953
);
5054

51-
$method = $this->mockedFunction->getShortName();
52-
$mockObject = $testCase->getMockBuilder(EmptyClass::class)
53-
->disableOriginalConstructor()
54-
->disableOriginalClone()
55-
->disableArgumentCloning()
56-
->disallowMockingUnknownTypes()
57-
->addMethods([$method])
58-
->getMock();
55+
$method = $this->mockedFunction->getShortName();
56+
57+
$mockObject = (new Generator())->testDouble(
58+
EmptyClass::class,
59+
true,
60+
true,
61+
[$method],
62+
[],
63+
'',
64+
false,
65+
false,
66+
true,
67+
false,
68+
false,
69+
null,
70+
false
71+
);
72+
assert($mockObject instanceof EmptyClass);
73+
assert($mockObject instanceof MockObject);
74+
$testCase->registerMockObject($mockObject);
5975

6076
if ($invocationRule === null) {
6177
$this->invocationMocker = $mockObject->method($method);

src/Phpunit/MockedMethod.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
namespace QratorLabs\Smocky\Phpunit;
66

77
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
8+
use PHPUnit\Framework\MockObject\Generator\Generator;
89
use PHPUnit\Framework\MockObject\MockObject;
910
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
1011
use PHPUnit\Framework\TestCase;
1112
use QratorLabs\Smocky\ClassMethod\MockedClassMethod;
1213
use QratorLabs\Smocky\EmptyClass;
1314
use ReflectionException;
1415

16+
use function assert;
17+
1518
class MockedMethod
1619
{
1720
/**
@@ -44,14 +47,25 @@ public function __construct(
4447
string $method,
4548
InvocationOrder $invocationRule = null
4649
) {
47-
$this->mockObject = $testCase
48-
->getMockBuilder(EmptyClass::class)
49-
->disableOriginalConstructor()
50-
->disableOriginalClone()
51-
->disableArgumentCloning()
52-
->disallowMockingUnknownTypes()
53-
->addMethods([$method])
54-
->getMock();
50+
$mockObject = (new Generator())->testDouble(
51+
EmptyClass::class,
52+
true,
53+
true,
54+
[$method],
55+
[],
56+
'',
57+
false,
58+
false,
59+
true,
60+
false,
61+
false,
62+
null,
63+
false
64+
);
65+
assert($mockObject instanceof EmptyClass);
66+
assert($mockObject instanceof MockObject);
67+
$this->mockObject = $mockObject;
68+
$testCase->registerMockObject($this->mockObject);
5569

5670
if ($invocationRule === null) {
5771
$this->invocationMocker = $this->mockObject->method($method);

test/caches/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!/.gitignore

test/phpunit/Constant/UndefinedClassConstantTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
*/
2525
class UndefinedClassConstantTest extends TestCase
2626
{
27-
public function testMissingConstantException(): void
28-
{
29-
$this->expectException(ReflectionException::class);
30-
new UndefinedClassConstant(ClassWithConstants::class, 'CONST_UNDEFINED');
31-
}
32-
3327
/**
3428
* @return Generator<string, array{string, string}>
3529
*/
@@ -54,26 +48,29 @@ public function dataCoreConstants(): Generator
5448
*/
5549
public function testCoreConstants(string $class, string $constantName): void
5650
{
57-
$ex = new class extends RuntimeException {
51+
$ex = new class extends RuntimeException {
5852
};
5953
$cls = get_class($ex);
6054

61-
$prev = set_error_handler(static function (int $errno, string $errstr) use ($cls) {
55+
set_error_handler(static function (int $errno, string $errstr) use ($cls) {
6256
throw new $cls($errstr, $errno);
6357
}, E_WARNING);
6458

6559

6660
$this->expectException($cls);
6761
try {
6862
new UndefinedClassConstant($class, $constantName);
69-
} catch (Throwable $ex) {
70-
if ($prev) {
71-
set_error_handler($prev);
72-
}
73-
throw $ex;
63+
} finally {
64+
restore_error_handler();
7465
}
7566
}
7667

68+
public function testMissingConstantException(): void
69+
{
70+
$this->expectException(ReflectionException::class);
71+
new UndefinedClassConstant(ClassWithConstants::class, 'CONST_UNDEFINED');
72+
}
73+
7774
/**
7875
* @param string $class
7976
* @param string $constantName

test/phpunit/Constant/UndefinedGlobalConstantTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
use function set_error_handler;
1818
use function uniqid;
1919

20-
use const E_WARNING;
21-
2220
/**
2321
* @internal
2422
*/
@@ -36,19 +34,15 @@ public function testOnlyUserDefined(): void
3634
};
3735
$cls = get_class($ex);
3836

39-
$prev = set_error_handler(static function (int $errno, string $errstr) use ($cls) {
37+
set_error_handler(static function (int $errno, string $errstr) use ($cls) {
4038
throw new $cls($errstr, $errno);
41-
}, E_WARNING);
42-
39+
});
4340

4441
$this->expectException($cls);
4542
try {
4643
new UndefinedGlobalConstant('PHP_VERSION');
47-
} catch (Throwable $ex) {
48-
if ($prev) {
49-
set_error_handler($prev);
50-
}
51-
throw $ex;
44+
} finally {
45+
restore_error_handler();
5246
}
5347
}
5448

0 commit comments

Comments
 (0)