-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
82 lines (82 loc) · 2.51 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
81
82
<?php
/**
* Check if extension is loaded.
*/
if (!extension_loaded('sapnwrfc')) {
throw new RuntimeException('PHP module sapnwrfc not loaded!');
}
printf('PHP module sapnwrfc version: %s%s', phpversion('sapnwrfc'), PHP_EOL);
$configFile = __DIR__ . DIRECTORY_SEPARATOR . 'sap.json';
/**
* Determine whether the config file exists or not.
*/
if (file_exists($configFile) !== true) {
throw new RuntimeException(sprintf(
'Cannot find config file %s! Create one from the template.',
$configFile
));
}
/**
* Try to read the configuration file.
*/
if (($configJson = file_get_contents($configFile)) === false) {
throw new RuntimeException(sprintf(
'Cannot read from config file %s!',
$configFile
));
}
$config = json_decode($configJson, true);
if (!is_array($config)) {
throw new RuntimeException(sprintf(
'Invalid format of config file %s!',
$configFile
));
}
/**
* Create connection instance to SAP using the config.
*/
echo 'Creating connection ... ';
$connection = new \SAPNWRFC\Connection($config);
echo 'OK.' . PHP_EOL;
/**
* First test: Call RFC_PING to see if remote function calls work.
*/
echo 'Calling RFC_PING ... ';
try {
$rfcPing = $connection->getFunction('RFC_PING');
$result = $rfcPing->invoke();
} catch (Exception $exception) {
echo 'FAIL! ' . get_class($exception) . ': ' . $exception->getMessage() . PHP_EOL;
exit(1);
}
echo 'OK.' . PHP_EOL;
/**
* Second test step 1: Get the description of a remote function.
*/
echo 'Get description of RFC_WALK_THRU_TEST ... ';
$walkthrough = $connection->getFunction('RFC_WALK_THRU_TEST');
if (!method_exists($walkthrough, 'getFunctionDescription')) {
echo 'FAIL! ' . get_class($walkthrough) . '::getFunctionDescription() doesn\'t exist.' . PHP_EOL;
exit(1);
}
/**
* Second test step 2: Rudimentary check whether the description is as expected.
*/
$description = $walkthrough->getFunctionDescription();
if (!is_array($description) || !array_key_exists('TEST_OUT', $description)) {
echo 'FAIL! Cannout find TEST_OUT in description.' . PHP_EOL;
exit(1);
}
if (!is_array($description['TEST_OUT'])
|| !array_key_exists('typedef', $description['TEST_OUT'])
) {
echo 'FAIL! Cannout find TEST_OUT.typedef in description.' . PHP_EOL;
exit(1);
}
if (!is_array($description['TEST_OUT']['typedef'])
|| !array_key_exists('RFCCHAR1', $description['TEST_OUT']['typedef'])
) {
echo 'FAIL! Cannout find TEST_OUT.typedef.RFCCHAR1 in description.' . PHP_EOL;
exit(1);
}
echo 'OK.' . PHP_EOL;