Skip to content

Commit

Permalink
Fixed unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dankovalenko-paysera committed Oct 16, 2024
1 parent 1e4edc5 commit 91e5550
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/WebToPay/Config/EnvReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class WebToPay_EnvReaderTest extends TestCase
{
/**
* @dataProvider getAsArrayData
*/
public function testGetAsString(string $key, ?string $expected, ?string $actual): void
{
$this->assertEquals($expected, $actual);
}

public function getAsArrayData(): iterable
{
$envReader = new WebToPay_EnvReader();

$key = 'testVar';
unset($_ENV[$key]);
putenv($key . '=');

yield 'not exists' => [
$key,
null,
$envReader->getAsString($key),
];

$expected = 'defaultValue';

yield 'with default' => [
$key,
$expected,
$envReader->getAsString($key, $expected),
];

$expected = 'testValue1';

$_ENV[$key] = $expected;

yield 'read from $_ENV' => [
$key,
$expected,
$envReader->getAsString($key),
];

unset($_ENV[$key]);

putenv(sprintf('%s=%s', $key, $expected));

yield 'read from getenv()' => [
$key,
$expected,
$envReader->getAsString($key),
];
}
}

0 comments on commit 91e5550

Please sign in to comment.