Skip to content

Commit

Permalink
ConnectionException is not thrown anymore #6
Browse files Browse the repository at this point in the history
  • Loading branch information
gregor-j committed Oct 23, 2023
1 parent 867eb00 commit 9d70f42
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/SapRfc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace phpsap\saprfc;

use Exception;
use phpsap\classes\AbstractFunction;
use phpsap\classes\Api\RemoteApi;
use phpsap\exceptions\ConnectionFailedException;
Expand All @@ -17,9 +18,9 @@
use phpsap\saprfc\Traits\ConfigTrait;
use phpsap\saprfc\Traits\ParamTrait;
use SAPNWRFC\Connection;
use SAPNWRFC\ConnectionException as ModuleConnectionException;
use SAPNWRFC\FunctionCallException as ModuleFunctionCallException;
use SAPNWRFC\RemoteFunction;
use TypeError;

use function array_merge;
use function get_object_vars;
Expand Down Expand Up @@ -141,7 +142,7 @@ protected function getConnection(): Connection
Connection::setTraceLevel($config->getTrace());
}
$this->connection = new Connection($moduleConfig);
} catch (ModuleConnectionException $exception) {
} catch (Exception | TypeError $exception) {
throw new ConnectionFailedException(sprintf(
'Connection creation failed: %s',
$exception->getMessage()
Expand Down
6 changes: 3 additions & 3 deletions tests/OutputTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace tests\phpsap\saprfc;

use Exception;
use phpsap\classes\Api\RemoteApi;
use phpsap\IntegrationTests\AbstractTestCase;
use phpsap\interfaces\exceptions\IConnectionFailedException;
use phpsap\interfaces\exceptions\IFunctionCallException;
use phpsap\interfaces\exceptions\IIncompleteConfigException;
use phpsap\interfaces\exceptions\IInvalidArgumentException;
use phpsap\interfaces\exceptions\IUnknownFunctionException;
use SAPNWRFC\ConnectionException;
use SAPNWRFC\FunctionCallException;
use SAPNWRFC\RemoteFunction;
use stdClass;
Expand Down Expand Up @@ -367,15 +367,15 @@ public function mockRfcOutputTable()
|| $config['user'] !== $expectedConfig->getUser()
|| $config['passwd'] !== $expectedConfig->getPasswd()
) {
throw new ConnectionException('mock received invalid config array!');
throw new Exception('mock received invalid config array!');
}
//set flag that a connection has been established
$flags->conn = true;
});
static::mock('\SAPNWRFC\Connection::close', static function () use ($flags) {
//calling \SAPNWRFC\Connection::close twice has to fail
if ($flags->conn !== true) {
throw new ConnectionException('mock connection already closed!');
throw new Exception('mock connection already closed!');
}
$flags->conn = false;
return true;
Expand Down
20 changes: 10 additions & 10 deletions tests/SapRfcIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace tests\phpsap\saprfc;

use Exception;
use phpsap\IntegrationTests\AbstractSapRfcTestCase;
use SAPNWRFC\ConnectionException;
use SAPNWRFC\FunctionCallException;
use SAPNWRFC\RemoteFunction;
use stdClass;
Expand Down Expand Up @@ -516,7 +516,7 @@ protected function tearDown(): void
protected function mockConnectionFailed()
{
static::mock('\SAPNWRFC\Connection::__construct', static function (array $config, array $options) {
throw new ConnectionException('mock failed connection');
throw new Exception('mock failed connection');
});
}

Expand All @@ -543,15 +543,15 @@ protected function mockSuccessfulRfcPing()
|| $config['user'] !== $expectedConfig->getUser()
|| $config['passwd'] !== $expectedConfig->getPasswd()
) {
throw new ConnectionException('mock received invalid config array!');
throw new Exception('mock received invalid config array!');
}
//set flag that a connection has been established
$flags->conn = true;
});
static::mock('\SAPNWRFC\Connection::close', static function () use ($flags) {
//calling \SAPNWRFC\Connection::close twice has to fail
if ($flags->conn !== true) {
throw new ConnectionException('mock connection already closed!');
throw new Exception('mock connection already closed!');
}
$flags->conn = false;
return true;
Expand Down Expand Up @@ -610,15 +610,15 @@ protected function mockUnknownFunctionException()
|| $config['user'] !== $expectedConfig->getUser()
|| $config['passwd'] !== $expectedConfig->getPasswd()
) {
throw new ConnectionException('mock received invalid config array!');
throw new Exception('mock received invalid config array!');
}
//set flag that a connection has been established
$flags->conn = true;
});
static::mock('\SAPNWRFC\Connection::close', static function () use ($flags) {
//calling \SAPNWRFC\Connection::close twice has to fail
if ($flags->conn !== true) {
throw new ConnectionException('mock connection already closed!');
throw new Exception('mock connection already closed!');
}
$flags->conn = false;
return true;
Expand Down Expand Up @@ -653,15 +653,15 @@ protected function mockRemoteFunctionCallWithParametersAndResults()
|| $config['user'] !== $expectedConfig->getUser()
|| $config['passwd'] !== $expectedConfig->getPasswd()
) {
throw new ConnectionException('mock received invalid config array!');
throw new Exception('mock received invalid config array!');
}
//set flag that a connection has been established
$flags->conn = true;
});
static::mock('\SAPNWRFC\Connection::close', static function () use ($flags) {
//calling \SAPNWRFC\Connection::close twice has to fail
if ($flags->conn !== true) {
throw new ConnectionException('mock connection already closed!');
throw new Exception('mock connection already closed!');
}
$flags->conn = false;
return true;
Expand Down Expand Up @@ -749,15 +749,15 @@ protected function mockFailedRemoteFunctionCallWithParameters()
|| $config['user'] !== $expectedConfig->getUser()
|| $config['passwd'] !== $expectedConfig->getPasswd()
) {
throw new ConnectionException('mock received invalid config array!');
throw new Exception('mock received invalid config array!');
}
//set flag that a connection has been established
$flags->conn = true;
});
static::mock('\SAPNWRFC\Connection::close', static function () use ($flags) {
//calling \SAPNWRFC\Connection::close twice has to fail
if ($flags->conn !== true) {
throw new ConnectionException('mock connection already closed!');
throw new Exception('mock connection already closed!');
}
$flags->conn = false;
return true;
Expand Down
26 changes: 10 additions & 16 deletions tests/helper/SAPNWRFC.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
namespace SAPNWRFC;

use Exception as PhpException;

/**
* Either run tests using this mock of the sapnwrfc class or run the tests with the
* actual module and an actual SAP system.
Expand Down Expand Up @@ -79,14 +81,6 @@ public function getErrorInfo(): array
}
}

/**
* Class ConnectionException
* @package SAPNWRFC
*/
class ConnectionException extends Exception
{
}

/**
* Class FunctionCallException
* @package SAPNWRFC
Expand Down Expand Up @@ -126,7 +120,7 @@ class Connection
* @var bool $use_function_desc_cache Use function desc cache (defaults to `true`)
* }
*
* @throws ConnectionException if the connection fails.
* @throws PhpException if the connection fails.
*/
public function __construct(array $parameters, array $options = [])
{
Expand All @@ -140,7 +134,7 @@ public function __construct(array $parameters, array $options = [])
*
* @return array Array of connection attributes.
*
* @throws ConnectionException if the connection attributes could not be
* @throws PhpException if the connection attributes could not be
* fetched.
*/
public function getAttributes(): array
Expand All @@ -153,7 +147,7 @@ public function getAttributes(): array
/**
* @return bool True if ping successful.
*
* @throws ConnectionException if the ping failed.
* @throws PhpException if the ping failed.
*/
public function ping(): bool
{
Expand Down Expand Up @@ -185,7 +179,7 @@ public function getFunction(string $functionName): RemoteFunction
* @return bool True if the connection was closed, false if the connection
* is closed already.
*
* @throws ConnectionException if the connection could not be closed.
* @throws PhpException if the connection could not be closed.
*/
public function close(): bool
{
Expand All @@ -203,7 +197,7 @@ public function close(): bool
*
* @return bool True if path was set.
*
* @throws ConnectionException if path could not be set.
* @throws PhpException if path could not be set.
*/
public static function setIniPath(string $path): bool
{
Expand All @@ -220,7 +214,7 @@ public static function setIniPath(string $path): bool
*
* @return bool True if INI file was reloaded.
*
* @throws ConnectionException if the INI file could not be reloaded.
* @throws PhpException if the INI file could not be reloaded.
*/
public static function reloadIniFile(): bool
{
Expand All @@ -236,7 +230,7 @@ public static function reloadIniFile(): bool
*
* @return bool True if path was set.
*
* @throws ConnectionException if path could not be set.
* @throws PhpException if path could not be set.
*/
public static function setTraceDir(string $path): bool
{
Expand All @@ -252,7 +246,7 @@ public static function setTraceDir(string $path): bool
*
* @return bool True if level was set.
*
* @throws ConnectionException if level could not be set.
* @throws PhpException if level could not be set.
*/
public static function setTraceLevel(int $level): bool
{
Expand Down

0 comments on commit 9d70f42

Please sign in to comment.