Skip to content

Commit ca50d04

Browse files
authored
Merge pull request #342 from dotkernel/hotfix/php-cs
PHP-CS bug fix
2 parents 0293de7 + 56f7ccc commit ca50d04

File tree

4 files changed

+51
-40
lines changed

4 files changed

+51
-40
lines changed

bin/composer-post-install-script.php

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22

33
declare(strict_types=1);
44

5+
require_once 'vendor/autoload.php';
6+
57
const ENVIRONMENT_DEVELOPMENT = 'development';
68
const ENVIRONMENT_PRODUCTION = 'production';
79

810
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
911

1012
function copyFile(array $file): void
1113
{
14+
if (! in_array(getEnvironment(), $file['environment'])) {
15+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
16+
return;
17+
}
18+
1219
if (is_readable($file['destination'])) {
13-
echo "File {$file['destination']} already exists." . PHP_EOL;
20+
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
21+
return;
22+
}
23+
24+
if (! copy($file['source'], $file['destination'])) {
25+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
1426
} else {
15-
if (! in_array(getEnvironment(), $file['environment'])) {
16-
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
17-
} else {
18-
if (! copy($file['source'], $file['destination'])) {
19-
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
20-
} else {
21-
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
22-
}
23-
}
27+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
2428
}
2529
}
2630

2731
function getEnvironment(): string
2832
{
29-
return file_exists('config/autoload/development.local.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
33+
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
3034
}
3135

3236
// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
@@ -49,4 +53,6 @@ function getEnvironment(): string
4953
],
5054
];
5155

56+
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
57+
5258
array_walk($files, 'copyFile');

config/autoload/local.php.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ return [
3232
],
3333
'routes' => [
3434
'page' => [
35-
'component' => 'components',
35+
'component' => 'components',
3636
],
3737
],
3838
'databases' => $databases,

test/Unit/Admin/Adapter/AuthenticationAdapterTest.php

+25-27
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
use Admin\Admin\Repository\AdminRepository;
1111
use AdminTest\Unit\UnitTest;
1212
use Doctrine\ORM\EntityManager;
13-
use PHPUnit\Framework\MockObject\Exception;
14-
use Psr\Container\ContainerExceptionInterface;
15-
use Psr\Container\NotFoundExceptionInterface;
13+
use Doctrine\ORM\Exception\ORMException;
14+
use PHPUnit\Framework\MockObject\Exception as MockObjectException;
1615
use ReflectionClass;
1716
use ReflectionException;
1817

@@ -24,7 +23,7 @@
2423
class AuthenticationAdapterTest extends UnitTest
2524
{
2625
/**
27-
* @throws Exception
26+
* @throws MockObjectException
2827
* @throws ReflectionException
2928
*/
3029
public function testAccessors(): void
@@ -48,8 +47,8 @@ public function testAccessors(): void
4847
}
4948

5049
/**
51-
* @throws Exception
52-
* @throws \Exception
50+
* @throws MockObjectException
51+
* @throws ORMException
5352
*/
5453
public function testWillNotAuthenticateWithoutValidConfig(): void
5554
{
@@ -98,8 +97,8 @@ public function testWillNotAuthenticateWithoutValidConfig(): void
9897
}
9998

10099
/**
101-
* @throws Exception
102-
* @throws \Exception
100+
* @throws MockObjectException
101+
* @throws ORMException
103102
* @group testing
104103
*/
105104
public function testWillNotAuthenticateWithInvalidIdentityClassConfig(): void
@@ -128,9 +127,8 @@ public function testWillNotAuthenticateWithInvalidIdentityClassConfig(): void
128127
}
129128

130129
/**
131-
* @throws ContainerExceptionInterface
132-
* @throws NotFoundExceptionInterface
133-
* @throws \Exception
130+
* @throws MockObjectException
131+
* @throws ORMException
134132
*/
135133
public function testWillNotAuthenticateWithInvalidIdentityPropertyConfig(): void
136134
{
@@ -158,8 +156,8 @@ public function testWillNotAuthenticateWithInvalidIdentityPropertyConfig(): void
158156
}
159157

160158
/**
161-
* @throws Exception
162-
* @throws \Exception
159+
* @throws MockObjectException
160+
* @throws ORMException
163161
*/
164162
public function testWillNotAuthenticateWithInvalidCredentialPropertyConfig(): void
165163
{
@@ -189,8 +187,8 @@ public function testWillNotAuthenticateWithInvalidCredentialPropertyConfig(): vo
189187
}
190188

191189
/**
192-
* @throws Exception
193-
* @throws \Exception
190+
* @throws MockObjectException
191+
* @throws ORMException
194192
*/
195193
public function testWillNotAuthenticateWhenInvalidIdentity(): void
196194
{
@@ -222,8 +220,8 @@ public function testWillNotAuthenticateWhenInvalidIdentity(): void
222220
}
223221

224222
/**
225-
* @throws Exception
226-
* @throws \Exception
223+
* @throws MockObjectException
224+
* @throws ORMException
227225
*/
228226
public function testWillNotAuthenticateWhenInvalidPassword(): void
229227
{
@@ -261,8 +259,8 @@ public function testWillNotAuthenticateWhenInvalidPassword(): void
261259
}
262260

263261
/**
264-
* @throws Exception
265-
* @throws \Exception
262+
* @throws MockObjectException
263+
* @throws ORMException
266264
*/
267265
public function testWillNotAuthenticateWhenInvalidMethodSpecifiedInOptionsConfig(): void
268266
{
@@ -309,8 +307,8 @@ public function testWillNotAuthenticateWhenInvalidMethodSpecifiedInOptionsConfig
309307
}
310308

311309
/**
312-
* @throws Exception
313-
* @throws \Exception
310+
* @throws MockObjectException
311+
* @throws ORMException
314312
*/
315313
public function testWillNotAuthenticateWhenMissingValueInOptionsConfig(): void
316314
{
@@ -354,8 +352,8 @@ public function testWillNotAuthenticateWhenMissingValueInOptionsConfig(): void
354352
}
355353

356354
/**
357-
* @throws Exception
358-
* @throws \Exception
355+
* @throws MockObjectException
356+
* @throws ORMException
359357
*/
360358
public function testWillNotAuthenticateWhenMissingMessageInOptionsConfig(): void
361359
{
@@ -399,8 +397,8 @@ public function testWillNotAuthenticateWhenMissingMessageInOptionsConfig(): void
399397
}
400398

401399
/**
402-
* @throws Exception
403-
* @throws \Exception
400+
* @throws MockObjectException
401+
* @throws ORMException
404402
*/
405403
public function testWillAuthenticateWithOptionsConfig(): void
406404
{
@@ -445,8 +443,8 @@ public function testWillAuthenticateWithOptionsConfig(): void
445443
}
446444

447445
/**
448-
* @throws Exception
449-
* @throws \Exception
446+
* @throws MockObjectException
447+
* @throws ORMException
450448
*/
451449
public function testWillAuthenticateWithoutOptionsConfig(): void
452450
{

test/Unit/Admin/Handler/Account/PostAccountLoginHandlerTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function testAdminAlreadyLoggedWillReturnRedirectResponse(): void
9494
public function testInvalidLoginFormDataProvidedWillReturnRedirectResponse(): void
9595
{
9696
$this->authenticationService->method('hasIdentity')->willReturn(false);
97+
$this->request->method('getUri')->willReturn($this->createMock(UriInterface::class));
98+
$this->request->method('getParsedBody')->willReturn(['test']);
9799
$this->loginForm->method('isValid')->willReturn(false);
98100
$this->request->method('getParsedBody')->willReturn(['test']);
99101
$this->request->method('getQueryParams')->willReturn([]);
@@ -123,7 +125,6 @@ public function testInvalidLoginFormDataProvidedWillReturnRedirectResponse(): vo
123125
}
124126

125127
/**
126-
* @throws Exception
127128
* @throws MockObjectException
128129
*/
129130
public function testInvalidPasswordProvidedWillReturnRedirectResponse(): void
@@ -179,6 +180,12 @@ public function testAdminInactiveWillReturnRedirectResponse(): void
179180
$this->authenticationAdapter->method('setCredential')->willReturn($this->authenticationAdapter);
180181
$this->authenticationService->method('getAdapter')->willReturn($this->authenticationAdapter);
181182

183+
$this
184+
->messenger
185+
->expects($this->atLeastOnce())
186+
->method('addError')
187+
->with(Message::ADMIN_INACTIVE);
188+
182189
$this
183190
->authenticationService
184191
->expects($this->atLeastOnce())

0 commit comments

Comments
 (0)