Skip to content

Commit 9b1d69a

Browse files
authored
Merge pull request #64 from jrushlow/functional-test
add tests for request repository trait
2 parents 771d672 + 2db9e00 commit 9b1d69a

8 files changed

+340
-46
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"friendsofphp/php-cs-fixer": "^2.16",
1414
"symfony/framework-bundle": "^5.0",
1515
"symfony/phpunit-bridge": "^5.0",
16-
"vimeo/psalm": "^3.8"
16+
"vimeo/psalm": "^3.8",
17+
"doctrine/doctrine-bundle": "^2.0"
1718
},
1819
"conflict": {
1920
"doctrine/orm": "<2.7",

tests/Fixtures/AbstractResetPasswordTestKernel.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures;
1111

12+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1213
use Psr\Log\LogLevel;
1314
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1415
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
@@ -39,6 +40,7 @@ public function registerBundles()
3940
return [
4041
new FrameworkBundle(),
4142
new SymfonyCastsResetPasswordBundle(),
43+
new DoctrineBundle(),
4244
];
4345
}
4446

@@ -64,11 +66,34 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
6466
'utf8' => true,
6567
],
6668
]);
69+
$container->loadFromExtension('doctrine', [
70+
'dbal' => [
71+
'driver' => 'pdo_sqlite',
72+
'url' => 'sqlite:///fake',
73+
],
74+
'orm' => [
75+
'auto_generate_proxy_classes' => true,
76+
'naming_strategy' => 'doctrine.orm.naming_strategy.underscore_number_aware',
77+
'auto_mapping' => true,
78+
'mappings' => [
79+
'App' => [
80+
'is_bundle' => false,
81+
'type' => 'annotation',
82+
'dir' => '%kernel.project_dir%/tests/Fixtures/Entity/',
83+
'prefix' => 'SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity',
84+
'alias' => 'App',
85+
],
86+
],
87+
],
88+
]);
6789

68-
$container->register(ResetPasswordRepositoryTestFixture::class);
90+
$container->register(ResetPasswordTestFixtureRequestRepository::class)
91+
->setAutoconfigured(true)
92+
->setAutowired(true)
93+
;
6994

7095
$container->loadFromExtension('symfonycasts_reset_password', [
71-
'request_password_repository' => ResetPasswordRepositoryTestFixture::class,
96+
'request_password_repository' => ResetPasswordTestFixtureRequestRepository::class,
7297
]);
7398

7499
// avoid logging request logs
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the SymfonyCasts ResetPasswordBundle package.
5+
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity;
11+
12+
use Doctrine\ORM\Mapping as ORM;
13+
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
14+
15+
/**
16+
* @author Jesse Rushlow <[email protected]>
17+
* @author Ryan Weaver <[email protected]>
18+
*
19+
* @internal
20+
* @ORM\Entity(repositoryClass="SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\ResetPasswordTestFixtureRequestRepository")
21+
*/
22+
final class ResetPasswordTestFixtureRequest implements ResetPasswordRequestInterface
23+
{
24+
/**
25+
* @ORM\Id()
26+
* @ORM\GeneratedValue()
27+
* @ORM\Column(type="integer")
28+
*/
29+
private $id;
30+
31+
/**
32+
* @ORM\Column(type="string", nullable=true)
33+
*/
34+
public $selector;
35+
36+
/**
37+
* @ORM\Column(type="datetime_immutable", nullable=true)
38+
*/
39+
public $expiresAt;
40+
41+
/**
42+
* @ORM\Column(type="datetime_immutable", nullable=true)
43+
*/
44+
public $requestedAt;
45+
46+
/**
47+
* @ORM\ManyToOne(targetEntity="ResetPasswordTestFixtureUser")
48+
*/
49+
public $user;
50+
51+
public function getRequestedAt(): \DateTimeInterface
52+
{
53+
return $this->requestedAt;
54+
}
55+
56+
public function isExpired(): bool
57+
{
58+
return $this->expiresAt->getTimestamp() <= \time();
59+
}
60+
61+
public function getExpiresAt(): \DateTimeInterface
62+
{
63+
}
64+
65+
public function getHashedToken(): string
66+
{
67+
}
68+
69+
public function getUser(): object
70+
{
71+
}
72+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the SymfonyCasts ResetPasswordBundle package.
5+
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity;
11+
12+
use Doctrine\ORM\Mapping as ORM;
13+
14+
/**
15+
* @author Jesse Rushlow <[email protected]>
16+
* @author Ryan Weaver <[email protected]>
17+
*
18+
* @internal
19+
* @ORM\Entity()
20+
*/
21+
final class ResetPasswordTestFixtureUser
22+
{
23+
/**
24+
* @ORM\Id()
25+
* @ORM\GeneratedValue()
26+
* @ORM\Column(type="integer")
27+
*/
28+
private $id;
29+
}

tests/Fixtures/ResetPasswordRequestTestFixture.php

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/Fixtures/ResetPasswordRepositoryTestFixture.php renamed to tests/Fixtures/ResetPasswordTestFixtureRequestRepository.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@
99

1010
namespace SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures;
1111

12+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
13+
use Doctrine\Common\Persistence\ManagerRegistry;
1214
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
1315
use SymfonyCasts\Bundle\ResetPassword\Persistence\Repository\ResetPasswordRequestRepositoryTrait;
1416
use SymfonyCasts\Bundle\ResetPassword\Persistence\ResetPasswordRequestRepositoryInterface;
17+
use SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\Entity\ResetPasswordTestFixtureRequest;
1518

1619
/**
1720
* @author Jesse Rushlow <[email protected]>
1821
* @author Ryan Weaver <[email protected]>
1922
*
2023
* @internal
2124
*/
22-
class ResetPasswordRepositoryTestFixture implements ResetPasswordRequestRepositoryInterface
25+
final class ResetPasswordTestFixtureRequestRepository extends ServiceEntityRepository implements ResetPasswordRequestRepositoryInterface
2326
{
2427
use ResetPasswordRequestRepositoryTrait;
2528

29+
private $manager;
30+
31+
public function __construct(ManagerRegistry $registry)
32+
{
33+
parent::__construct($registry, ResetPasswordTestFixtureRequest::class);
34+
}
35+
2636
public function createResetPasswordRequest(
2737
object $user,
2838
\DateTimeInterface $expiresAt,

0 commit comments

Comments
 (0)