Skip to content

Commit 996d98e

Browse files
minor symfony#58391 relax mock class name matching (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- relax mock class name matching | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Instead of performing some fuzzy matching on the automatically generated mock name (the pattern varies between different PHPUnit versions) we can simply use the actual exact class name. Commits ------- 2c99e00 relax mock class name matching
2 parents a6149f9 + 2c99e00 commit 996d98e

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

src/Symfony/Component/Messenger/Tests/Middleware/SendMessageMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testItSendsTheMessageToAssignedSender()
4444
/* @var SentStamp $stamp */
4545
$this->assertInstanceOf(SentStamp::class, $stamp = $envelope->last(SentStamp::class), 'it adds a sent stamp');
4646
$this->assertSame('my_sender', $stamp->getSenderAlias());
47-
$this->assertStringMatchesFormat('Mock_SenderInterface_%s', $stamp->getSenderClass());
47+
$this->assertStringMatchesFormat($sender::class, $stamp->getSenderClass());
4848
}
4949

5050
public function testItSendsTheMessageToMultipleSenders()

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testSetValueFailsIfNoAdderNorRemoverFound()
165165
->willReturn($axesBefore);
166166

167167
$this->expectException(NoSuchPropertyException::class);
168-
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTestCase_CarNoAdderAndRemover_[^"]*"./');
168+
$this->expectExceptionMessageMatches(\sprintf('/Could not determine access type for property "axes" in class "%s"./', $car::class));
169169

170170
$this->propertyAccessor->setValue($car, 'axes', $axesAfter);
171171
}

src/Symfony/Component/Security/Http/Tests/Authentication/AuthenticatorManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public function log($level, $message, array $context = []): void
368368
$manager = $this->createManager([$authenticator], 'main', true, [], $logger);
369369
$response = $manager->authenticateRequest($this->request);
370370
$this->assertSame($this->response, $response);
371-
$this->assertStringContainsString('Mock_TestInteractiveAuthenticator', $logger->logContexts[0]['authenticator']);
371+
$this->assertStringContainsString($authenticator::class, $logger->logContexts[0]['authenticator']);
372372
}
373373

374374
private function createAuthenticator(?bool $supports = true)

src/Symfony/Component/Security/Http/Tests/Controller/UserValueResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testResolveThrowsAccessDeniedWithWrongUserClass()
120120
$metadata = new ArgumentMetadata('foo', InMemoryUser::class, false, false, null, false, [new CurrentUser()]);
121121

122122
$this->expectException(AccessDeniedException::class);
123-
$this->expectExceptionMessageMatches('/^The logged-in user is an instance of "Mock_UserInterface[^"]+" but a user of type "Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\InMemoryUser" is expected.$/');
123+
$this->expectExceptionMessageMatches(\sprintf('/^The logged-in user is an instance of "%s" but a user of type "Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\InMemoryUser" is expected.$/', $user::class));
124124
$resolver->resolve(Request::create('/'), $metadata);
125125
}
126126

src/Symfony/Component/VarDumper/Tests/Caster/DoctrineCasterTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function testCastPersistentCollection()
2929
{
3030
$classMetadata = new ClassMetadata(__CLASS__);
3131

32-
$collection = new PersistentCollection($this->createMock(EntityManagerInterface::class), $classMetadata, new ArrayCollection(['test']));
32+
$entityManager = $this->createMock(EntityManagerInterface::class);
33+
$entityManagerClass = $entityManager::class;
34+
$collection = new PersistentCollection($entityManager, $classMetadata, new ArrayCollection(['test']));
3335

3436
if (property_exists(PersistentCollection::class, 'isDirty')) {
3537
// Collections >= 2
@@ -38,7 +40,7 @@ public function testCastPersistentCollection()
3840
%A
3941
-backRefFieldName: null
4042
-isDirty: false
41-
-em: Mock_EntityManagerInterface_%s { …3}
43+
-em: $entityManagerClass { …3}
4244
-typeClass: Doctrine\ORM\Mapping\ClassMetadata { …}
4345
%A
4446
EODUMP;
@@ -47,7 +49,7 @@ public function testCastPersistentCollection()
4749
$expected = <<<EODUMP
4850
Doctrine\ORM\PersistentCollection {
4951
%A
50-
-em: Mock_EntityManagerInterface_%s { …3}
52+
-em: $entityManagerClass { …3}
5153
-backRefFieldName: null
5254
-typeClass: Doctrine\ORM\Mapping\ClassMetadata { …}
5355
%A

0 commit comments

Comments
 (0)