Skip to content

Commit

Permalink
fixing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Mar 1, 2020
1 parent f218967 commit 5deb1ac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
5 changes: 4 additions & 1 deletion core/ArchiveProcessor/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ protected function isArchivingForcedToTrigger()
public function loadExistingArchiveIdFromDb()
{
if ($this->isArchivingForcedToTrigger()) {
return [false, false, false, false]; // no usable archive found, no existing archive
// TODO: lot's log here
// return no usable archive found, no existing archive. this will skip invalidation, which should
// be fine since we just force archiving. TODO: check this is true?
return [false, false, false, false];
}

$minDatetimeArchiveProcessedUTC = $this->getMinTimeArchiveProcessed();
Expand Down
26 changes: 17 additions & 9 deletions core/DataAccess/ArchiveSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ public static function getArchiveIdAndVisits(ArchiveProcessor\Parameters $params
return [false, false, false, false];
}

$result = self::findArchiveDataWithLatestTsArchived($results, $requestedPlugin, $segment);
if (!isset($result['idarchive'])
|| !isset($result['nb_visits'])
) {
return [false, false, false, true];
$result = self::findArchiveDataWithLatestTsArchived($results, $plugins, $segment);
if (!isset($result['idarchive'])) {
return [false, false, false, false];
}

if (!in_array($result['value'], $doneFlagValues)) { // the archive cannot be considered valid for this request (has wrong done flag value)
Expand All @@ -92,8 +90,8 @@ public static function getArchiveIdAndVisits(ArchiveProcessor\Parameters $params
}

$idArchive = $result['idarchive'];
$visits = $result['nb_visits'];
$visitsConverted = $result['nb_visits_converted'];
$visits = isset($result['nb_visits']) ? $result['nb_visits'] : false;
$visitsConverted = isset($result['nb_visits_converted']) ? $result['nb_visits_converted'] : false;

return array($idArchive, $visits, $visitsConverted, true);
}
Expand Down Expand Up @@ -344,9 +342,9 @@ private static function getNameCondition(array $plugins, Segment $segment, $incl
}

// TODO: document magic method
private static function findArchiveDataWithLatestTsArchived($results, $requestedPlugin, $segment)
private static function findArchiveDataWithLatestTsArchived($results, $plugins, $segment)
{
$namesRequestedPlugin = Rules::getDoneFlags(array($requestedPlugin), $segment);
$namesRequestedPlugin = Rules::getDoneFlags($plugins, $segment);

// find latest idarchive for each done flag
$idArchives = [];
Expand All @@ -372,6 +370,16 @@ private static function findArchiveDataWithLatestTsArchived($results, $requested
}
}

// if an archive is found, but the metric data isn't found, we set the value to 0,
// so it won't get returned as false. // TODO: note if this is for BC or not. first check if it is for BC or not.
foreach ([self::NB_VISITS_RECORD_LOOKED_UP, self::NB_VISITS_CONVERTED_RECORD_LOOKED_UP] as $metric) {
if (!empty($idArchives)
&& !isset($archiveData[$metric])
) {
$archiveData[$metric] = 0;
}
}

// set the idarchive & ts_archived for the archive we're looking for
foreach ($results as $row) {
$name = $row['name'];
Expand Down
2 changes: 1 addition & 1 deletion core/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ protected function addFilter_notification()
if (!empty($options['raw'])) {
$template .= piwik_fix_lbrace($message);
} else {
$template .= twig_escape_filter($twigEnv, $message, 'html');
$template .= piwik_escape_filter($twigEnv, $message, 'html');
}

$template .= '</div>';
Expand Down
4 changes: 4 additions & 0 deletions plugins/Monolog/Processor/ExceptionToTextProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ private function getStackTrace($exception)

public static function getWholeBacktrace(\Exception $exception, $shouldPrintBacktrace = true)
{
if (!$shouldPrintBacktrace) {
return $exception->getMessage();
}

$message = "";

$e = $exception;
Expand Down
12 changes: 6 additions & 6 deletions tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function test_loadExistingArchiveIdFromDb_returnsFalsesIfNoArchiveFound()

$archiveInfo = $loader->loadExistingArchiveIdFromDb();

$this->assertEquals([false, false, false], $archiveInfo);
$this->assertEquals([false, false, false, false], $archiveInfo);
}

/**
Expand All @@ -55,12 +55,12 @@ public function test_loadExistingArchiveIdFromDb_returnsFalsesPeriodIsForcedToAr
$loader = new Loader($params);

$archiveInfo = $loader->loadExistingArchiveIdFromDb();
$this->assertNotEquals([false, false, false], $archiveInfo);
$this->assertNotEquals([false, false, false, false], $archiveInfo);

Config::getInstance()->Debug[$configSetting] = 1;

$archiveInfo = $loader->loadExistingArchiveIdFromDb();
$this->assertEquals([false, false, false], $archiveInfo);
$this->assertEquals([false, false, false, false], $archiveInfo);
}

public function getTestDataForLoadExistingArchiveIdFromDbDebugConfig()
Expand All @@ -82,7 +82,7 @@ public function test_loadExistingArchiveIdFromDb_returnsArchiveIfArchiveInThePas
$loader = new Loader($params);

$archiveInfo = $loader->loadExistingArchiveIdFromDb();
$this->assertEquals(['1', '10', '0'], $archiveInfo);
$this->assertEquals(['1', '10', '0', true], $archiveInfo);
}

public function test_loadExistingArchiveIdFromDb_returnsArchiveIfForACurrentPeriod_AndNewEnough()
Expand All @@ -93,7 +93,7 @@ public function test_loadExistingArchiveIdFromDb_returnsArchiveIfForACurrentPeri
$loader = new Loader($params);

$archiveInfo = $loader->loadExistingArchiveIdFromDb();
$this->assertEquals(['1', '10', '0'], $archiveInfo);
$this->assertEquals(['1', '10', '0', true], $archiveInfo);
}

public function test_loadExistingArchiveIdFromDb_returnsNoArchiveIfForACurrentPeriod_AndNoneAreNewEnough()
Expand All @@ -104,7 +104,7 @@ public function test_loadExistingArchiveIdFromDb_returnsNoArchiveIfForACurrentPe
$loader = new Loader($params);

$archiveInfo = $loader->loadExistingArchiveIdFromDb();
$this->assertEquals([false, false, false], $archiveInfo);
$this->assertEquals([false, false, false, true], $archiveInfo);
}

private function insertArchive(Parameters $params, $tsArchived = null, $visits = 10)
Expand Down

0 comments on commit 5deb1ac

Please sign in to comment.