Skip to content

Commit fe1e574

Browse files
committed
Move exception matching code to a compat trait
1 parent d484eb0 commit fe1e574

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

tests/Doctrine/Tests/ORM/Functional/Ticket/GH10449Test.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
use Doctrine\ORM\Mapping as ORM;
99
use Doctrine\ORM\Mapping\MappingException;
1010
use Doctrine\Tests\OrmTestCase;
11-
12-
use function get_parent_class;
13-
use function method_exists;
11+
use Doctrine\Tests\PHPUnitCompatibility\ExceptionMatching;
1412

1513
class GH10449Test extends OrmTestCase
1614
{
15+
use ExceptionMatching;
16+
1717
public function testToManyAssociationOnMappedSuperclassShallBeRejected(): void
1818
{
1919
$em = $this->getTestEntityManager();
@@ -25,18 +25,6 @@ public function testToManyAssociationOnMappedSuperclassShallBeRejected(): void
2525
// https://github.com/doctrine/orm/pull/10398
2626
$em->getClassMetadata(GH10449Entity::class);
2727
}
28-
29-
/**
30-
* Override for BC with PHPUnit <8
31-
*/
32-
public function expectExceptionMessageMatches(string $regularExpression): void
33-
{
34-
if (method_exists(get_parent_class($this), 'expectExceptionMessageMatches')) {
35-
parent::expectExceptionMessageMatches($regularExpression);
36-
} else {
37-
parent::expectExceptionMessageRegExp($regularExpression);
38-
}
39-
}
4028
}
4129

4230
/**

tests/Doctrine/Tests/ORM/Functional/Ticket/GH10454Test.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
use Doctrine\ORM\Mapping as ORM;
88
use Doctrine\ORM\Mapping\MappingException;
99
use Doctrine\Tests\OrmTestCase;
10+
use Doctrine\Tests\PHPUnitCompatibility\ExceptionMatching;
1011
use Generator;
1112

12-
use function get_parent_class;
13-
use function method_exists;
14-
1513
class GH10454Test extends OrmTestCase
1614
{
15+
use ExceptionMatching;
16+
1717
/**
1818
* @param class-string $className
1919
*
@@ -34,18 +34,6 @@ public function classesThatOverrideFieldNames(): Generator
3434
yield 'Entity class that redeclares a protected field inherited from a base entity' => [GH10454EntityChildProtected::class];
3535
yield 'Entity class that redeclares a protected field inherited from a mapped superclass' => [GH10454MappedSuperclassChildProtected::class];
3636
}
37-
38-
/**
39-
* Override for BC with PHPUnit <8
40-
*/
41-
public function expectExceptionMessageMatches(string $regularExpression): void
42-
{
43-
if (method_exists(get_parent_class($this), 'expectExceptionMessageMatches')) {
44-
parent::expectExceptionMessageMatches($regularExpression);
45-
} else {
46-
parent::expectExceptionMessageRegExp($regularExpression);
47-
}
48-
}
4937
}
5038

5139
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\PHPUnitCompatibility;
6+
7+
use function get_parent_class;
8+
use function method_exists;
9+
10+
trait ExceptionMatching
11+
{
12+
/**
13+
* Override for BC with PHPUnit <8
14+
*/
15+
public function expectExceptionMessageMatches(string $regularExpression): void
16+
{
17+
if (method_exists(get_parent_class($this), 'expectExceptionMessageMatches')) {
18+
parent::expectExceptionMessageMatches($regularExpression);
19+
} else {
20+
parent::expectExceptionMessageRegExp($regularExpression);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)