Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"require": {
"php": ">=5.6",
"php-mock/php-mock": "^2.5",
"phpunit/php-text-template": "^1 || ^2 || ^3 || ^4"
"phpunit/php-text-template": "^1 || ^2 || ^3 || ^4 || ^5"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9 || ^10 || ^11"
"phpunit/phpunit": "^5.7.27 || ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12"
},
"archive": {
"exclude": ["/tests"]
Expand Down
7 changes: 6 additions & 1 deletion tests/MockDelegateFunctionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function testSameSignaturesProduceSameClass()
*
* @doesNotPerformAssertions
*/
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
#[\PHPUnit\Framework\Attributes\DataProvider('provideTestBackupStaticAttributes')]
#[\PHPUnit\Framework\Attributes\BackupStaticProperties(true)]
public function testBackupStaticAttributes()
{
$builder = new MockDelegateFunctionBuilder();
Expand All @@ -97,12 +100,14 @@ public static function provideTestBackupStaticAttributes()
*
* @doesNotPerformAssertions
*/
#[\PHPUnit\Framework\Attributes\RunInSeparateProcess]
#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
public function testDeserializationInNewProcess()
{
$builder = new MockDelegateFunctionBuilder();
$builder->build("min");

$data = serialize($this->getMockForAbstractClass($builder->getFullyQualifiedClassName()));
$data = serialize($this->getMockBuilder($builder->getFullyQualifiedClassName())->getMock());

unserialize($data);
}
Expand Down
32 changes: 26 additions & 6 deletions tests/MockDelegateFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ protected function setUpCompat()
*
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function testDelegateReturnsMockResult()
{
$expected = 3;
$mock = $this->getMockForAbstractClass($this->className);

$expected = 3;
$mockBuilder = $this->getMockBuilder($this->className);

// `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
if (method_exists($mockBuilder, 'onlyMethods')) {
$mockBuilder->onlyMethods([MockDelegateFunctionBuilder::METHOD]);
} else {
$mockBuilder->setMethods([MockDelegateFunctionBuilder::METHOD]);
}

$mock = $mockBuilder->getMock();

$mock->expects($this->once())
->method(MockDelegateFunctionBuilder::METHOD)
->willReturn($expected);
Expand All @@ -53,14 +63,24 @@ public function testDelegateReturnsMockResult()
*
* @test
*/
#[\PHPUnit\Framework\Attributes\Test]
public function testDelegateForwardsArguments()
{
$mock = $this->getMockForAbstractClass($this->className);

$mockBuilder = $this->getMockBuilder($this->className);

// `setMethods` is gone from phpunit 10, alternative is `onlyMethods`
if (method_exists($mockBuilder, 'onlyMethods')) {
$mockBuilder->onlyMethods([MockDelegateFunctionBuilder::METHOD]);
} else {
$mockBuilder->setMethods([MockDelegateFunctionBuilder::METHOD]);
}

$mock = $mockBuilder->getMock();

$mock->expects($this->once())
->method(MockDelegateFunctionBuilder::METHOD)
->with(1, 2);

call_user_func($mock->getCallable(), 1, 2);
}
}