Skip to content

Commit 3a98171

Browse files
committed
[#.x] - phpcs and phpstan
1 parent 4811613 commit 3a98171

File tree

5 files changed

+45
-49
lines changed

5 files changed

+45
-49
lines changed

src/Domain/Exceptions/InvalidConfigurationArgumentException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace Phalcon\Api\Domain\Exceptions;
1515

16-
class InvalidConfigurationArgumentException extends \InvalidArgumentException
16+
use InvalidArgumentException;
17+
18+
class InvalidConfigurationArgumentException extends InvalidArgumentException
1719
{
1820
}

src/Domain/Hello/HelloService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __invoke(): Payload
2626
return new Payload(
2727
DomainStatus::SUCCESS,
2828
[
29-
'results' => "Hello World!!! - " . date("Y-m-d H:i:s")
29+
'results' => "Hello World!!! - " . date("Y-m-d H:i:s"),
3030
]
3131
);
3232
}

src/Domain/Services/Env/EnvFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function newInstance(string $name, mixed ...$parameters): AdapterInterfac
3636

3737
$definition = $adapters[$name];
3838
/** @var AdapterInterface $instance */
39-
$instance = new $definition(...$parameters);
39+
$instance = new $definition(...$parameters);
4040
$this->instances[$name] = $instance;
4141
}
4242

tests/Unit/Domain/Services/Env/Adapters/DotEnvTest.php

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,46 @@
1515

1616
use Phalcon\Api\Domain\Exceptions\InvalidConfigurationArgumentException;
1717
use Phalcon\Api\Domain\Services\Env\Adapters\DotEnv;
18-
use Phalcon\Api\Domain\Services\Env\EnvFactory;
1918
use Phalcon\Api\Domain\Services\Env\EnvManager;
2019
use Phalcon\Api\Tests\Unit\AbstractUnitTestCase;
2120

2221
final class DotEnvTest extends AbstractUnitTestCase
2322
{
2423
private string $envFile;
2524

26-
protected function setUp(): void
25+
public function testLoadExceptionForEmptyFilePath(): void
2726
{
28-
$this->envFile = EnvManager::appPath()
29-
. '/tests/Fixtures/Domain/Services/Env/'
30-
;
27+
$this->expectException(InvalidConfigurationArgumentException::class);
28+
$this->expectExceptionMessage(
29+
'The .env file does not exist at the specified path'
30+
);
31+
32+
$dotEnv = new DotEnv();
33+
$options = [
34+
'filePath' => '',
35+
];
36+
37+
$dotEnv->load($options);
38+
}
39+
40+
public function testLoadExceptionForMissingFile(): void
41+
{
42+
$this->expectException(InvalidConfigurationArgumentException::class);
43+
$this->expectExceptionMessage(
44+
'The .env file does not exist at the specified path'
45+
);
46+
47+
$dotEnv = new DotEnv();
48+
$options = [
49+
'filePath' => '/does/not/exist/',
50+
];
51+
52+
$dotEnv->load($options);
3153
}
3254

3355
public function testLoadSuccess(): void
3456
{
35-
$dotEnv = new DotEnv();
57+
$dotEnv = new DotEnv();
3658
$options = [
3759
'filePath' => $this->envFile,
3860
];
@@ -43,7 +65,7 @@ public function testLoadSuccess(): void
4365
'SAMPLE_TRUE' => 'true',
4466
'SAMPLE_FALSE' => 'false',
4567
];
46-
$actual = $dotEnv->load($options);
68+
$actual = $dotEnv->load($options);
4769

4870
$this->assertArrayHasKey('SAMPLE_STRING', $actual);
4971
$this->assertArrayHasKey('SAMPLE_INT', $actual);
@@ -60,33 +82,9 @@ public function testLoadSuccess(): void
6082
$this->assertSame($expected, $actualArray);
6183
}
6284

63-
public function testLoadExceptionForEmptyFilePath(): void
64-
{
65-
$this->expectException(InvalidConfigurationArgumentException::class);
66-
$this->expectExceptionMessage(
67-
'The .env file does not exist at the specified path'
68-
);
69-
70-
$dotEnv = new DotEnv();
71-
$options = [
72-
'filePath' => '',
73-
];
74-
75-
$dotEnv->load($options);
76-
}
77-
78-
public function testLoadExceptionForMissingFile(): void
85+
protected function setUp(): void
7986
{
80-
$this->expectException(InvalidConfigurationArgumentException::class);
81-
$this->expectExceptionMessage(
82-
'The .env file does not exist at the specified path'
83-
);
84-
85-
$dotEnv = new DotEnv();
86-
$options = [
87-
'filePath' => '/does/not/exist/',
88-
];
89-
90-
$dotEnv->load($options);
87+
$this->envFile = EnvManager::appPath()
88+
. '/tests/Fixtures/Domain/Services/Env/';
9189
}
9290
}

tests/Unit/Domain/Services/Env/EnvManagerTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,14 @@
1313

1414
namespace Phalcon\Api\Tests\Unit\Domain\Services\Env;
1515

16-
use Phalcon\Api\Domain\Exceptions\InvalidConfigurationArgumentException;
17-
use Phalcon\Api\Domain\Services\Env\Adapters\DotEnv;
18-
use Phalcon\Api\Domain\Services\Env\EnvFactory;
1916
use Phalcon\Api\Domain\Services\Env\EnvManager;
2017
use Phalcon\Api\Tests\Unit\AbstractUnitTestCase;
21-
use Phalcon\Container\Lazy\Env;
2218
use PHPUnit\Framework\Attributes\BackupGlobals;
2319
use ReflectionClass;
2420

2521
#[BackupGlobals(true)]
2622
final class EnvManagerTest extends AbstractUnitTestCase
2723
{
28-
protected function setUp(): void
29-
{
30-
$ref = new ReflectionClass(EnvManager::class);
31-
$ref->setStaticPropertyValue('isLoaded', false);
32-
$ref->setStaticPropertyValue('settings', []);
33-
}
34-
3524
public function testAppPathReturnsRoot(): void
3625
{
3726
$expected = dirname(__DIR__, 5);
@@ -44,7 +33,7 @@ public function testGetFromDotEnvLoad(): void
4433
$_ENV = [
4534
'APP_ENV_ADAPTER' => 'dotenv',
4635
'APP_ENV_FILE_PATH' => EnvManager::appPath()
47-
. '/tests/Fixtures/Domain/Services/Env/'
36+
. '/tests/Fixtures/Domain/Services/Env/',
4837
];
4938

5039
$values = [
@@ -74,4 +63,11 @@ public function testGetFromDotEnvLoad(): void
7463
$actual = EnvManager::get('SAMPLE_FALSE');
7564
$this->assertSame($expected, $actual);
7665
}
66+
67+
protected function setUp(): void
68+
{
69+
$ref = new ReflectionClass(EnvManager::class);
70+
$ref->setStaticPropertyValue('isLoaded', false);
71+
$ref->setStaticPropertyValue('settings', []);
72+
}
7773
}

0 commit comments

Comments
 (0)