Skip to content

Commit

Permalink
implement package specific functions for abstract remote function cal…
Browse files Browse the repository at this point in the history
…l class
  • Loading branch information
gregor-j committed Jan 21, 2019
1 parent 254497d commit b86e0e6
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/AbstractRemoteFunctionCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* File src/AbstractRemoteFunctionCall.php
*
* PHP/SAP proxy class for SAP remote function calls.
*
* @package saprfc-harding
* @author Gregor J.
* @license MIT
*/

namespace phpsap\saprfc;

use phpsap\interfaces\IConfig;

/**
* Class phpsap\saprfc\AbstractRemoteFunctionCall
*
* Abstract class handling a PHP/SAP connection and remote function.
*
* @package phpsap\saprfc
* @author Gregor J.
* @license MIT
*/
abstract class AbstractRemoteFunctionCall extends \phpsap\classes\AbstractRemoteFunctionCall
{
/**
* Create a connection instance using the given config.
* @param \phpsap\interfaces\IConfig $config
* @return \phpsap\interfaces\IConnection|\phpsap\saprfc\SapRfcConnection
* @throws \phpsap\interfaces\exceptions\IIncompleteConfigException
*/
protected function createConnectionInstance(IConfig $config)
{
return new SapRfcConnection($config);
}

/**
* Get the typecast of the expected return values.
* @return \kbATeam\TypeCast\ITypeCast|null
*/
protected function getReturnTypecast()
{
return null;
}
}
62 changes: 62 additions & 0 deletions tests/AbstractRemoteFunctionCallTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* File src/AbstractRemoteFunctionCallTest.php
*
* Test the abstract remote function call.
*
* @package saprfc-harding
* @author Gregor J.
* @license MIT
*/

namespace tests\phpsap\saprfc;

use phpsap\saprfc\SapRfcConfigA;
use phpsap\saprfc\SapRfcConnection;
use PHPUnit\Framework\TestCase;
use tests\phpsap\saprfc\helper\RemoteFunctionCall;

/**
* Class tests\phpsap\saprfc\AbstractRemoteFunctionCallTest
*
* Test the abstract remote function call.
*
* @package tests\phpsap\saprfc
* @author Gregor J.
* @license MIT
*/
class AbstractRemoteFunctionCallTest extends TestCase
{
/**
* Test test creating a package specific connection instance.
*/
public function testCreateConnectionInstance()
{
$config = new SapRfcConfigA([
'ashost' => 'sap.example.com',
'sysnr' => '001',
'client' => '002',
'user' => 'username',
'passwd' => 'password'
]);
$rfc = new RemoteFunctionCall($config);
$connection = $rfc->createConnectionInstance($config);
static::assertInstanceOf(SapRfcConnection::class, $connection);
}

/**
* Test getting an empty return typecast.
*/
public function testGetReturnTypecast()
{
$config = new SapRfcConfigA([
'ashost' => 'sap.example.com',
'sysnr' => '001',
'client' => '002',
'user' => 'username',
'passwd' => 'password'
]);
$rfc = new RemoteFunctionCall($config);
static::assertNull($rfc->getReturnTypecast());
}
}
63 changes: 63 additions & 0 deletions tests/helper/RemoteFunctionCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* File tests/helper/RemoteFunctionCall.php
*
* Helper class extending the abstract remote function class for testing.
*
* @package common
* @author Gregor J.
* @license MIT
*/

namespace tests\phpsap\saprfc\helper;

use phpsap\interfaces\IConfig;
use phpsap\saprfc\AbstractRemoteFunctionCall;

/**
* Class tests\phpsap\saprfc\helper\RemoteFunctionCall
*
* Helper class extending the abstract remote function class for testing.
*
* @package tests\phpsap\saprfc\helper
* @author Gregor J.
* @license MIT
*/
class RemoteFunctionCall extends AbstractRemoteFunctionCall
{
/**
* @var string function name
*/
public $returnName = 'cketfemo';

/**
* The SAP remote function name.
* @return string
*/
public function getName()
{
return $this->returnName;
}

/**
* Make protected function public for testing.
* Create a connection instance using the given config.
* @param \phpsap\interfaces\IConfig $config
* @return \phpsap\interfaces\IConnection|\phpsap\saprfc\SapRfcConnection
* @throws \phpsap\interfaces\exceptions\IIncompleteConfigException
*/
public function createConnectionInstance(IConfig $config)
{
return parent::createConnectionInstance($config);
}

/**
* Make protected function public for testing.
* Get the typecast of the expected return values.
* @return \kbATeam\TypeCast\ITypeCast|null
*/
public function getReturnTypecast()
{
return parent::getReturnTypecast();
}
}

0 comments on commit b86e0e6

Please sign in to comment.