-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
80 lines (75 loc) · 2.48 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require 'ffmpegavcc/classes/curl_handler.php';
require 'ffmpegavcc/util.php';
use \filter_ffmpegavcc\util\Utility;
/* Array to store occuring errors during assertions */
$errors = array();
/* Error handler for assertions */
function error_handler($file, $line, $code, $desc = null)
{
global $errors;
echo "Assertion failed at $file:$line: $code";
if ($desc) {
echo ": $desc";
}
echo "\n";
$errors[$line] = false;
}
/* Generic assertion executor function */
function test_assertion($assertion, $desc = "")
{
assert($assertion, $desc);
}
/* Assertion configuration */
assert_options(ASSERT_ACTIVE, true);
assert_options(ASSERT_WARNING, true);
assert_options(ASSERT_BAIL, false);
assert_options(ASSERT_EXCEPTION, false);
assert_options(ASSERT_CALLBACK, 'error_handler');
/* Base url for the webservice */
$base_url = "http://localhost:3000";
// TODO: Add test cases to array
$test_cases = array();
// Ping Route
$ping_route = "/ping";
$ping_expected_response = "pong";
// GET /conversion
$conversion_route = "/conversion";
$conversion_expected_response = new stdClass;
$conversion_expected_response->{'conversions'} = array();
$conversion_expected_response->{'remainingConversions'} = 0;
// GET /conversion/conversionId
// Should handle FAILURE because non-existent conversionId-url param
// generate uuid
$non_conversion_id = file_get_contents('/proc/sys/kernel/random/uuid');
$conversion_route = "/conversion/" . $non_conversion_id;
$test_cases[$ping_route] = $ping_expected_response;
$test_cases[$conversion_route] = $conversion_expected_response;
foreach ($test_cases as $route => $expected_res) {
$raw = $route == "/ping";
$route = $base_url . $route;
$response = \filter_ffmpegavcc\curl_handler::fetch_url_data(
$route
);
echo "Asserting for route: " . $route . "\n";
test_assertion($response == $expected_res);
}
$conversionfile = "file_example_OGG_1MB.ogg";
if (function_exists("curl_file_create")) {
$conversionfile = curl_file_create("file_example_OGG_1MB.ogg");
} else {
$conversionfile = "@$conversionfile";
}
$req_body = [
"conversionFile" => $conversionfile,
"originalFormat" => '.ogg',
"targetFormat" => '.mp3'
];
var_dump($req_body);
$conversion_response = Utility::start_conversion($req_body);
var_dump($conversion_response);
/*
* If $errors contains a 'false' one of the assertions failed.
* Therefore exit the program with non-zero exitcode.
*/
in_array(false, $errors) ? exit(1) : exit(0);