-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support property hooks for extendable classes
- Loading branch information
1 parent
97375eb
commit 6963b30
Showing
9 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/_files/mock-object/ExtendableClassWithPropertyWithGetHook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\MockObject; | ||
|
||
class ExtendableClassWithPropertyWithGetHook | ||
{ | ||
public string $property { | ||
get { | ||
return 'value'; | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/_files/mock-object/ExtendableClassWithPropertyWithSetHook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace PHPUnit\TestFixture\MockObject; | ||
|
||
class ExtendableClassWithPropertyWithSetHook | ||
{ | ||
public string $property { | ||
set (string $value) { | ||
$this->property = $value; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/end-to-end/mock-objects/generator/extendable_class_get_property_hook.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
Extendable class with property with non-final get property hook | ||
--SKIPIF-- | ||
<?php declare(strict_types=1); | ||
if (!method_exists(ReflectionProperty::class, 'getHooks')) { | ||
print 'skip: PHP 8.4 is required.'; | ||
} | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
class Foo | ||
{ | ||
public string $bar { | ||
get { | ||
return 'value'; | ||
} | ||
} | ||
} | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
$generator = new \PHPUnit\Framework\MockObject\Generator\Generator; | ||
|
||
$testDoubleClass = $generator->generate( | ||
Foo::class, | ||
false, | ||
false, | ||
[], | ||
'TestStubFoo', | ||
); | ||
|
||
print $testDoubleClass->classCode(); | ||
--EXPECTF-- | ||
declare(strict_types=1); | ||
|
||
class TestStubFoo extends Foo implements PHPUnit\Framework\MockObject\StubInternal | ||
{ | ||
use PHPUnit\Framework\MockObject\StubApi; | ||
use PHPUnit\Framework\MockObject\GeneratedAsTestStub; | ||
use PHPUnit\Framework\MockObject\Method; | ||
use PHPUnit\Framework\MockObject\DoubledCloneMethod; | ||
|
||
public string $bar { | ||
get { | ||
return $this->__phpunit_getInvocationHandler()->invoke( | ||
new \PHPUnit\Framework\MockObject\Invocation( | ||
'TestStubFoo', '$bar::get', [], 'string', $this, false | ||
) | ||
); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests/end-to-end/mock-objects/generator/extendable_class_get_set_property_hook.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--TEST-- | ||
Extendable class with property with non-final get and set property hooks | ||
--SKIPIF-- | ||
<?php declare(strict_types=1); | ||
if (!method_exists(ReflectionProperty::class, 'getHooks')) { | ||
print 'skip: PHP 8.4 is required.'; | ||
} | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
class Foo | ||
{ | ||
public string $bar { | ||
get { | ||
return 'value'; | ||
} | ||
|
||
set (string $value) { | ||
$this->bar = $value; | ||
} | ||
} | ||
} | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
$generator = new \PHPUnit\Framework\MockObject\Generator\Generator; | ||
|
||
$testDoubleClass = $generator->generate( | ||
Foo::class, | ||
false, | ||
false, | ||
[], | ||
'TestStubFoo', | ||
); | ||
|
||
print $testDoubleClass->classCode(); | ||
--EXPECTF-- | ||
declare(strict_types=1); | ||
|
||
class TestStubFoo extends Foo implements PHPUnit\Framework\MockObject\StubInternal | ||
{ | ||
use PHPUnit\Framework\MockObject\StubApi; | ||
use PHPUnit\Framework\MockObject\GeneratedAsTestStub; | ||
use PHPUnit\Framework\MockObject\Method; | ||
use PHPUnit\Framework\MockObject\DoubledCloneMethod; | ||
|
||
public string $bar { | ||
get { | ||
return $this->__phpunit_getInvocationHandler()->invoke( | ||
new \PHPUnit\Framework\MockObject\Invocation( | ||
'TestStubFoo', '$bar::get', [], 'string', $this, false | ||
) | ||
); | ||
} | ||
|
||
set (string $value) { | ||
$this->__phpunit_getInvocationHandler()->invoke( | ||
new \PHPUnit\Framework\MockObject\Invocation( | ||
'TestStubFoo', '$bar::set', [$value], 'void', $this, false | ||
) | ||
); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/end-to-end/mock-objects/generator/extendable_class_set_property_hook.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
Extendable class with property with non-final set property hook | ||
--SKIPIF-- | ||
<?php declare(strict_types=1); | ||
if (!method_exists(ReflectionProperty::class, 'getHooks')) { | ||
print 'skip: PHP 8.4 is required.'; | ||
} | ||
--FILE-- | ||
<?php declare(strict_types=1); | ||
class Foo | ||
{ | ||
public string $bar { | ||
set (string $value) { | ||
$this->bar = $value; | ||
} | ||
} | ||
} | ||
|
||
require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
||
$generator = new \PHPUnit\Framework\MockObject\Generator\Generator; | ||
|
||
$testDoubleClass = $generator->generate( | ||
Foo::class, | ||
false, | ||
false, | ||
[], | ||
'TestStubFoo', | ||
); | ||
|
||
print $testDoubleClass->classCode(); | ||
--EXPECTF-- | ||
declare(strict_types=1); | ||
|
||
class TestStubFoo extends Foo implements PHPUnit\Framework\MockObject\StubInternal | ||
{ | ||
use PHPUnit\Framework\MockObject\StubApi; | ||
use PHPUnit\Framework\MockObject\GeneratedAsTestStub; | ||
use PHPUnit\Framework\MockObject\Method; | ||
use PHPUnit\Framework\MockObject\DoubledCloneMethod; | ||
|
||
public string $bar { | ||
set (string $value) { | ||
$this->__phpunit_getInvocationHandler()->invoke( | ||
new \PHPUnit\Framework\MockObject\Invocation( | ||
'TestStubFoo', '$bar::set', [$value], 'void', $this, false | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters