Skip to content

Commit d5a20ab

Browse files
committed
Fix testMarkTestSkipped compatibility
1 parent a499352 commit d5a20ab

File tree

20 files changed

+52
-35
lines changed

20 files changed

+52
-35
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [8.1, 8.2, 8.3, 8.4]
11+
php: [8.2, 8.3, 8.4]
1212

1313
steps:
1414
- name: Checkout code

codeception.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
namespace: Tests
2+
support_namespace: Support
3+
4+
settings:
5+
shuffle: true
6+
lint: true
17
paths:
28
tests: tests
39
output: tests/_output
4-
data: tests/_data
5-
support: tests/_support
6-
envs: tests/_envs
7-
actor_suffix: Tester
10+
support: tests/Support
11+
data: tests/Support/Data
12+

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"homepage": "https://codeception.com/",
2424
"require": {
25-
"php": "^8.1",
25+
"php": "^8.2",
2626
"codeception/codeception": "*@dev",
2727
"codeception/lib-asserts": "^2.2"
2828
},

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A Codeception module containing various assertions.
99

1010
## Requirements
1111

12-
* `PHP 8.1` or higher.
12+
* `PHP 8.2` or higher.
1313

1414
## Installation
1515

src/Codeception/Module/Asserts.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Codeception\Module;
66

7+
use Throwable;
8+
use function get_debug_type;
9+
710
/**
811
* Special module for using asserts in your tests.
912
*/
@@ -31,10 +34,8 @@ class Asserts extends AbstractAsserts
3134
* $this->doSomethingBad();
3235
* });
3336
* ```
34-
*
35-
* @param \Throwable|string $throwable
3637
*/
37-
public function expectThrowable($throwable, callable $callback): void
38+
public function expectThrowable(string|Throwable $throwable, callable $callback): void
3839
{
3940
if (is_object($throwable)) {
4041
$class = get_class($throwable);
@@ -48,7 +49,7 @@ public function expectThrowable($throwable, callable $callback): void
4849

4950
try {
5051
$callback();
51-
} catch (\Throwable $t) {
52+
} catch (Throwable $t) {
5253
$this->checkThrowable($t, $class, $msg, $code);
5354
return;
5455
}
@@ -60,13 +61,13 @@ public function expectThrowable($throwable, callable $callback): void
6061
* Check if the given throwable matches the expected data,
6162
* fail (throws an exception) if it does not.
6263
*/
63-
protected function checkThrowable(\Throwable $throwable, string $expectedClass, ?string $expectedMsg, $expectedCode = null): void
64+
protected function checkThrowable(Throwable $throwable, string $expectedClass, ?string $expectedMsg, int|null $expectedCode = null): void
6465
{
6566
if (!($throwable instanceof $expectedClass)) {
6667
$this->fail(sprintf(
6768
"Exception of class '%s' expected to be thrown, but class '%s' was caught",
6869
$expectedClass,
69-
get_class($throwable)
70+
get_debug_type($throwable)
7071
));
7172
}
7273

tests/_data/DummyClass.php renamed to tests/Support/Data/DummyClass.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
declare(strict_types=1);
44

5+
namespace Support\Data;
6+
57
class DummyClass
68
{
79
private int $foo;
8-
10+
911
private static int $staticFoo;
1012
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
<?php
22

3+
declare(strict_types=1);
4+
5+
namespace Tests\Support;
36

47
/**
58
* Inherited Methods
6-
* @method void wantToTest($text)
79
* @method void wantTo($text)
10+
* @method void wantToTest($text)
811
* @method void execute($callable)
912
* @method void expectTo($prediction)
1013
* @method void expect($prediction)
1114
* @method void amGoingTo($argumentation)
1215
* @method void am($role)
1316
* @method void lookForwardTo($achieveValue)
1417
* @method void comment($description)
15-
* @method void pause()
18+
* @method void pause($vars = [])
1619
*
1720
* @SuppressWarnings(PHPMD)
1821
*/
1922
class UnitTester extends \Codeception\Actor
2023
{
2124
use _generated\UnitTesterActions;
2225

23-
/**
24-
* Define custom actions here
25-
*/
26+
/**
27+
* Define custom actions here
28+
*/
2629
}

tests/Support/_generated/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/Unit.suite.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
actor: UnitTester
2+
suite_namespace: Tests\Unit
3+
modules:
4+
enabled: []

tests/unit/Codeception/Module/AssertsTest.php renamed to tests/Unit/Codeception/Module/AssertsTest.php

+16-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
use PHPUnit\Framework\AssertionFailedError;
1313
use PHPUnit\Framework\Constraint\IsEqual;
1414
use PHPUnit\Framework\IncompleteTestError;
15+
use PHPUnit\Framework\SkippedTestError;
1516
use PHPUnit\Framework\SkippedWithMessageException;
17+
use PHPUnit\Runner\Version as PHPUnitVersion;
1618
use RuntimeException;
1719
use stdClass;
1820

@@ -46,14 +48,14 @@ public function testPHPUnitAsserts()
4648
{
4749
$this->module->assertArrayHasKey('one', ['one' => 1, 'two' => 2]);
4850
$this->module->assertArrayNotHasKey('three', ['one' => 1, 'two' => 2]);
49-
$this->module->assertClassHasAttribute('foo', \DummyClass::class);
50-
$this->module->assertClassHasStaticAttribute('staticFoo', \DummyClass::class);
51-
$this->module->assertClassNotHasAttribute('bar', \DummyClass::class);
52-
$this->module->assertClassNotHasStaticAttribute('staticBar', \DummyClass::class);
51+
$this->module->assertClassHasAttribute('foo', \Support\Data\DummyClass::class);
52+
$this->module->assertClassHasStaticAttribute('staticFoo', \Support\Data\DummyClass::class);
53+
$this->module->assertClassNotHasAttribute('bar', \Support\Data\DummyClass::class);
54+
$this->module->assertClassNotHasStaticAttribute('staticBar', \Support\Data\DummyClass::class);
5355
$this->module->assertContains(1, [1, 2]);
5456
$this->module->assertContainsEquals(2, [1, 2]);
55-
$this->module->assertContainsOnly(\DummyClass::class, [new \DummyClass(), new \DummyClass()]);
56-
$this->module->assertContainsOnlyInstancesOf(\DummyClass::class, [new \DummyClass(), new \DummyClass()]);
57+
$this->module->assertContainsOnly(\Support\Data\DummyClass::class, [new \Support\Data\DummyClass(), new \Support\Data\DummyClass()]);
58+
$this->module->assertContainsOnlyInstancesOf(\Support\Data\DummyClass::class, [new \Support\Data\DummyClass(), new \Support\Data\DummyClass()]);
5759
$this->module->assertCount(3, [1, 2, 3]);
5860
$this->module->assertDirectoryDoesNotExist(__DIR__.'notExist');
5961
$this->module->assertDirectoryExists(__DIR__);
@@ -130,7 +132,7 @@ public function testPHPUnitAsserts()
130132
$this->module->assertNan(sqrt(-1));
131133
$this->module->assertNotContains('three', ['one', 'two']);
132134
$this->module->assertNotContainsEquals(3, [1, 2]);
133-
$this->module->assertNotContainsOnly(\DummyClass::class, [new \DummyClass(), new Exception()]);
135+
$this->module->assertNotContainsOnly(\Support\Data\DummyClass::class, [new \Support\Data\DummyClass(), new Exception()]);
134136
$this->module->assertNotCount(1, ['one', 'two']);
135137
$this->module->assertNotEmpty([1]);
136138
$this->module->assertNotEquals(true, false);
@@ -150,8 +152,8 @@ public function testPHPUnitAsserts()
150152
$this->module->assertNotTrue(null);
151153
$this->module->assertNotTrue('foo');
152154
$this->module->assertNull(null);
153-
$this->module->assertObjectHasAttribute('foo', new \DummyClass());
154-
$this->module->assertObjectNotHasAttribute('bar', new \DummyClass());
155+
$this->module->assertObjectHasAttribute('foo', new \Support\Data\DummyClass());
156+
$this->module->assertObjectNotHasAttribute('bar', new \Support\Data\DummyClass());
155157
$this->module->assertSame(1, 1);
156158
$this->module->assertSameSize([1, 2, 3], [1, 2, 3]);
157159
$this->module->assertStringContainsString('bar', 'foobar');
@@ -280,8 +282,12 @@ public function testMarkTestIncomplete()
280282

281283
public function testMarkTestSkipped()
282284
{
283-
$this->expectException(SkippedWithMessageException::class);
284285
$this->expectExceptionMessage('foobar');
286+
if (PHPUnitVersion::series() < 10) {
287+
$this->expectException(SkippedTestError::class);
288+
} else {
289+
$this->expectException(SkippedWithMessageException::class);
290+
}
285291

286292
$this->module->markTestSkipped('foobar');
287293
}

tests/_support/_generated/.gitignore

-1
This file was deleted.

tests/unit.suite.yml

-5
This file was deleted.

0 commit comments

Comments
 (0)