Skip to content

PHPUnit 12 #50

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

Merged
merged 3 commits into from
Feb 14, 2025
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"require": {
"php": "^7.4 | ^8.0",
"phpunit/phpunit": "^8.4 | ^9.0 | ^10.0 | ^11"
"phpunit/phpunit": "^8.4 | ^9.0 | ^10.0 | ^11 | ^12"
},
"require-dev": {
"consolidation/robo": "^3.0"
Expand Down
6 changes: 5 additions & 1 deletion src/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,11 @@ public static function constructEmptyExcept(
private static function generateMock()
{
$args = func_get_args();
if (version_compare(PHPUnitVersion::series(), '11', '>=')) {
// PHPUnit 11 added the optional parameter $markAsMockObject:
// https://github.com/sebastianbergmann/phpunit/commit/db9ae302fe1ad89451ecfacc850e88ab7c6df5a3
// The parameter was removed in PHPUnit 12:
// https://github.com/sebastianbergmann/phpunit/commit/a98e3939c74f6103cbeb7a785b73eb4a10784474
if (version_compare(PHPUnitVersion::series(), '11', '>=') && version_compare(PHPUnitVersion::series(), '12', '<')) {
if (!is_bool($args[1]) || !is_bool($args[2])) {
$additionalParameters = [];
if (!is_bool($args[1])) {
Expand Down
8 changes: 8 additions & 0 deletions tests/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Codeception\Stub;
use Codeception\Stub\StubMarshaler;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\NoMoreReturnValuesConfiguredException;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -231,6 +232,7 @@ public static function matcherAndFailMessageProvider(): array
/**
* @dataProvider matcherAndFailMessageProvider
*/
#[DataProvider('matcherAndFailMessageProvider')]
Comment on lines 232 to +235
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the annotations because attributes are not available in PHPUnit < 10

public function testExpectedMethodIsCalledFail(StubMarshaler $stubMarshaler, string $failMessage)
{
$mock = Stub::makeEmptyExcept('DummyClass', 'call', ['targetMethod' => $stubMarshaler], $this);
Expand Down Expand Up @@ -282,6 +284,7 @@ public static function matcherProvider(): array
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithMake(int $count, StubMarshaler $matcher, $expected = false)
{
$dummy = Stub::make('DummyClass', ['goodByeWorld' => $matcher], $this);
Expand All @@ -292,6 +295,7 @@ public function testMethodMatcherWithMake(int $count, StubMarshaler $matcher, $e
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithMakeEmpty(int $count, StubMarshaler $matcher)
{
$dummy = Stub::makeEmpty('DummyClass', ['goodByeWorld' => $matcher], $this);
Expand All @@ -302,6 +306,7 @@ public function testMethodMatcherWithMakeEmpty(int $count, StubMarshaler $matche
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithMakeEmptyExcept(int $count, StubMarshaler $matcher)
{
$dummy = Stub::makeEmptyExcept('DummyClass', 'getCheckMe', ['goodByeWorld' => $matcher], $this);
Expand All @@ -312,6 +317,7 @@ public function testMethodMatcherWithMakeEmptyExcept(int $count, StubMarshaler $
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithConstruct(int $count, StubMarshaler $matcher)
{
$dummy = Stub::construct('DummyClass', [], ['goodByeWorld' => $matcher], $this);
Expand All @@ -322,6 +328,7 @@ public function testMethodMatcherWithConstruct(int $count, StubMarshaler $matche
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithConstructEmpty(int $count, StubMarshaler $matcher)
{
$dummy = Stub::constructEmpty('DummyClass', [], ['goodByeWorld' => $matcher], $this);
Expand All @@ -332,6 +339,7 @@ public function testMethodMatcherWithConstructEmpty(int $count, StubMarshaler $m
/**
* @dataProvider matcherProvider
*/
#[DataProvider('matcherProvider')]
public function testMethodMatcherWithConstructEmptyExcept(int $count, StubMarshaler $matcher)
{
$dummy = Stub::constructEmptyExcept(
Expand Down