Skip to content

Commit 4a6b9ab

Browse files
committed
update SAPNWRFC helper to stub from version 2.1.0
1 parent 9e19958 commit 4a6b9ab

File tree

1 file changed

+85
-15
lines changed

1 file changed

+85
-15
lines changed

tests/helper/SAPNWRFC.php

Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* actual module and an actual SAP system.
2222
*/
2323
if (extension_loaded('sapnwrfc')) {
24-
throw new \RuntimeException('PHP module sapnwrfc is loaded. Cannot run tests using mockups.');
24+
die('PHP module sapnwrfc is loaded. Cannot run tests using mockups.');
2525
}
2626

2727
/**
@@ -73,7 +73,7 @@ class Exception extends \RuntimeException
7373
*
7474
* @returns array|null
7575
*/
76-
public function getErrorInfo(): array
76+
public function getErrorInfo(): ?array
7777
{
7878
return $this->errorInfo;
7979
}
@@ -102,21 +102,34 @@ class FunctionCallException extends Exception
102102
class Connection
103103
{
104104
/**
105-
* Disable SAP remote function call tracing.
105+
* Off. Only severe errors are logged to the dev_rfc.log file.
106+
* @var int
106107
*/
107108
public const TRACE_LEVEL_OFF = 0;
108109
/**
109-
* Brief tracing of SAP remote function calls.
110+
* Brief. All API calls (except for the setter and getter functions) and important attributes like codepages,
111+
* RFC headers, logon parameters are traced. Trace is written to a file named rfc<pid>.trc or
112+
* rfc<pid>_<tid>.trc, depending on whether tracing is done on a "per-process" basis or a "per-thread" basis.
113+
* <pid> is the current process ID, <tid> the current thread ID.
114+
* @var int
110115
*/
111116
public const TRACE_LEVEL_BRIEF = 1;
112117
/**
113-
* Verbose tracing of SAP remote function calls.
118+
* Verbose. In addition to 1, the values of the "scalar" RFC parameters as well as the contents of the network
119+
* containers are traced. Scalar parameters are primitive types (CHAR, INT, FLOAT, etc) and flat structures.
120+
* @var int
114121
*/
115122
public const TRACE_LEVEL_VERBOSE = 2;
116123
/**
117-
* Debug-like tracing of SAP remote function calls.
124+
* Detailed. In addition to 2 the contents of nested structures and tables and hexdumps are traced.
125+
* @var int
118126
*/
119-
public const TRACE_LEVEL_FULL = 3;
127+
public const TRACE_LEVEL_DETAILED = 3;
128+
/**
129+
* Full. In addition to 3 all API calls of setter and getter functions and table operations are traced.
130+
* @var int
131+
*/
132+
public const TRACE_LEVEL_FULL = 4;
120133

121134
/**
122135
* Connect to the system using the given parameters.
@@ -166,19 +179,41 @@ public function ping(): bool
166179
* Lookup a RFC function and return a RemoteFunction object.
167180
*
168181
* @param string $functionnName Name of the function.
182+
* @param bool $invalidateCache If true, invalidates the function desc cache.
169183
*
170184
* @return RemoteFunction A RemoteFunction class for the RFC function.
171185
*
172186
* @throws FunctionCallException if the lookup fails or an error is
173187
* returned during parameter parsing.
174188
*/
175-
public function getFunction(string $functionName): RemoteFunction
189+
public function getFunction(string $functionName, bool $invalidateCache = false): RemoteFunction
176190
{
177191
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
178192
->get('\SAPNWRFC\Connection::' . __FUNCTION__);
179193
return $func($functionName);
180194
}
181195

196+
/**
197+
* Retrieve a SSO ticket from the connection.
198+
*
199+
* For this to work, the connection must be opened with parameter `GETSSO2=1`
200+
* and the profile parameter `login/create_sso2_ticket` must be set to a value
201+
* different from '0' in the backend.
202+
*
203+
* Note: To retrieve a SSO ticket from the connection, SDK version 7.50.1 or
204+
* later is required.
205+
*
206+
* @return string The SSO ticket.
207+
*
208+
* @throws ConnectionException if no SSO ticket could be retrieved.
209+
*/
210+
public function getSSOTicket(): string
211+
{
212+
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
213+
->get('\SAPNWRFC\Connection::' . __FUNCTION__);
214+
return $func();
215+
}
216+
182217
/**
183218
* Close the connection.
184219
*
@@ -234,7 +269,7 @@ public static function reloadIniFile(): bool
234269
*
235270
* @param string $path Path to trace directory (must exist).
236271
*
237-
* @return bool True if path was set.
272+
* @return true True if path was set (BC).
238273
*
239274
* @throws ConnectionException if path could not be set.
240275
*/
@@ -250,7 +285,7 @@ public static function setTraceDir(string $path): bool
250285
*
251286
* @param int $level Trace level.
252287
*
253-
* @return bool True if level was set.
288+
* @return true True if trace level was set (BC).
254289
*
255290
* @throws ConnectionException if level could not be set.
256291
*/
@@ -261,14 +296,34 @@ public static function setTraceLevel(int $level): bool
261296
return $func($level);
262297
}
263298

299+
/**
300+
* Sets the global logon timeout in seconds.
301+
*
302+
* Sets the timeout for how long the logon in the ABAP backend can take when opening a connection.
303+
* The default value is 60 seconds.
304+
*
305+
* The timeout can also be set via <code>RFC_GLOBAL_LOGON_TIMEOUT</code> in the <code>DEFAULT</code>
306+
* section of the <em>sapnwrfc.ini</em> file.
307+
*
308+
* @param int $timeout Timeout in seconds (1 - 3600).
309+
*
310+
* @throws ConnectionException if timeout cannot be set or is out of range.
311+
*/
312+
public static function setGlobalLogonTimeout(int $timeout): void
313+
{
314+
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
315+
->get('\SAPNWRFC\Connection::' . __FUNCTION__);
316+
$func($timeout);
317+
}
318+
264319
/**
265320
* Get the extension version.
266321
*
267322
* @return string The extension version.
268323
*/
269324
public static function version(): string
270325
{
271-
return 'SAPNWRFC MOCKUP 1.0';
326+
return 'SAPNWRFC MOCKUP 2.1.0';
272327
}
273328

274329
/**
@@ -289,7 +344,8 @@ public static function rfcVersion(): string
289344
class RemoteFunction
290345
{
291346
/**
292-
* RemoteFunction constructor.
347+
* Manually inserted RemoteFunction constructor for ease of creation by
348+
* \SAPNWRFC\Connection::getFunction()
293349
* @param string $name function name
294350
*/
295351
public function __construct($name)
@@ -325,7 +381,7 @@ public function invoke(array $parameters = [], array $options = []): array
325381
*
326382
* @throws FunctionCallException if the parameter status could not be set.
327383
*/
328-
public function setParameterActive(string $parameterName, bool $isActive)
384+
public function setParameterActive(string $parameterName, bool $isActive): void
329385
{
330386
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
331387
->get('\SAPNWRFC\RemoteFunction::' . __FUNCTION__);
@@ -347,14 +403,28 @@ public function isParameterActive(string $parameterName): bool
347403
}
348404

349405
/**
350-
* Return the SAP remote function API description as array.
406+
* Get the function's parameter description.
407+
*
408+
* @return array The parameter descriptions, indexed by parameter name.
351409
*
352-
* @return array
410+
* @throws FunctionCallException if the interface description cannot be retrieved.
353411
*/
354412
public function getFunctionDescription(): array
355413
{
356414
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
357415
->get('\SAPNWRFC\RemoteFunction::' . __FUNCTION__);
358416
return $func();
359417
}
418+
419+
/**
420+
* Get the function's name.
421+
*
422+
* @return string The function name.
423+
*/
424+
public function getName(): string
425+
{
426+
$func = \phpsap\IntegrationTests\SapRfcModuleMocks::singleton()
427+
->get('\SAPNWRFC\RemoteFunction::' . __FUNCTION__);
428+
return $func();
429+
}
360430
}

0 commit comments

Comments
 (0)