Skip to content

Commit 3b653b8

Browse files
committed
Converted #736 test case into an integration test
While the `.phpt` test was valid, it does not produce coverage nor mutation test output, and requires to run in a separate test: converting it back to a more typical PHPUnit test makes it a bit quicker to run, and also puts it under `vimeo/psalm`'s watchful eyes.
1 parent f8f50d2 commit 3b653b8

File tree

3 files changed

+87
-58
lines changed

3 files changed

+87
-58
lines changed

tests/ProxyManagerTest/Functional/AccessInterceptorValueHolderFunctionalTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use ProxyManagerTestAsset\ClassWithSelfHint;
2626
use ProxyManagerTestAsset\EmptyClass;
2727
use ProxyManagerTestAsset\OtherObjectAccessClass;
28+
use ProxyManagerTestAsset\ReferenceIncrementDecrementClass;
2829
use ProxyManagerTestAsset\VoidCounter;
2930
use ReflectionClass;
3031
use ReflectionProperty;
@@ -696,6 +697,79 @@ public function testWillInterceptAndReturnEarlyOnVoidMethod(): void
696697
self::assertSame($increment + $addMore + 1, $object->counter);
697698
}
698699

700+
public function testByReferencePassedArgumentsAreGivenAsReferenceToInterceptorCallbacks(): void
701+
{
702+
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy(
703+
new ReferenceIncrementDecrementClass(),
704+
[
705+
'incrementReference' => static function (
706+
object $proxy,
707+
ReferenceIncrementDecrementClass $instance,
708+
string $method,
709+
array $args,
710+
bool &$returnEarly
711+
): void {
712+
self::assertSame(0, $args['reference']);
713+
714+
$returnEarly = true;
715+
$args['reference'] = 5;
716+
},
717+
]
718+
);
719+
720+
$number = 0;
721+
722+
$proxy->incrementReference($number);
723+
724+
self::assertSame(5, $number, 'Number was changed by interceptor');
725+
}
726+
727+
public function testByReferenceArgumentsAreForwardedThroughInterceptorsAndSubject(): void
728+
{
729+
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy(
730+
new ReferenceIncrementDecrementClass(),
731+
[
732+
'incrementReference' => static function (
733+
object $proxy,
734+
ReferenceIncrementDecrementClass $instance,
735+
string $method,
736+
array $args,
737+
bool &$returnEarly
738+
): void {
739+
self::assertSame(0, $args['reference']);
740+
741+
$returnEarly = false;
742+
$args['reference'] = 5;
743+
},
744+
],
745+
[
746+
'incrementReference' => static function (
747+
object $proxy,
748+
ReferenceIncrementDecrementClass $instance,
749+
string $method,
750+
array $args,
751+
mixed $returnValue,
752+
bool &$returnEarly
753+
): void {
754+
self::assertIsInt($args['reference']);
755+
756+
$returnEarly = false;
757+
$args['reference'] *= 2;
758+
},
759+
]
760+
);
761+
762+
$number = 0;
763+
764+
$proxy->incrementReference($number);
765+
766+
self::assertSame(
767+
12,
768+
$number,
769+
'Number was changed by prefix interceptor, then incremented, then doubled by suffix interceptor'
770+
);
771+
}
772+
699773
private static function assertByRefVariableValueSame(mixed $expected, mixed & $actual): void
700774
{
701775
self::assertSame($expected, $actual);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ProxyManagerTestAsset;
6+
7+
class ReferenceIncrementDecrementClass
8+
{
9+
public function incrementReference(int & $reference): void
10+
{
11+
$reference += 1;
12+
}
13+
}

tests/language-feature-scripts/access-interceptor-value-holder-intercepting-keeps-parameter-references.phpt

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

0 commit comments

Comments
 (0)