Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for phpunit 11 #57

Merged
merged 7 commits into from
Feb 10, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2']
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
composer-flags: ['', '--prefer-lowest']
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": ">=7.4",
"doctrine/inflector": "^2.0",
"phpdocumentor/type-resolver": "^1.7",
"phpunit/phpunit": "^9.0 || ^10.0"
"phpunit/phpunit": "^9.0 || ^10.0 || ^11.0"
},
"require-dev": {
"phpmd/phpmd": "@stable",
Expand Down
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ parameters:
message: "#^Class DigitalRevolution\\\\AccessorPairConstraint\\\\Tests\\\\Integration\\\\data\\\\TestEnum not found\\.$#"
count: 2
path: tests/Unit/Constraint/ValueProvider/Compound/InstanceProviderTest.php

-
message: "#^Call to function method_exists\\(\\) with 'PHPUnit\\\\\\\\Runner\\\\\\\\Version' and 'majorVersionNumber' will always evaluate to false\\.$#"
count: 1
path: src/Constraint/ValueProvider/Compound/InstanceProvider.php
18 changes: 10 additions & 8 deletions src/Constraint/AccessorPairConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ReflectionClass;
use ReflectionMethod;
use ReflectionParameter;
use SebastianBergmann\Exporter\Exporter;

class AccessorPairConstraint extends Constraint
{
Expand Down Expand Up @@ -131,7 +132,6 @@ protected function testPropertyDefaults(array $accessorPairs): void

/**
* Test all accessorPairs, by passing test values to the setter and expect the exact same value back from the getter.
*
* @throws Exception
*/
protected function testAccessorPair(AccessorPair $accessorPair): void
Expand All @@ -154,7 +154,6 @@ protected function testAccessorPair(AccessorPair $accessorPair): void
/**
* The setter's parameter has a default value
* Call the setter without provider a parameter. Then call the getter and expect the default value return.
*
* @throws Exception
*/
protected function testOptionalParameter(AccessorPair $accessorPair, ReflectionParameter $parameter): void
Expand All @@ -173,10 +172,11 @@ protected function testOptionalParameter(AccessorPair $accessorPair, ReflectionP
$storedValue = $accessorPair->getGetMethod()->invoke($instance);

if ($storedValue !== $expectedReturn) {
$exporter = new Exporter();
$this->fail(
$accessorPair->getClass()->getNamespaceName(),
"Stored value (" . $this->exporter()->export($storedValue) . ") does not match " .
"default value (" . $this->exporter()->export($expectedReturn) . ")"
"Stored value (" . $exporter->export($storedValue) . ") does not match " .
"default value (" . $exporter->export($expectedReturn) . ")"
);
}
}
Expand Down Expand Up @@ -218,10 +218,11 @@ protected function testParameter(ReflectionParameter $parameter, AccessorPair $a
}

if ($storedValue !== $expectedReturn) {
$exporter = new Exporter();
$this->fail(
$accessorPair->getClass()->getNamespaceName(),
"Stored value (" . $this->exporter()->export($storedValue) . ") does not match " .
"given value (" . $this->exporter()->export($expectedReturn) . ")"
"Stored value (" . $exporter->export($storedValue) . ") does not match " .
"given value (" . $exporter->export($expectedReturn) . ")"
);
}
}
Expand Down Expand Up @@ -263,10 +264,11 @@ protected function testConstructorPair(ConstructorPair $constructorPair): void
}

if ($storedValue !== $expectedReturn) {
$exporter = new Exporter();
$this->fail(
$constructorPair->getClass()->getNamespaceName(),
"Stored value (" . $this->exporter()->export($storedValue) . ") does not match " .
"given value (" . $this->exporter()->export($expectedReturn) . ")"
"Stored value (" . $exporter->export($storedValue) . ") does not match " .
"given value (" . $exporter->export($expectedReturn) . ")"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DigitalRevolution\AccessorPairConstraint\Constraint\ValueProvider\ValueProvider;
use LogicException;
use PHPUnit\Framework\MockObject\Generator\Generator;
use PHPUnit\Runner\Version;
use UnitEnum;

class InstanceProvider implements ValueProvider
Expand Down Expand Up @@ -38,7 +39,11 @@ public function getValues(): array
/** @var \PHPUnit\Framework\MockObject\Generator $mockGenerator */
$mockGenerator = new Generator();
if (method_exists($mockGenerator, 'testDouble')) {
$instance = $mockGenerator->testDouble($this->typehint, true, [], [], '', false);
if (method_exists(Version::class, 'majorVersionNumber') && Version::majorVersionNumber() >= 11) {
$instance = $mockGenerator->testDouble($this->typehint, true, true, [], [], '', false);
} else {
$instance = $mockGenerator->testDouble($this->typehint, true, [], [], '', false);
}
} else {
$instance = $mockGenerator->getMock($this->typehint, [], [], '', false);
}
Expand Down
Loading