Skip to content

Commit dab04b8

Browse files
authored
Merge pull request #638 from TomHAnderson/hotfix/tests-feature-phpcs
Hotfix/tests feature phpcs
2 parents a62a443 + 57f6ed6 commit dab04b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+935
-1071
lines changed

phpcs.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<!-- Directories to be checked -->
1313
<file>src</file>
14+
<file>tests</file>
1415

1516
<!-- Include full Doctrine Coding Standard -->
1617
<rule ref="Doctrine"/>
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LaravelDoctrineTest\ORM\Assets;
6+
7+
class InvalidDoctrineExtender
8+
{
9+
}

tests/Assets/MyDoctrineExtender.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LaravelDoctrineTest\ORM\Assets;
6+
7+
use Doctrine\Common\EventManager;
8+
use Doctrine\DBAL\Connection;
9+
use Doctrine\ORM\Configuration;
10+
use LaravelDoctrine\ORM\DoctrineExtender;
11+
use LaravelDoctrineTest\ORM\Feature\DoctrineManagerTest;
12+
13+
class MyDoctrineExtender implements DoctrineExtender
14+
{
15+
public function extend(Configuration $configuration, Connection $connection, EventManager $eventManager): void
16+
{
17+
(new DoctrineManagerTest())->assertExtendedCorrectly($configuration, $connection, $eventManager);
18+
}
19+
}

tests/Assets/Testing/EntityStub.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LaravelDoctrineTest\ORM\Assets\Testing;
6+
7+
use Doctrine\ORM\Mapping\Column;
8+
use Doctrine\ORM\Mapping\Entity;
9+
use Doctrine\ORM\Mapping\GeneratedValue;
10+
use Doctrine\ORM\Mapping\Id;
11+
use Doctrine\ORM\Mapping\InverseJoinColumn;
12+
use Doctrine\ORM\Mapping\JoinColumn;
13+
use Doctrine\ORM\Mapping\JoinTable;
14+
use Doctrine\ORM\Mapping\ManyToMany;
15+
16+
#[Entity]
17+
class EntityStub
18+
{
19+
#[Id]
20+
#[GeneratedValue]
21+
#[Column(type: 'integer')]
22+
public mixed $id;
23+
24+
#[Column(type: 'string')]
25+
public mixed $name;
26+
27+
#[ManyToMany(targetEntity: 'EntityStub')]
28+
#[JoinTable(name: 'stub_stubs')]
29+
#[JoinColumn(name: 'owner_id', referencedColumnName: 'id')]
30+
#[InverseJoinColumn(name: 'owned_id', referencedColumnName: 'id')]
31+
public mixed $others;
32+
}

tests/Feature/Auth/DoctrineUserProviderTest.php

+36-52
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace LaravelDoctrineTest\ORM\Feature\Auth;
46

57
use Doctrine\ORM\EntityManagerInterface;
@@ -10,100 +12,84 @@
1012
use LaravelDoctrineTest\ORM\Assets\Auth\AuthenticableWithNonEmptyConstructorMock;
1113
use LaravelDoctrineTest\ORM\TestCase;
1214
use Mockery as m;
13-
use Mockery\Mock;
1415

1516
class DoctrineUserProviderTest extends TestCase
1617
{
17-
/**
18-
* @var Mock
19-
*/
20-
protected $hasher;
21-
22-
/**
23-
* @var Mock
24-
*/
25-
protected $em;
26-
27-
/**
28-
* @var DoctrineUserProvider
29-
*/
30-
protected $provider;
31-
32-
/**
33-
* @var DoctrineUserProvider
34-
*/
35-
protected $providerNonEmpty;
36-
37-
/**
38-
* @var Mock
39-
*/
40-
protected $repo;
18+
protected Hasher $hasher;
19+
20+
protected EntityManagerInterface $em;
21+
22+
protected DoctrineUserProvider $provider;
23+
24+
protected DoctrineUserProvider $providerNonEmpty;
25+
26+
protected EntityRepository $repo;
4127

4228
protected function setUp(): void
4329
{
4430
$this->hasher = m::mock(Hasher::class);
4531
$this->em = m::mock(EntityManagerInterface::class);
4632
$this->repo = m::mock(EntityRepository::class);
4733

48-
$this->provider = new DoctrineUserProvider(
34+
$this->provider = new DoctrineUserProvider(
4935
$this->hasher,
5036
$this->em,
51-
AuthenticableMock::class
37+
AuthenticableMock::class,
5238
);
5339
$this->providerNonEmpty = new DoctrineUserProvider(
5440
$this->hasher,
5541
$this->em,
56-
AuthenticableWithNonEmptyConstructorMock::class
42+
AuthenticableWithNonEmptyConstructorMock::class,
5743
);
5844

5945
parent::setUp();
6046
}
6147

62-
public function test_can_retrieve_by_id()
48+
public function testCanRetrieveById(): void
6349
{
6450
$this->mockGetRepository();
6551

66-
$user = new AuthenticableMock;
52+
$user = new AuthenticableMock();
6753
$this->repo->shouldReceive('find')
6854
->once()->with(1)
6955
->andReturn($user);
7056

7157
$this->assertEquals($user, $this->provider->retrieveById(1));
7258
}
7359

74-
public function test_can_retrieve_by_token()
60+
public function testCanRetrieveByToken(): void
7561
{
7662
$this->mockGetRepository();
7763

78-
$user = new AuthenticableMock;
64+
$user = new AuthenticableMock();
7965
$this->repo->shouldReceive('findOneBy')
8066
->with([
8167
'id' => 1,
82-
'rememberToken' => 'myToken'
68+
'rememberToken' => 'myToken',
8369
])
8470
->once()->andReturn($user);
8571

8672
$this->assertEquals($user, $this->provider->retrieveByToken(1, 'myToken'));
8773
}
8874

89-
public function test_can_retrieve_by_token_with_non_empty_constructor()
75+
public function testCanRetrieveByTokenWithNonEmptyConstructor(): void
9076
{
9177
$this->mockGetRepository(AuthenticableWithNonEmptyConstructorMock::class);
9278

9379
$user = new AuthenticableWithNonEmptyConstructorMock(['myPassword']);
9480
$this->repo->shouldReceive('findOneBy')
9581
->with([
9682
'id' => 1,
97-
'rememberToken' => 'myToken'
83+
'rememberToken' => 'myToken',
9884
])
9985
->once()->andReturn($user);
10086

10187
$this->assertEquals($user, $this->providerNonEmpty->retrieveByToken(1, 'myToken'));
10288
}
10389

104-
public function test_can_update_remember_token()
90+
public function testCanUpdateRememberToken(): void
10591
{
106-
$user = new AuthenticableMock;
92+
$user = new AuthenticableMock();
10793

10894
$this->em->shouldReceive('persist')->once()->with($user);
10995
$this->em->shouldReceive('flush')->once()->withNoArgs();
@@ -113,40 +99,38 @@ public function test_can_update_remember_token()
11399
$this->assertEquals('newToken', $user->getRememberToken());
114100
}
115101

116-
public function test_can_retrieve_by_credentials()
102+
public function testCanRetrieveByCredentials(): void
117103
{
118104
$this->mockGetRepository();
119105

120-
$user = new AuthenticableMock;
106+
$user = new AuthenticableMock();
121107
$this->repo->shouldReceive('findOneBy')
122-
->with([
123-
'email' => 'email',
124-
])
108+
->with(['email' => 'email'])
125109
->once()->andReturn($user);
126110

127111
$this->assertEquals($user, $this->provider->retrieveByCredentials([
128112
'email' => 'email',
129-
'password' => 'password'
113+
'password' => 'password',
130114
]));
131115
}
132116

133-
public function test_can_validate_credentials()
117+
public function testCanValidateCredentials(): void
134118
{
135-
$user = new AuthenticableMock;
119+
$user = new AuthenticableMock();
136120

137121
$this->hasher->shouldReceive('check')->once()
138122
->with('myPassword', 'myPassword')
139123
->andReturn(true);
140124

141125
$this->assertTrue($this->provider->validateCredentials(
142126
$user,
143-
['password' => 'myPassword']
127+
['password' => 'myPassword'],
144128
));
145129
}
146130

147-
public function test_rehash_password_if_required_rehash()
131+
public function testRehashPasswordIfRequriredRehash(): void
148132
{
149-
$user = new AuthenticableMock;
133+
$user = new AuthenticableMock();
150134

151135
$this->hasher->shouldReceive('needsRehash')->once()->andReturn(true);
152136
$this->hasher->shouldReceive('make')->once()->andReturn('hashedPassword');
@@ -157,9 +141,9 @@ public function test_rehash_password_if_required_rehash()
157141
$this->assertEquals('hashedPassword', $user->getPassword());
158142
}
159143

160-
public function test_rehash_password_if_required_rehash_force()
144+
public function testRehashPasswordIfRequiredRehashForce(): void
161145
{
162-
$user = new AuthenticableMock;
146+
$user = new AuthenticableMock();
163147

164148
$this->hasher->shouldReceive('needsRehash')->once()->andReturn(false);
165149
$this->hasher->shouldReceive('make')->once()->andReturn('hashedPassword');
@@ -170,7 +154,7 @@ public function test_rehash_password_if_required_rehash_force()
170154
$this->assertEquals('hashedPassword', $user->getPassword());
171155
}
172156

173-
public function test_rehash_password_if_required_rehash_norehash_needed()
157+
public function testRehashPasswordIfRequiredRehashNorehashNeeded(): void
174158
{
175159
$user = new AuthenticableMock();
176160
$user->setPassword('originalPassword');
@@ -181,7 +165,7 @@ public function test_rehash_password_if_required_rehash_norehash_needed()
181165
$this->assertEquals('originalPassword', $user->getPassword());
182166
}
183167

184-
protected function mockGetRepository($class = AuthenticableMock::class)
168+
protected function mockGetRepository(string $class = AuthenticableMock::class): void
185169
{
186170
$this->em->shouldReceive('getRepository')
187171
->with($class)

0 commit comments

Comments
 (0)