Skip to content

Commit 4ca9b7d

Browse files
authored
Merge pull request #1061 from jrushlow/ci/handle-attributes-in-tests
[ci] handle attributes in reset password tests
2 parents 085358c + dce5386 commit 4ca9b7d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/Maker/MakeResetPasswordTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Tests\Maker;
1313

14+
use Doctrine\ORM\Mapping\Driver\AttributeReader;
1415
use Symfony\Bundle\MakerBundle\Maker\MakeResetPassword;
1516
use Symfony\Bundle\MakerBundle\Test\MakerTestCase;
1617
use Symfony\Bundle\MakerBundle\Test\MakerTestDetails;
@@ -159,9 +160,17 @@ public function getTestDetails()
159160
$this->assertStringContainsString('\'emailAddress\' => $emailFormData,', $contentResetPasswordController);
160161
$this->assertStringContainsString('$user->setMyPassword($encodedPassword);', $contentResetPasswordController);
161162
$this->assertStringContainsString('->to($user->getEmailAddress())', $contentResetPasswordController);
163+
162164
// check ResetPasswordRequest
163165
$contentResetPasswordRequest = file_get_contents($runner->getPath('src/Entity/ResetPasswordRequest.php'));
164-
$this->assertStringContainsString('ORM\ManyToOne(targetEntity=UserCustom::class)', $contentResetPasswordRequest);
166+
167+
/* @legacy Drop annotation test when annotations are no longer supported. */
168+
if ($this->useAttributes($runner)) {
169+
$this->assertStringContainsString('ORM\ManyToOne(targetEntity: UserCustom::class)', $contentResetPasswordRequest);
170+
} else {
171+
$this->assertStringContainsString('ORM\ManyToOne(targetEntity=UserCustom::class)', $contentResetPasswordRequest);
172+
}
173+
165174
// check ResetPasswordRequestFormType
166175
$contentResetPasswordRequestFormType = file_get_contents($runner->getPath('/src/Form/ResetPasswordRequestFormType.php'));
167176
$this->assertStringContainsString('->add(\'emailAddress\', EmailType::class, [', $contentResetPasswordRequestFormType);
@@ -198,4 +207,11 @@ private function makeUser(MakerTestRunner $runner, string $identifier = 'email',
198207
$checkPassword ? 'y' : 'n', // password
199208
]);
200209
}
210+
211+
private function useAttributes(MakerTestRunner $runner): bool
212+
{
213+
return \PHP_VERSION_ID >= 80000
214+
&& $runner->doesClassExist(AttributeReader::class)
215+
&& $runner->getSymfonyVersion() >= 50200;
216+
}
201217
}

0 commit comments

Comments
 (0)