Skip to content

Commit 3f3d62d

Browse files
committed
Sap::getAttributes() throws exception when not connected
1 parent 4300190 commit 3f3d62d

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

classes/Sap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public function getFunctionClass(): string
9393
* Get connection attributes
9494
*
9595
* @return array
96+
*
97+
* @throws SapConnectionException if no connection is available
9698
*/
9799
public function getAttributes(): array
98100
{

php_sap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ PHP_METHOD(Sap, getAttributes)
22662266
int utf8len;
22672267

22682268
if (NULL == intern->connection) {
2269-
zend_error_noreturn(E_ERROR, "No active connection found");
2269+
zend_throw_exception(sap_ce_SapConnectionException, PHP_SAP_NO_CONNECTION, -1);
2270+
return;
22702271
}
22712272

22722273
if (RFC_OK != RfcGetConnectionAttributes(intern->connection->handle, &attributes, (RFC_ERROR_INFO*)&err))

tests/sap_Sap___construct_basic.phpt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@ if (!$config) {
1313
/** test constructor no arguments */
1414
$s = new Sap();
1515

16+
/** test connect() is not called */
17+
try { $s->getAttributes(); }
18+
catch (SapConnectionException $e) {
19+
echo $e->getMessage(), PHP_EOL;
20+
}
21+
1622
/** test constructor passing null as logon parameters is ok */
1723
$s = new Sap(null);
1824

25+
/** test connect() is not called */
26+
try { $s->getAttributes(); }
27+
catch (SapConnectionException $e) {
28+
echo $e->getMessage(), PHP_EOL;
29+
}
30+
1931
$config = include 'config.inc';
2032

33+
/** test can connect */
2134
$s = new Sap($config);
2235
?>
23-
--EXPECT--
36+
--EXPECT--
37+
There is no connection to a SAP R/3 system
38+
There is no connection to a SAP R/3 system
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Sap::getAttributes error behavior
3+
--FILE--
4+
<?php
5+
$s = new Sap();
6+
7+
try { $s->getAttributes(); }
8+
catch (SapConnectionException $e) {
9+
echo $e->getMessage(), PHP_EOL;
10+
}
11+
?>
12+
--EXPECT--
13+
There is no connection to a SAP R/3 system

0 commit comments

Comments
 (0)