|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ArtARTs36\MergeRequestLinter\Tests\Unit\Environment; |
| 4 | + |
| 5 | +use ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment; |
| 6 | +use ArtARTs36\MergeRequestLinter\Exception\EnvironmentDataKeyNotFound; |
| 7 | +use ArtARTs36\MergeRequestLinter\Tests\TestCase; |
| 8 | + |
| 9 | +final class LocalEnvironmentTest extends TestCase |
| 10 | +{ |
| 11 | + public function providerForTestGetString(): array |
| 12 | + { |
| 13 | + return [ |
| 14 | + [ |
| 15 | + 'local_environment_test_var_1=123', |
| 16 | + 'local_environment_test_var_1', |
| 17 | + '123', |
| 18 | + ], |
| 19 | + ]; |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @dataProvider providerForTestGetString |
| 24 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::getString |
| 25 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::get |
| 26 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::doGet |
| 27 | + */ |
| 28 | + public function testGetString(string $assigment, string $key, string $expected): void |
| 29 | + { |
| 30 | + putenv($assigment); |
| 31 | + |
| 32 | + self::assertEquals($expected, (new LocalEnvironment())->getString($key)); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::getString |
| 37 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::get |
| 38 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::doGet |
| 39 | + */ |
| 40 | + public function testGetStringOnNotFound(): void |
| 41 | + { |
| 42 | + self::expectException(EnvironmentDataKeyNotFound::class); |
| 43 | + |
| 44 | + (new LocalEnvironment())->getString('local_environment_test_var_not_found'); |
| 45 | + } |
| 46 | + |
| 47 | + public function providerForTestGetInt(): array |
| 48 | + { |
| 49 | + return [ |
| 50 | + [ |
| 51 | + 'local_environment_test_var_2=123', |
| 52 | + 'local_environment_test_var_2', |
| 53 | + 123, |
| 54 | + ], |
| 55 | + ]; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider providerForTestGetInt |
| 60 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::getInt |
| 61 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::get |
| 62 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::doGet |
| 63 | + */ |
| 64 | + public function testGetInt(string $assigment, string $key, int $expected): void |
| 65 | + { |
| 66 | + putenv($assigment); |
| 67 | + |
| 68 | + self::assertEquals($expected, (new LocalEnvironment())->getInt($key)); |
| 69 | + } |
| 70 | + |
| 71 | + public function providerForTestHas(): array |
| 72 | + { |
| 73 | + return [ |
| 74 | + [ |
| 75 | + "local_environment_test_var_3=123\nlocal_environment_test_var_4=str", |
| 76 | + 'local_environment_test_var_3', |
| 77 | + true, |
| 78 | + ], |
| 79 | + [ |
| 80 | + "local_environment_test_var_3=123\nlocal_environment_test_var_4=str", |
| 81 | + 'local_environment_test_var_not_exists', |
| 82 | + false, |
| 83 | + ], |
| 84 | + ]; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @dataProvider providerForTestHas |
| 89 | + * @covers \ArtARTs36\MergeRequestLinter\Environment\LocalEnvironment::has |
| 90 | + */ |
| 91 | + public function testHas(string $assigment, string $key, bool $expected): void |
| 92 | + { |
| 93 | + putenv($assigment); |
| 94 | + |
| 95 | + self::assertEquals($expected, (new LocalEnvironment())->has($key)); |
| 96 | + } |
| 97 | +} |
0 commit comments