/** @test */
 public function serviceTest()
 {
     $config = $this->unknownService();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "unknown-service";
     $this->assertSame($expectRes, "unknown-service");
     $config = $this->mailgunTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = array("message" => "Queued. Thank you.");
     $this->assertSame($expectRes["message"], $response["message"]);
     $config = $this->imgurFileNot();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "file not found";
     $this->assertSame($expectRes, $response);
     $config = $this->imgurTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = array("success" => true, "status" => 200);
     $this->assertSame($expectRes["success"], $response["success"]);
     $this->assertSame($expectRes["status"], $response["status"]);
     $config = $this->imageShackFileNot();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "file not found";
     $this->assertSame($expectRes, $response);
     $config = $this->imageShackTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "http://imagizer.imageshack.com";
     $this->assertSame(0, (int) strpos($response['links']['image_link'], $expectRes));
     $config = $this->bitlyTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "http://bit.ly/";
     $this->assertSame(0, (int) strpos($response["data"]["url"], $expectRes));
     $config = $this->googlTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "http://goo.gl/";
     $this->assertSame(0, (int) strpos($response["id"], $expectRes));
     $config = $this->mcafeeTest();
     $bundle = new \peter\components\serviceBundle\serviceBundle($config);
     $response = $bundle->sendReq();
     $expectRes = "http://mcaf.ee/";
     $this->assertSame(0, (int) strpos($response["data"]["url"], $expectRes));
 }
Beispiel #2
0
        echo "index.js file not found.";
    }
    return $response;
});
$router->post('/post/url', function () {
    $serviceName = filter_input(INPUT_POST, "sel-service");
    $longUrl = filter_input(INPUT_POST, "longUrl");
    if (isset($serviceName) && isset($longUrl)) {
        $key = file_get_contents("auth/key.txt");
        $key = json_decode($key, true);
        if ($serviceName === "goo.gl") {
            $config = array('service-name' => $serviceName, 'longUrl' => $longUrl, 'apiKey' => $key[$serviceName]);
        } else {
            if ($serviceName === "bit.ly") {
                $config = array('service-name' => $serviceName, 'longUrl' => $longUrl, 'apiKey' => $key[$serviceName]["apiKey"], 'login' => $key[$serviceName]["login"]);
            } else {
                $config = array('service-name' => $serviceName, 'longUrl' => $longUrl);
            }
        }
        $bundle = new \peter\components\serviceBundle\serviceBundle($config);
        echo json_encode($bundle->sendReq());
    } else {
        echo "Oops ! no data input";
    }
});
$router->set404(function () {
    header('HTTP/1.1 404 Not Found');
    // ... do something special here
    echo file_get_contents("404.html");
});
$router->run();