Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ find a change that break's semver, please create an issue.*

### Feature

- [#303](https://github.com/symfonycasts/reset-password-bundle/pull/303) - [trait] remove annotation support for ResetPasswordRequest objects - *@jrushlow*
- [#302](https://github.com/symfonycasts/reset-password-bundle/pull/302) - [trait] remove deprecated methods in `ReserPasswordControllerTrait` - *@jrushlow*
- [#300](https://github.com/symfonycasts/reset-password-bundle/pull/300) - [interface] change `generateResetToken()` signature - *@jrushlow*
- [#298](https://github.com/symfonycasts/reset-password-bundle/pull/298) - replace final annotation with final class keyword - *@jrushlow*
Expand Down
30 changes: 29 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,38 @@ replaced with the `final` class keyword. Extending this class is not allowed.
- Class became `@final` in `v1.22.0` and in `v2.0.0` the `@final` annotation was
replaced with the `final` class keyword. Extending this class is not allowed.

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

## ResetPasswordControllerTrait

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

- Removed deprecated `canCheckEmail()` method from trait.

## ResetPasswordRequestTrait

- Annotation support for ResetPasswordRequest Doctrine entities that use the
trait has been dropped - attribute mapping is required.

- Property types were added to `selector`, `hashedToken`, `requestedAt`, & `expiresAt`.

```diff
- protected $selector;
+ protected string $selector;

- protected $hashedToken;
+ protected string $hashedToken;

- protected $requestedAt;
+ protected \DateTimeImmutable $requestedAt;

- protected $expiresAt;
+ protected \DateTimeInterface $expiresAt;
```

- `initalize()` now returns `void`. Previously the return type was not declared

```diff
- protected function initialize(....)
+ protected function initialize(....): void
```
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"symfony/framework-bundle": "^6.4.5 | ^7.0",
"symfony/phpunit-bridge": "^6.4.5 | ^7.0",
"doctrine/doctrine-bundle": "^2.8",
"doctrine/annotations": "^1.0",
"phpstan/phpstan": "^1.11.x-dev"
},
"autoload": {
Expand Down
31 changes: 5 additions & 26 deletions src/Model/ResetPasswordRequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,19 @@
*/
trait ResetPasswordRequestTrait
{
/**
* @var string
*
* @ORM\Column(type="string", length=20)
*/
#[ORM\Column(type: Types::STRING, length: 20)]
protected $selector;
protected string $selector;

/**
* @var string
*
* @ORM\Column(type="string", length=100)
*/
#[ORM\Column(type: Types::STRING, length: 100)]
protected $hashedToken;
protected string $hashedToken;

/**
* @var \DateTimeImmutable
*
* @ORM\Column(type="datetime_immutable")
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $requestedAt;
protected \DateTimeImmutable $requestedAt;

/**
* @var \DateTimeInterface
*
* @ORM\Column(type="datetime_immutable")
*/
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
protected $expiresAt;
protected \DateTimeInterface $expiresAt;

/** @return void */
protected function initialize(\DateTimeInterface $expiresAt, string $selector, string $hashedToken)
protected function initialize(\DateTimeInterface $expiresAt, string $selector, string $hashedToken): void
{
$this->requestedAt = new \DateTimeImmutable('now');
$this->expiresAt = $expiresAt;
Expand Down
21 changes: 0 additions & 21 deletions tests/Fixtures/Entity/ResetPasswordTestFixtureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,24 @@
* @author Ryan Weaver <[email protected]>
*
* @internal
*
* @ORM\Entity(repositoryClass="SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\ResetPasswordTestFixtureRequestRepository")
*/
#[ORM\Entity(repositoryClass: "SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\ResetPasswordTestFixtureRequestRepository")]
final class ResetPasswordTestFixtureRequest implements ResetPasswordRequestInterface
{
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
public $id;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
public $selector;

/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
public $expiresAt;

/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
public $requestedAt;

/**
* @ORM\ManyToOne(targetEntity="ResetPasswordTestFixtureUser")
*/
#[ORM\ManyToOne(targetEntity: 'ResetPasswordTestFixtureUser')]
public $user;

Expand Down
9 changes: 0 additions & 9 deletions tests/Fixtures/Entity/ResetPasswordTestFixtureUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@
* @author Ryan Weaver <[email protected]>
*
* @internal
*
* @ORM\Entity()
*/
#[ORM\Entity]
final class ResetPasswordTestFixtureUser
{
/**
* @ORM\Id()
*
* @ORM\GeneratedValue()
*
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
Expand Down
7 changes: 1 addition & 6 deletions tests/ResetPasswordTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
'mappings' => [
'App' => [
'is_bundle' => false,
'type' => self::shouldUseAttributes() ? 'attribute' : 'annotation',
'type' => 'attribute',
'dir' => 'tests/Fixtures/Entity/',
'prefix' => 'SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity',
'alias' => 'App',
Expand Down Expand Up @@ -141,9 +141,4 @@ public function getLogDir(): string
{
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
}

public static function shouldUseAttributes(): bool
{
return Kernel::VERSION_ID >= 70000;
}
}
23 changes: 16 additions & 7 deletions tests/Unit/Model/ResetPasswordRequestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

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

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

public function propertyDataProvider(): \Generator
{
yield ['selector', '@ORM\Column(type="string", length=20)'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these unit tests almost seem silly if we have a full stack test in the bundle.. if we dont - we should create one and remove these tests..

yield ['hashedToken', '@ORM\Column(type="string", length=100)'];
yield ['requestedAt', '@ORM\Column(type="datetime_immutable")'];
yield ['expiresAt', '@ORM\Column(type="datetime_immutable")'];
yield ['selector', ['type' => Types::STRING, 'length' => 20]];
yield ['hashedToken', ['type' => Types::STRING, 'length' => 100]];
yield ['requestedAt', ['type' => Types::DATETIME_IMMUTABLE]];
yield ['expiresAt', ['type' => Types::DATETIME_IMMUTABLE]];
}

/**
* @dataProvider propertyDataProvider
*/
public function testORMAnnotationSetOnProperty(string $propertyName, string $expectedAnnotation): void
public function testORMAnnotationSetOnProperty(string $propertyName, array $expectedAttributeProperties): void
{
$property = new \ReflectionProperty(ResetPasswordRequestTrait::class, $propertyName);
$result = $property->getDocComment();
$attributes = $property->getAttributes(Column::class);

self::assertStringContainsString($expectedAnnotation, $result, sprintf('%s::%s does not contain "%s" in the docBlock.', ResetPasswordRequestTrait::class, $propertyName, $expectedAnnotation));
self::assertCount(1, $attributes);

foreach ($expectedAttributeProperties as $argumentName => $expectedValue) {
$attributeArguments = $attributes[0]->getArguments();

self::assertArrayHasKey($argumentName, $attributeArguments);
self::assertSame($expectedValue, $attributeArguments[$argumentName]);
}
}

public function isExpiredDataProvider(): \Generator
Expand Down