Example #1
0
    /**
     * Format and echo output from extracted data
     * @param $method
     * @param $requestPath
     * @param array $summary
     */
    protected function formatOutput($method, $requestPath, array $summary)
    {
        // these 3 aren't really needed.
        // here for:
        // 1- To not give warnings in IDE about unknown variables
        // 2- To set a default value, always a safer practice.
        $dynos = array();
        $totalOccurrences = 0;
        $responseTimes = array();
        extract($summary);
        if (!$totalOccurrences) {
            // not using die() as it causes issue with ob_*
            echo "No occurrences of {$method} {$requestPath} found" . PHP_EOL;
            return;
        }
        $mostCommonDyno = ArrayUtil::findModes($dynos);
        $leastCommonDyno = ArrayUtil::findLeastCommonValues($dynos);
        $meanResponseTime = ArrayUtil::findMean($responseTimes);
        $medianResponseTime = ArrayUtil::findMedian($responseTimes);
        $modeResponseTimes = ArrayUtil::findModes($responseTimes);
        $minResponseTime = min($responseTimes);
        $maxResponseTime = max($responseTimes);
        $summary = <<<SUMMARY
        Number of times request was made: %d
        Most active Dyno(s): %s
        Least active Dyno(s): %s
        Min. Response Time: %d
        Max. Response Time: %d
        Mean Response Time: %f
        Median Response Time: %f
        Mode Response Time(s): %s

SUMMARY;
        echo sprintf($summary, $totalOccurrences, implode(', ', $mostCommonDyno), implode(', ', $leastCommonDyno), $minResponseTime, $maxResponseTime, $meanResponseTime, $medianResponseTime, implode(', ', $modeResponseTimes));
    }
 /**
  * @depends testFindLeastCommonValuesWithSingleLeastCommonElementArray
  */
 public function testFindLeastCommonValuesWithMultipleLeastCommonElementsArray()
 {
     $mode = ArrayUtil::findLeastCommonValues(array(1, 2, 4, 2));
     $this->assertEquals(array(1, 4), $mode);
 }