-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMappersTest.php
More file actions
50 lines (42 loc) · 1.59 KB
/
MappersTest.php
File metadata and controls
50 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace FlagsmithTest\Utils;
use Flagsmith\Utils\Mappers;
use PHPUnit\Framework\TestCase;
class MappersTest extends TestCase
{
/** @return \Generator<string, array<array<string, mixed>>> */
public function extractMapperTestCases(): \Generator
{
$testCasePaths = glob(__DIR__ . '/../Engine/EngineTests/EngineTestData/mapper_test_cases/test_*.{json,jsonc}', \GLOB_BRACE);
foreach ($testCasePaths as $testCasePath) {
$testCaseJson = file_get_contents($testCasePath);
$testCase = json5_decode($testCaseJson);
$testName = basename($testCasePath);
yield $testName => [[
'environment_document' => $testCase->environment_document,
'expected_evaluation_context' => $testCase->expected_evaluation_context,
]];
}
}
/**
* @dataProvider extractMapperTestCases
* @param array<string, mixed> $case
* @return void
*/
public function testMapEnvironmentDocumentToContextMatchesTestData($case): void
{
// Given
$environmentDocument = $case['environment_document'];
// When
$actual = Mappers::mapEnvironmentDocumentToContext($environmentDocument);
// Replace -INF with string "-INF" to allow JSON encoding
$serialized = serialize($actual);
$serialized = str_replace('d:-INF;', 's:4:"-INF";', $serialized);
$actual = unserialize($serialized);
// Then
$this->assertEquals(
$case['expected_evaluation_context'],
json_decode(json_encode($actual)),
);
}
}