Fixed the test data to comply with the actual stats modifications.

pull/316/head
Ruslan Baidan 2020-06-12 12:40:25 +02:00
parent 285e60c06a
commit 7b198da74f
No known key found for this signature in database
GPG Key ID: 4B7724C136BF1D89
2 changed files with 5991 additions and 798 deletions

View File

@ -103,9 +103,9 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
/** @var AnrTable $anrTable */ /** @var AnrTable $anrTable */
$anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class); $anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class);
$anrs = $anrTable->findAll(); $anrs = $anrTable->findAll();
$anrUuid = []; $anrUuids = [];
foreach ($anrs as $anr) { foreach ($anrs as $anr) {
$anrUuid[] = $anr->getUuid(); $anrUuids[] = $anr->getUuid();
} }
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse())); $this->mockHandler->append(new Response(200, [], $this->getStatsResponse()));
@ -116,7 +116,7 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
$statsAnrService->collectStats(); $statsAnrService->collectStats();
$this->assertJsonStringEqualsJsonString( $this->assertJsonStringEqualsJsonString(
$this->getExpectedStatsDataJson($anrUuid), $this->getExpectedStatsDataJson($anrUuids),
$this->mockHandler->getLastRequest()->getBody()->getContents() $this->mockHandler->getLastRequest()->getBody()->getContents()
); );
} }
@ -128,12 +128,12 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
/** @var AnrTable $anrTable */ /** @var AnrTable $anrTable */
$anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class); $anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class);
$anrs = $anrTable->findByIds($anrIdsToGenerateTheStats); $anrs = $anrTable->findByIds($anrIdsToGenerateTheStats);
$anrUuid = []; $anrUuids = [];
foreach ($anrs as $num => $anr) { foreach ($anrs as $num => $anr) {
$anrUuid[] = $anr->getUuid(); $anrUuids[] = $anr->getUuid();
} }
$this->assertCount(\count($anrIdsToGenerateTheStats), $anrUuid); $this->assertCount(\count($anrIdsToGenerateTheStats), $anrUuids);
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse())); $this->mockHandler->append(new Response(200, [], $this->getStatsResponse()));
$this->mockHandler->append(new Response(201, [], '{"status": "ok"}')); $this->mockHandler->append(new Response(201, [], '{"status": "ok"}'));
@ -143,7 +143,7 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
$statsAnrService->collectStats($anrIdsToGenerateTheStats); $statsAnrService->collectStats($anrIdsToGenerateTheStats);
$this->assertJsonStringEqualsJsonString( $this->assertJsonStringEqualsJsonString(
$this->getExpectedStatsDataJson($anrUuid), $this->getExpectedStatsDataJson($anrUuids),
$this->mockHandler->getLastRequest()->getBody()->getContents() $this->mockHandler->getLastRequest()->getBody()->getContents()
); );
} }
@ -162,7 +162,7 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
]); ]);
} }
private function getExpectedStatsDataJson(array $anrUuid): string private function getExpectedStatsDataJson(array $anrUuids): string
{ {
$allStatsData = json_decode( $allStatsData = json_decode(
file_get_contents($this->testPath . '/data/expected_stats_data_for_all_anrs.json'), file_get_contents($this->testPath . '/data/expected_stats_data_for_all_anrs.json'),
@ -170,17 +170,20 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
); );
$expectedStats = []; $expectedStats = [];
foreach ($allStatsData as $num => $statsData) { foreach ($anrUuids as $num => $anrUuid) {
if (!isset($anrUuid[$num])) { foreach ($allStatsData as $statsData) {
break; if ($statsData['anr'] !== '{{uuid_' . $num . '}}') {
continue;
} }
$statsData['anr'] = $anrUuid[$num]; $statsData['anr'] = $anrUuid;
$statsData['day'] = $this->currentDateParams['day']; $statsData['day'] = $this->currentDateParams['day'];
$statsData['week'] = $this->currentDateParams['week']; $statsData['week'] = $this->currentDateParams['week'];
$statsData['month'] = $this->currentDateParams['month']; $statsData['month'] = $this->currentDateParams['month'];
$statsData['quarter'] = $this->currentDateParams['quarter'];
$statsData['year'] = $this->currentDateParams['year']; $statsData['year'] = $this->currentDateParams['year'];
$expectedStats[] = $statsData; $expectedStats[] = $statsData;
} }
}
return json_encode($expectedStats); return json_encode($expectedStats);
} }
@ -193,6 +196,7 @@ class StatsApiServiceTest extends AbstractIntegrationTestCase
'day' => (int)$dateTime->format('z') + 1, 'day' => (int)$dateTime->format('z') + 1,
'week' => (int)$dateTime->format('W'), 'week' => (int)$dateTime->format('W'),
'month' => (int)$dateTime->format('m'), 'month' => (int)$dateTime->format('m'),
'quarter' => (int)ceil($dateTime->format('m') / 3),
'year' => (int)$dateTime->format('Y'), 'year' => (int)$dateTime->format('Y'),
]; ];
} }

File diff suppressed because it is too large Load Diff