MCPcopy Create free account
hub / github.com/Rello/analytics / BundleDefinitionTest

Class BundleDefinitionTest

tests/Service/BundleDefinitionTest.php:11–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9use PHPUnit\Framework\TestCase;
10
11class BundleDefinitionTest extends TestCase {
12 private function bundle(): array {
13 return json_decode(file_get_contents(__DIR__ . '/../../resources/demo.json'), true, 512, JSON_THROW_ON_ERROR);
14 }
15
16 public function testBundledDemoUsesSharedDatasetsAndPortableReportReferences(): void {
17 $bundle = $this->bundle();
18 BundleDefinition::validate($bundle);
19 $this->assertSame($bundle['reports'][0]['dataset'], $bundle['reports'][1]['dataset']);
20 $this->assertSame($bundle['reports'][5]['dataset'], $bundle['reports'][6]['dataset']);
21 $this->assertCount(6, $bundle['panoramas'][0]['pages'][0]['reports']);
22 $this->assertSame('sales-ranking', $bundle['panoramas'][0]['pages'][0]['reports'][5]['value']);
23 }
24
25 public function testStructureOnlyBundleIsValid(): void {
26 $bundle = $this->bundle();
27 foreach ($bundle['datasets'] as &$dataset) unset($dataset['data']);
28 BundleDefinition::validate($bundle);
29 $this->addToAssertionCount(1);
30 }
31
32 /** @dataProvider invalidCases */
33 public function testInvalidBundlesAreRejectedBeforeCreation(string $case): void {
34 $bundle = $this->bundle();
35 switch ($case) {
36 case 'version': $bundle['version'] = 2; break;
37 case 'duplicate': $bundle['reports'][] = $bundle['reports'][0]; break;
38 case 'dataset-id': $bundle['reports'][0]['dataset'] = 88; break;
39 case 'unknown-dataset': $bundle['reports'][0]['dataset'] = 'foreign'; break;
40 case 'folder': $bundle['reports'][0]['folder'] = 'demo-datasets'; break;
41 case 'tile-id': $bundle['panoramas'][0]['pages'][0]['reports'][0]['value'] = 156; break;
42 case 'filter-id': $bundle['panoramas'][0]['filters'][0]['mappings'][0]['reportId'] = 'foreign'; break;
43 case 'picture': $bundle['panoramas'][0]['pages'][0]['reports'][0] = ['type' => 2, 'value' => '42']; break;
44 case 'precision': $bundle['datasets'][0]['data'][0][2] = '0.3098'; break;
45 case 'row-shape': $bundle['datasets'][0]['data'][0] = ['only one']; break;
46 case 'row-duplicate': $bundle['datasets'][0]['data'][] = $bundle['datasets'][0]['data'][0]; break;
47 case 'nested-folder': $bundle['folders'][0]['parent'] = 'other'; break;
48 case 'notification': $bundle['reports'][0]['thresholds'][0]['severity'] = 1; break;
49 case 'external': $bundle['reports'][0]['type'] = 4; break;
50 case 'flexible': $bundle['datasets'][0]['storageMode'] = 'flexible_shared'; break;
51 }
52 $this->expectException(\InvalidArgumentException::class);
53 BundleDefinition::validate($bundle);
54 }
55
56 public static function invalidCases(): array {
57 return array_map(static fn($case) => [$case], ['version', 'duplicate', 'dataset-id', 'unknown-dataset', 'folder', 'tile-id', 'filter-id', 'picture', 'precision', 'row-shape', 'row-duplicate', 'nested-folder', 'notification', 'external', 'flexible']);
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected