Skip to content

Commit d17ac77

Browse files
authored
Merge pull request #679 from cakephp/3.next
3.next
2 parents 6f4553e + 549744f commit d17ac77

File tree

6 files changed

+81
-58
lines changed

6 files changed

+81
-58
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"psr/http-server-middleware": "^1.0"
3232
},
3333
"require-dev": {
34-
"cakephp/cakephp": "^5.0",
34+
"cakephp/cakephp": "^5.1.0",
3535
"cakephp/cakephp-codesniffer": "^5.0",
3636
"firebase/php-jwt": "^6.2",
37-
"phpunit/phpunit": "^10.1.0"
37+
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
3838
},
3939
"suggest": {
4040
"ext-ldap": "Make sure this php extension is installed and enabled on your system if you want to use the built-in LDAP adapter for \"LdapIdentifier\".",

tests/TestCase/Authenticator/AbstractAuthenticatorTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
namespace Authentication\Test\TestCase\Authenticator;
1818

1919
use Authentication\Authenticator\AbstractAuthenticator;
20+
use Authentication\Authenticator\Result;
21+
use Authentication\Authenticator\ResultInterface;
2022
use Authentication\Identifier\IdentifierInterface;
2123
use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
2224

@@ -30,7 +32,12 @@ class AbstractAuthenticatorTest extends TestCase
3032
public function testGetIdentifier()
3133
{
3234
$identifier = $this->createMock(IdentifierInterface::class);
33-
$authenticator = $this->getMockForAbstractClass(AbstractAuthenticator::class, [$identifier]);
35+
$authenticator = new class ($identifier) extends AbstractAuthenticator {
36+
public function authenticate($request): Result
37+
{
38+
return new Result([], ResultInterface::SUCCESS);
39+
}
40+
};
3441

3542
$this->assertSame($identifier, $authenticator->getIdentifier());
3643
}
@@ -42,11 +49,17 @@ public function testGetIdentifier()
4249
*/
4350
public function testSetIdentifier()
4451
{
45-
$authenticator = $this->getMockForAbstractClass(AbstractAuthenticator::class, [], '', false);
46-
4752
$identifier = $this->createMock(IdentifierInterface::class);
48-
$authenticator->setIdentifier($identifier);
53+
$authenticator = new class ($identifier) extends AbstractAuthenticator {
54+
public function authenticate($request): Result
55+
{
56+
return new Result([], ResultInterface::SUCCESS);
57+
}
58+
};
4959

50-
$this->assertSame($identifier, $authenticator->getIdentifier());
60+
$otherIdentifier = $this->createMock(IdentifierInterface::class);
61+
$authenticator->setIdentifier($otherIdentifier);
62+
63+
$this->assertSame($otherIdentifier, $authenticator->getIdentifier());
5164
}
5265
}

tests/TestCase/Authenticator/JwtAuthenticatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function testAuthenticateInvalidPayloadEmpty()
226226

227227
$authenticator->expects($this->once())
228228
->method('getPayLoad')
229-
->will($this->returnValue(new stdClass()));
229+
->willReturn(new stdClass());
230230

231231
$result = $authenticator->authenticate($request);
232232
$this->assertInstanceOf(Result::class, $result);

tests/TestCase/Authenticator/SessionAuthenticatorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public function testAuthenticateSuccess()
8080
$this->sessionMock->expects($this->once())
8181
->method('read')
8282
->with('Auth')
83-
->will($this->returnValue([
83+
->willReturn([
8484
'username' => 'mariano',
8585
'password' => 'password',
86-
]));
86+
]);
8787

8888
$request = $request->withAttribute('session', $this->sessionMock);
8989

@@ -106,7 +106,7 @@ public function testAuthenticateFailure()
106106
$this->sessionMock->expects($this->once())
107107
->method('read')
108108
->with('Auth')
109-
->will($this->returnValue(null));
109+
->willReturn(null);
110110

111111
$request = $request->withAttribute('session', $this->sessionMock);
112112

@@ -129,10 +129,10 @@ public function testVerifyByDatabaseSuccess()
129129
$this->sessionMock->expects($this->once())
130130
->method('read')
131131
->with('Auth')
132-
->will($this->returnValue([
132+
->willReturn([
133133
'username' => 'mariano',
134134
'password' => 'h45h',
135-
]));
135+
]);
136136

137137
$request = $request->withAttribute('session', $this->sessionMock);
138138

@@ -157,10 +157,10 @@ public function testVerifyByDatabaseFailure()
157157
$this->sessionMock->expects($this->once())
158158
->method('read')
159159
->with('Auth')
160-
->will($this->returnValue([
160+
->willReturn([
161161
'username' => 'does-not',
162162
'password' => 'exist',
163-
]));
163+
]);
164164

165165
$request = $request->withAttribute('session', $this->sessionMock);
166166

tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,31 @@ class ResolverAwareTraitTest extends TestCase
2525
{
2626
public function testBuildResolverFromClassName()
2727
{
28-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
29-
->addMethods(['getConfig'])
30-
->getMockForTrait();
28+
$object = new class {
29+
use ResolverAwareTrait;
3130

32-
$object->expects($this->once())
33-
->method('getConfig')
34-
->willReturn('Test');
31+
public function getConfig()
32+
{
33+
return 'Test';
34+
}
35+
};
3536

3637
$resolver = $object->getResolver();
3738
$this->assertInstanceOf(TestResolver::class, $resolver);
3839
}
3940

4041
public function testBuildResolverFromArray()
4142
{
42-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
43-
->addMethods(['getConfig'])
44-
->getMockForTrait();
43+
$object = new class {
44+
use ResolverAwareTrait;
4545

46-
$object->expects($this->once())
47-
->method('getConfig')
48-
->willReturn([
49-
'className' => 'Test',
50-
]);
46+
public function getConfig()
47+
{
48+
return [
49+
'className' => 'Test',
50+
];
51+
}
52+
};
5153

5254
$resolver = $object->getResolver();
5355
$this->assertInstanceOf(TestResolver::class, $resolver);
@@ -57,13 +59,14 @@ public function testBuildResolverInvalid()
5759
{
5860
$this->expectException('RuntimeException');
5961
$this->expectExceptionMessage('Resolver must implement `Authentication\Identifier\Resolver\ResolverInterface`.');
60-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
61-
->addMethods(['getConfig'])
62-
->getMockForTrait();
62+
$object = new class {
63+
use ResolverAwareTrait;
6364

64-
$object->expects($this->once())
65-
->method('getConfig')
66-
->willReturn('Invalid');
65+
public function getConfig()
66+
{
67+
return 'Invalid';
68+
}
69+
};
6770

6871
$object->getResolver();
6972
}
@@ -72,13 +75,14 @@ public function testBuildResolverMissing()
7275
{
7376
$this->expectException('InvalidArgumentException');
7477
$this->expectExceptionMessage('Resolver class `Missing` does not exist.');
75-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
76-
->addMethods(['getConfig'])
77-
->getMockForTrait();
78+
$object = new class {
79+
use ResolverAwareTrait;
7880

79-
$object->expects($this->once())
80-
->method('getConfig')
81-
->willReturn('Missing');
81+
public function getConfig()
82+
{
83+
return 'Missing';
84+
}
85+
};
8286

8387
$object->getResolver();
8488
}
@@ -87,13 +91,14 @@ public function testBuildResolverMissingClassNameOption()
8791
{
8892
$this->expectException('InvalidArgumentException');
8993
$this->expectExceptionMessage('Option `className` is not present.');
90-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
91-
->addMethods(['getConfig'])
92-
->getMockForTrait();
94+
$object = new class {
95+
use ResolverAwareTrait;
9396

94-
$object->expects($this->once())
95-
->method('getConfig')
96-
->willReturn([]);
97+
public function getConfig()
98+
{
99+
return [];
100+
}
101+
};
97102

98103
$object->getResolver();
99104
}
@@ -102,22 +107,23 @@ public function testGetResolverNotSet()
102107
{
103108
$this->expectException('RuntimeException');
104109
$this->expectExceptionMessage('Resolver has not been set.');
105-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
106-
->addMethods(['getConfig'])
107-
->getMockForTrait();
110+
$object = new class {
111+
use ResolverAwareTrait;
108112

109-
$object->expects($this->once())
110-
->method('getConfig')
111-
->willReturn(null);
113+
public function getConfig()
114+
{
115+
return null;
116+
}
117+
};
112118

113119
$object->getResolver();
114120
}
115121

116122
public function testSetResolver()
117123
{
118-
$object = $this->getMockBuilder(ResolverAwareTrait::class)
119-
->addMethods(['getConfig'])
120-
->getMockForTrait();
124+
$object = new class {
125+
use ResolverAwareTrait;
126+
};
121127

122128
$resolver = $this->createMock(ResolverInterface::class);
123129

tests/TestCase/PasswordHasher/PasswordHasherTraitTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class PasswordHasherTraitTest extends TestCase
3232
*/
3333
public function testGetPasswordHasher()
3434
{
35-
$object = $this->getMockForTrait(PasswordHasherTrait::class);
35+
$object = new class {
36+
use PasswordHasherTrait;
37+
};
3638

3739
$defaultHasher = $object->getPasswordHasher();
3840
$this->assertInstanceOf(DefaultPasswordHasher::class, $defaultHasher);
@@ -46,7 +48,9 @@ public function testGetPasswordHasher()
4648
public function testSetPasswordHasher()
4749
{
4850
$hasher = $this->createMock(PasswordHasherInterface::class);
49-
$object = $this->getMockForTrait(PasswordHasherTrait::class);
51+
$object = new class {
52+
use PasswordHasherTrait;
53+
};
5054

5155
$object->setPasswordHasher($hasher);
5256
$passwordHasher = $object->getPasswordHasher();

0 commit comments

Comments
 (0)