Skip to content

Commit 5c9bfcd

Browse files
authored
Merge pull request #318 from cakephp/authn-v4
Allow using Authentication v4.
2 parents e90a4b4 + cec4ee6 commit 5c9bfcd

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
"psr/http-server-middleware": "^1.0"
3232
},
3333
"require-dev": {
34-
"cakephp/authentication": "^3.0",
34+
"cakephp/authentication": "^3.0 || ^4.0",
3535
"cakephp/bake": "^3.2",
3636
"cakephp/cakephp": "^5.1",
3737
"cakephp/cakephp-codesniffer": "^5.1",
38-
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
38+
"phpunit/phpunit": "^10.5.58 || ^11.5.3 || ^12.4 || ^13.0"
3939
},
4040
"suggest": {
4141
"cakephp/http": "To use \"RequestPolicyInterface\" (Not needed separately if using full CakePHP framework).",

tests/TestCase/IdentityDecoratorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function constructorDataProvider()
3535
#[DataProvider('constructorDataProvider')]
3636
public function testConstructorAccepted($data)
3737
{
38-
$auth = $this->createMock(AuthorizationServiceInterface::class);
38+
$auth = $this->createStub(AuthorizationServiceInterface::class);
3939
$identity = new IdentityDecorator($auth, $data);
4040
$this->assertSame($data['id'], $identity['id']);
4141
}
@@ -82,7 +82,7 @@ public function testApplyScopeAdditionalParams()
8282
public function testCall()
8383
{
8484
$data = new Article(['id' => 1]);
85-
$auth = $this->createMock(AuthorizationServiceInterface::class);
85+
$auth = $this->createStub(AuthorizationServiceInterface::class);
8686
$identity = new IdentityDecorator($auth, $data);
8787
$this->assertFalse(method_exists($identity, 'isDirty'), 'method not defined on decorator');
8888
$this->assertTrue($identity->isDirty('id'), 'method is callable though.');
@@ -92,15 +92,15 @@ public function testCallArray()
9292
{
9393
$this->expectException(BadMethodCallException::class);
9494
$data = ['id' => 1];
95-
$auth = $this->createMock(AuthorizationServiceInterface::class);
95+
$auth = $this->createStub(AuthorizationServiceInterface::class);
9696
$identity = new IdentityDecorator($auth, $data);
9797
$identity->boom();
9898
}
9999

100100
public function testArrayAccessImplementation()
101101
{
102102
$data = new ArrayObject(['id' => 1]);
103-
$auth = $this->createMock(AuthorizationServiceInterface::class);
103+
$auth = $this->createStub(AuthorizationServiceInterface::class);
104104
$identity = new IdentityDecorator($auth, $data);
105105

106106
$this->assertTrue(isset($identity['id']));
@@ -117,15 +117,15 @@ public function testArrayAccessImplementation()
117117
public function testGetOriginalData()
118118
{
119119
$data = ['id' => 2];
120-
$auth = $this->createMock(AuthorizationServiceInterface::class);
120+
$auth = $this->createStub(AuthorizationServiceInterface::class);
121121
$identity = new IdentityDecorator($auth, $data);
122122
$this->assertSame($data, $identity->getOriginalData());
123123
}
124124

125125
public function testGetOriginalDataWrappedObjectHasOriginalData()
126126
{
127127
$data = ['id' => 2];
128-
$auth = $this->createMock(AuthorizationServiceInterface::class);
128+
$auth = $this->createStub(AuthorizationServiceInterface::class);
129129
$inner = new IdentityDecorator($auth, $data);
130130
$identity = new IdentityDecorator($auth, $inner);
131131
$this->assertSame($data, $identity->getOriginalData());
@@ -134,7 +134,7 @@ public function testGetOriginalDataWrappedObjectHasOriginalData()
134134
public function testGetProperty()
135135
{
136136
$data = new Article(['id' => 2]);
137-
$auth = $this->createMock(AuthorizationServiceInterface::class);
137+
$auth = $this->createStub(AuthorizationServiceInterface::class);
138138
$identity = new IdentityDecorator($auth, $data);
139139

140140
$this->assertTrue(isset($identity->id));

tests/TestCase/Middleware/AuthorizationMiddlewareTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AuthorizationMiddlewareTest extends TestCase
4242
{
4343
public function testInvokeService()
4444
{
45-
$service = $this->createMock(AuthorizationServiceInterface::class);
45+
$service = $this->createStub(AuthorizationServiceInterface::class);
4646
$request = new ServerRequest();
4747
$handler = new TestRequestHandler(function ($request) use ($service) {
4848
$this->assertInstanceOf(ServerRequestInterface::class, $request);
@@ -80,7 +80,7 @@ public function testInvokeAuthorizationRequiredError()
8080

8181
public function testInvokeApp()
8282
{
83-
$service = $this->createMock(AuthorizationServiceInterface::class);
83+
$service = $this->createStub(AuthorizationServiceInterface::class);
8484
$provider = $this->createMock(AuthorizationServiceProviderInterface::class);
8585
$provider
8686
->expects($this->once())
@@ -110,7 +110,7 @@ public function testInvokeServiceWithIdentity()
110110
'id' => 1,
111111
]);
112112

113-
$service = $this->createMock(AuthorizationServiceInterface::class);
113+
$service = $this->createStub(AuthorizationServiceInterface::class);
114114
$request = (new ServerRequest())->withAttribute('identity', $identity);
115115
$handler = new TestRequestHandler(function ($request) use ($service) {
116116
$this->assertInstanceOf(RequestInterface::class, $request);
@@ -130,7 +130,7 @@ public function testInvokeServiceWithIdentity()
130130

131131
public function testIdentityInstance()
132132
{
133-
$service = $this->createMock(AuthorizationServiceInterface::class);
133+
$service = $this->createStub(AuthorizationServiceInterface::class);
134134
$identity = new IdentityDecorator($service, [
135135
'id' => 1,
136136
]);
@@ -155,7 +155,7 @@ public function testCustomIdentity()
155155
'id' => 1,
156156
];
157157

158-
$service = $this->createMock(AuthorizationServiceInterface::class);
158+
$service = $this->createStub(AuthorizationServiceInterface::class);
159159
$request = (new ServerRequest())->withAttribute('user', $identity);
160160
$handler = new TestRequestHandler(function ($request) use ($service) {
161161
$this->assertInstanceOf(RequestInterface::class, $request);
@@ -183,7 +183,7 @@ public function testCustomIdentityDecorator()
183183
'id' => 1,
184184
]);
185185

186-
$service = $this->createMock(AuthorizationServiceInterface::class);
186+
$service = $this->createStub(AuthorizationServiceInterface::class);
187187
$request = (new ServerRequest())->withAttribute('identity', $identity);
188188
$handler = new TestRequestHandler(function ($request) use ($service, $identity) {
189189
$this->assertInstanceOf(RequestInterface::class, $request);
@@ -212,7 +212,7 @@ public function testInvalidIdentity()
212212
'id' => 1,
213213
];
214214

215-
$service = $this->createMock(AuthorizationServiceInterface::class);
215+
$service = $this->createStub(AuthorizationServiceInterface::class);
216216
$request = (new ServerRequest())->withAttribute('identity', $identity);
217217
$handler = new TestRequestHandler();
218218

@@ -229,7 +229,7 @@ public function testInvalidIdentity()
229229

230230
public function testUnauthorizedHandler()
231231
{
232-
$service = $this->createMock(AuthorizationServiceInterface::class);
232+
$service = $this->createStub(AuthorizationServiceInterface::class);
233233
$request = new ServerRequest();
234234
$handler = new TestRequestHandler(function () {
235235
throw new Exception();
@@ -243,7 +243,7 @@ public function testUnauthorizedHandler()
243243

244244
public function testUnauthorizedHandlerSuppress()
245245
{
246-
$service = $this->createMock(AuthorizationServiceInterface::class);
246+
$service = $this->createStub(AuthorizationServiceInterface::class);
247247
$request = new ServerRequest();
248248
$handler = new TestRequestHandler(function () {
249249
throw new Exception();
@@ -260,7 +260,7 @@ public function testUnauthorizedHandlerSuppress()
260260

261261
public function testUnauthorizedHandlerRequireAuthz()
262262
{
263-
$service = $this->createMock(AuthorizationServiceInterface::class);
263+
$service = $this->createStub(AuthorizationServiceInterface::class);
264264
$request = new ServerRequest();
265265
$handler = new TestRequestHandler(function () {
266266
throw new Exception();
@@ -301,7 +301,7 @@ public function testMiddlewareInjectsServiceIntoDICViaCustomContainerInstance()
301301
);
302302
$handler = new TestRequestHandler();
303303

304-
$service = $this->createMock(AuthorizationServiceInterface::class);
304+
$service = $this->createStub(AuthorizationServiceInterface::class);
305305
$provider = $this->createMock(AuthorizationServiceProviderInterface::class);
306306
$provider
307307
->expects($this->once())

tests/TestCase/Policy/Exception/MissingPolicyExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MissingPolicyExceptionTest extends TestCase
2727
public function testConstructQueryInstance(): void
2828
{
2929
$articles = new ArticlesTable();
30-
$query = $this->createMock(QueryInterface::class);
30+
$query = $this->createStub(QueryInterface::class);
3131
$query->method('getRepository')
3232
->willReturn($articles);
3333
$missingPolicyException = new MissingPolicyException($query);

tests/TestCase/Policy/OrmResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function testGetPolicyUnknownTable()
119119
{
120120
$this->expectException(MissingPolicyException::class);
121121

122-
$articles = $this->createMock('Cake\Datasource\RepositoryInterface');
122+
$articles = $this->createStub('Cake\Datasource\RepositoryInterface');
123123
$resolver = new OrmResolver('TestApp');
124124
$resolver->getPolicy($articles);
125125
}

0 commit comments

Comments
 (0)