Beispiel #1
0
 public function testFetchContent()
 {
     $obj = new _Json();
     $json_content = $obj->setURI(TEST_FILES . 'test_input.json')->fetchContent();
     $this->integer(count($json_content))->isEqualTo(2);
     $this->boolean(isset($json_content['www.mozilla.org']))->isTrue();
 }
Beispiel #2
0
// Launch PHP dev server in the background
chdir("{$root_folder}/web");
exec('php -S 0.0.0.0:8083 > /dev/null 2>&1 & echo $!', $output);
// We will need the pid to kill it, beware, this is the pid of the php server started above
$pid = $output[0];
// Pause to let time for the dev server to launch in the background
sleep(3);
$failures = [];
$base_url = 'http://localhost:8083/';
$json_data = new Json();
// Base URL
$headers = get_headers($base_url, 1);
if (strpos($headers[0], '200 OK') === false) {
    $failures[] = "HTTP status for base URL is: {$headers[0]}. Expected: 200.";
}
$response = $json_data->setURI($base_url)->fetchContent();
if (!isset($response[0])) {
    $failures[] = "Product 0 is missing.";
} else {
    if ($response[0]['id'] !== 'beta') {
        $failures[] = "Product 0 is not 'beta'.";
    }
    if (!in_array('de', $response[0]['locales'])) {
        $failures[] = "'de' is missing from product 0.";
    }
}
// /?repo=unknown
$url = $base_url . '?repo=unknown';
$headers = get_headers($url, 1);
if (strpos($headers[0], '400 Bad Request') === false) {
    $failures[] = "HTTP status for /?repo=unknown is: {$headers[0]}. Expected: 400.";
<?php

namespace Transvision;

use Json\Json;
// Create a JSON file logging locale/number of requests
$json_data = new Json();
$local_filename = CACHE_PATH . 'stats_locales.json';
$stats = $json_data->setURI($local_filename)->fetchContent();
$stats[$locale] = array_key_exists($locale, $stats) ? $stats[$locale] += 1 : 1;
$json_data->saveFile($stats, $local_filename);
// Create a JSON file logging search options to determine if some are unused
$local_filename = CACHE_PATH . 'stats_requests.json';
$stats = $json_data->setURI($local_filename)->fetchContent();
foreach ($check as $k => $v) {
    if (in_array($k, $form_checkboxes) && $v == 1) {
        $stats[$k] = array_key_exists($k, $stats) ? $stats[$k] += 1 : 1;
    }
    if (in_array($k, array_diff($form_search_options, $form_checkboxes))) {
        $stats[$v] = array_key_exists($v, $stats) ? $stats[$v] += 1 : 1;
    }
    $json_data->saveFile($stats, $local_filename);
}
unset($stats);