Skip to content

Commit aa54daa

Browse files
authored
feature #303 [trait] remove annotation support for ResetPasswordRequest objects
1 parent b9b02ba commit aa54daa

8 files changed

+52
-71
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ find a change that break's semver, please create an issue.*
99

1010
### Feature
1111

12+
- [#303](https://github.com/symfonycasts/reset-password-bundle/pull/303) - [trait] remove annotation support for ResetPasswordRequest objects - *@jrushlow*
1213
- [#302](https://github.com/symfonycasts/reset-password-bundle/pull/302) - [trait] remove deprecated methods in `ReserPasswordControllerTrait` - *@jrushlow*
1314
- [#300](https://github.com/symfonycasts/reset-password-bundle/pull/300) - [interface] change `generateResetToken()` signature - *@jrushlow*
1415
- [#298](https://github.com/symfonycasts/reset-password-bundle/pull/298) - replace final annotation with final class keyword - *@jrushlow*

UPGRADING.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,38 @@ replaced with the `final` class keyword. Extending this class is not allowed.
2222
- Class became `@final` in `v1.22.0` and in `v2.0.0` the `@final` annotation was
2323
replaced with the `final` class keyword. Extending this class is not allowed.
2424

25-
- Command is now registered using the Symfony `#[AsCommand]` attribute
25+
- Command is now registered using the Symfony `#[AsCommand]` attribute.
2626

2727
## ResetPasswordControllerTrait
2828

2929
- Removed deprecated `setCanCheckEmailInSession()` method from trait.
3030

3131
- Removed deprecated `canCheckEmail()` method from trait.
32+
33+
## ResetPasswordRequestTrait
34+
35+
- Annotation support for ResetPasswordRequest Doctrine entities that use the
36+
trait has been dropped - attribute mapping is required.
37+
38+
- Property types were added to `selector`, `hashedToken`, `requestedAt`, & `expiresAt`.
39+
40+
```diff
41+
- protected $selector;
42+
+ protected string $selector;
43+
44+
- protected $hashedToken;
45+
+ protected string $hashedToken;
46+
47+
- protected $requestedAt;
48+
+ protected \DateTimeImmutable $requestedAt;
49+
50+
- protected $expiresAt;
51+
+ protected \DateTimeInterface $expiresAt;
52+
```
53+
54+
- `initalize()` now returns `void`. Previously the return type was not declared
55+
56+
```diff
57+
- protected function initialize(....)
58+
+ protected function initialize(....): void
59+
```

composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"symfony/framework-bundle": "^6.4.5 | ^7.0",
1818
"symfony/phpunit-bridge": "^6.4.5 | ^7.0",
1919
"doctrine/doctrine-bundle": "^2.8",
20-
"doctrine/annotations": "^1.0",
2120
"phpstan/phpstan": "^1.11.x-dev"
2221
},
2322
"autoload": {

src/Model/ResetPasswordRequestTrait.php

+5-26
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,19 @@
1818
*/
1919
trait ResetPasswordRequestTrait
2020
{
21-
/**
22-
* @var string
23-
*
24-
* @ORM\Column(type="string", length=20)
25-
*/
2621
#[ORM\Column(type: Types::STRING, length: 20)]
27-
protected $selector;
22+
protected string $selector;
2823

29-
/**
30-
* @var string
31-
*
32-
* @ORM\Column(type="string", length=100)
33-
*/
3424
#[ORM\Column(type: Types::STRING, length: 100)]
35-
protected $hashedToken;
25+
protected string $hashedToken;
3626

37-
/**
38-
* @var \DateTimeImmutable
39-
*
40-
* @ORM\Column(type="datetime_immutable")
41-
*/
4227
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
43-
protected $requestedAt;
28+
protected \DateTimeImmutable $requestedAt;
4429

45-
/**
46-
* @var \DateTimeInterface
47-
*
48-
* @ORM\Column(type="datetime_immutable")
49-
*/
5030
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
51-
protected $expiresAt;
31+
protected \DateTimeInterface $expiresAt;
5232

53-
/** @return void */
54-
protected function initialize(\DateTimeInterface $expiresAt, string $selector, string $hashedToken)
33+
protected function initialize(\DateTimeInterface $expiresAt, string $selector, string $hashedToken): void
5534
{
5635
$this->requestedAt = new \DateTimeImmutable('now');
5736
$this->expiresAt = $expiresAt;

tests/Fixtures/Entity/ResetPasswordTestFixtureRequest.php

-21
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,24 @@
1717
* @author Ryan Weaver <[email protected]>
1818
*
1919
* @internal
20-
*
21-
* @ORM\Entity(repositoryClass="SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\ResetPasswordTestFixtureRequestRepository")
2220
*/
2321
#[ORM\Entity(repositoryClass: "SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\ResetPasswordTestFixtureRequestRepository")]
2422
final class ResetPasswordTestFixtureRequest implements ResetPasswordRequestInterface
2523
{
26-
/**
27-
* @ORM\Id()
28-
*
29-
* @ORM\GeneratedValue()
30-
*
31-
* @ORM\Column(type="integer")
32-
*/
3324
#[ORM\Id]
3425
#[ORM\GeneratedValue]
3526
#[ORM\Column(type: 'integer')]
3627
public $id;
3728

38-
/**
39-
* @ORM\Column(type="string", nullable=true)
40-
*/
4129
#[ORM\Column(type: 'string', nullable: true)]
4230
public $selector;
4331

44-
/**
45-
* @ORM\Column(type="datetime_immutable", nullable=true)
46-
*/
4732
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
4833
public $expiresAt;
4934

50-
/**
51-
* @ORM\Column(type="datetime_immutable", nullable=true)
52-
*/
5335
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
5436
public $requestedAt;
5537

56-
/**
57-
* @ORM\ManyToOne(targetEntity="ResetPasswordTestFixtureUser")
58-
*/
5938
#[ORM\ManyToOne(targetEntity: 'ResetPasswordTestFixtureUser')]
6039
public $user;
6140

tests/Fixtures/Entity/ResetPasswordTestFixtureUser.php

-9
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@
1616
* @author Ryan Weaver <[email protected]>
1717
*
1818
* @internal
19-
*
20-
* @ORM\Entity()
2119
*/
2220
#[ORM\Entity]
2321
final class ResetPasswordTestFixtureUser
2422
{
25-
/**
26-
* @ORM\Id()
27-
*
28-
* @ORM\GeneratedValue()
29-
*
30-
* @ORM\Column(type="integer")
31-
*/
3223
#[ORM\Id]
3324
#[ORM\GeneratedValue]
3425
#[ORM\Column(type: 'integer')]

tests/ResetPasswordTestKernel.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
9191
'mappings' => [
9292
'App' => [
9393
'is_bundle' => false,
94-
'type' => self::shouldUseAttributes() ? 'attribute' : 'annotation',
94+
'type' => 'attribute',
9595
'dir' => 'tests/Fixtures/Entity/',
9696
'prefix' => 'SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity',
9797
'alias' => 'App',
@@ -141,9 +141,4 @@ public function getLogDir(): string
141141
{
142142
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
143143
}
144-
145-
public static function shouldUseAttributes(): bool
146-
{
147-
return Kernel::VERSION_ID >= 70000;
148-
}
149144
}

tests/Unit/Model/ResetPasswordRequestTraitTest.php

+16-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace SymfonyCasts\Bundle\ResetPassword\Tests\Unit\Model;
1111

12+
use Doctrine\DBAL\Types\Types;
13+
use Doctrine\ORM\Mapping\Column;
1214
use PHPUnit\Framework\TestCase;
1315
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
1416
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
@@ -26,21 +28,28 @@ public function testIsCompatibleWithInterface(): void
2628

2729
public function propertyDataProvider(): \Generator
2830
{
29-
yield ['selector', '@ORM\Column(type="string", length=20)'];
30-
yield ['hashedToken', '@ORM\Column(type="string", length=100)'];
31-
yield ['requestedAt', '@ORM\Column(type="datetime_immutable")'];
32-
yield ['expiresAt', '@ORM\Column(type="datetime_immutable")'];
31+
yield ['selector', ['type' => Types::STRING, 'length' => 20]];
32+
yield ['hashedToken', ['type' => Types::STRING, 'length' => 100]];
33+
yield ['requestedAt', ['type' => Types::DATETIME_IMMUTABLE]];
34+
yield ['expiresAt', ['type' => Types::DATETIME_IMMUTABLE]];
3335
}
3436

3537
/**
3638
* @dataProvider propertyDataProvider
3739
*/
38-
public function testORMAnnotationSetOnProperty(string $propertyName, string $expectedAnnotation): void
40+
public function testORMAnnotationSetOnProperty(string $propertyName, array $expectedAttributeProperties): void
3941
{
4042
$property = new \ReflectionProperty(ResetPasswordRequestTrait::class, $propertyName);
41-
$result = $property->getDocComment();
43+
$attributes = $property->getAttributes(Column::class);
4244

43-
self::assertStringContainsString($expectedAnnotation, $result, sprintf('%s::%s does not contain "%s" in the docBlock.', ResetPasswordRequestTrait::class, $propertyName, $expectedAnnotation));
45+
self::assertCount(1, $attributes);
46+
47+
foreach ($expectedAttributeProperties as $argumentName => $expectedValue) {
48+
$attributeArguments = $attributes[0]->getArguments();
49+
50+
self::assertArrayHasKey($argumentName, $attributeArguments);
51+
self::assertSame($expectedValue, $attributeArguments[$argumentName]);
52+
}
4453
}
4554

4655
public function isExpiredDataProvider(): \Generator

0 commit comments

Comments
 (0)