Repository navigation
Expand file tree
/
Copy pathUserRepositoryTest.php
More file actions
69 lines (58 loc) · 2.91 KB
/
Copy pathUserRepositoryTest.php
File metadata and controls
69 lines (58 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* This file is part of the Silverback API Components Bundle Project
*
* (c) Daniel West <daniel@silverback.is>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silverback\ApiComponentsBundle\Tests\Repository\User;
use PHPUnit\Framework\Attributes\DataProvider;
use Silverback\ApiComponentsBundle\Repository\User\UserRepository;
use Silverback\ApiComponentsBundle\Tests\Functional\TestBundle\Entity\User;
use Silverback\ApiComponentsBundle\Tests\Helper\OrphanedResource\OrphanedResourceDatabaseTestCase;
final class UserRepositoryTest extends OrphanedResourceDatabaseTestCase
{
/**
* @return iterable<string, array{\Closure(UserRepository): ?User}>
*/
public static function lookupsWithSurroundingSpace(): iterable
{
yield 'a username identifier' => [static fn (UserRepository $repository) => $repository->loadUserByIdentifier(" My_Username \t")];
yield 'an email address identifier' => [static fn (UserRepository $repository) => $repository->loadUserByIdentifier(' User@Example.com ')];
yield 'a username through the deprecated loader' => [static fn (UserRepository $repository) => $repository->loadUserByUsername('MY_username ')];
yield 'an email address' => [static fn (UserRepository $repository) => $repository->findOneByEmail(' User@Example.COM ')];
yield 'a username with a password reset token' => [static fn (UserRepository $repository) => $repository->findOneWithPasswordResetToken(' My_Username ')];
yield 'a username and new email address' => [static fn (UserRepository $repository) => $repository->findOneByUsernameAndNewEmailAddress(' My_Username ', ' New@Example.com ')];
}
#[DataProvider('lookupsWithSurroundingSpace')]
public function test_a_lookup_ignores_surrounding_whitespace_and_case(\Closure $lookup): void
{
$user = $this->persistUser();
self::assertSame($user, $lookup($this->repository()));
}
public function test_an_identifier_that_matches_no_one_finds_no_user(): void
{
$this->persistUser();
self::assertNull($this->repository()->loadUserByIdentifier('my user'));
}
private function persistUser(): User
{
$user = new User('my_username', 'user@example.com');
$user
->setNewPasswordConfirmationToken('token')
->setPasswordRequestedAt(new \DateTime())
->setNewEmailAddress('new@example.com')
->setNewEmailConfirmationToken('token')
->setNewEmailAddressChangeRequestedAt(new \DateTime());
$this->timestampedDataPersister->persistTimestampedFields($user, true);
$this->entityManager->persist($user);
$this->entityManager->flush();
return $user;
}
private function repository(): UserRepository
{
return new UserRepository($this->registry, User::class, 3600, 3600);
}
}