Skip to content

Commit dac961d

Browse files
committed
remove getReturnTypecast() and rely on overwriting invoke()
* Remove getReturnTypecast() method because it is more transparent to rely on the user-code to overwrite invoke() for typecasting. * Remove suggestion for kba-team/typecast from composer. * Remove kba-team/typecast from composer dev-requirements. * Remove reset() from invoke(). * Update tests.
1 parent bf56c9b commit dac961d

File tree

5 files changed

+10
-87
lines changed

5 files changed

+10
-87
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"psr/container": "^1.0"
2727
},
2828
"suggest": {
29-
"kba-team/typecast": "Automatically typecast the return values of a SAP remote function call when extending AbstractRemoteFunctionCall."
29+
"php-sap/datetime": "Cast and/or export SAP week date, time and timestamp formats to/from DateTime."
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -40,8 +40,7 @@
4040
}
4141
},
4242
"require-dev": {
43-
"phpunit/phpunit": "^4.8",
44-
"kba-team/typecast": "^1.0"
43+
"phpunit/phpunit": "^4.8"
4544
},
4645
"scripts": {
4746
"tests": "vendor/bin/phpunit"

composer.lock

Lines changed: 1 addition & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AbstractRemoteFunctionCall.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,8 @@ public function setParam($name, $value)
8787
public function invoke($params = null)
8888
{
8989
//invoke the remove function call
90-
$result = $this->getFunction()
90+
return $this->getFunction()
9191
->invoke($params);
92-
$this->reset();
93-
//cast the return values to the types defined in the implementing class
94-
$typecast = $this->getReturnTypecast();
95-
if ($typecast !== null) {
96-
return $typecast->cast($result);
97-
}
98-
return $result;
9992
}
10093

10194
/**
@@ -120,12 +113,6 @@ protected function getFunction()
120113
*/
121114
abstract public function getName();
122115

123-
/**
124-
* Get the typecast of the expected return values.
125-
* @return \kbATeam\TypeCast\ITypeCast|null
126-
*/
127-
abstract protected function getReturnTypecast();
128-
129116
/**
130117
* Create a connection instance using the given config.
131118
* @param \phpsap\interfaces\IConfig $config

tests/AbstractRemoteFunctionCallTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,11 @@ public function testReset()
117117
/**
118118
* Test invoking a remote function call without parameters.
119119
*/
120-
public function testInvokeWithoutTypecast()
120+
public function testInvoke()
121121
{
122122
$rfc = new RemoteFunctionCall(new ConfigA());
123123
$rfc->getFunction()->results = ['gpgtowzq' => 'C5AWVD1h'];
124124
$results = $rfc->invoke();
125125
static::assertSame(['gpgtowzq' => 'C5AWVD1h'], $results);
126126
}
127-
128-
public function testInvokeWithTypecast()
129-
{
130-
$rfc = new RemoteFunctionCall(new ConfigA());
131-
$rfc->getFunction()->results = ['rjgcdeyl' => "6.19"];
132-
$rfc->returnTypecast = new TypeCastArray();
133-
$rfc->returnTypecast['rjgcdeyl'] = new TypeCastValue('float');
134-
$results = $rfc->invoke();
135-
static::assertArrayHasKey('rjgcdeyl', $results);
136-
static::assertSame(6.19, $results['rjgcdeyl']);
137-
}
138127
}

tests/helper/RemoteFunctionCall.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ class RemoteFunctionCall extends AbstractRemoteFunctionCall
3030
*/
3131
public $returnName = 'cketfemo';
3232

33-
/**
34-
* @var null|\kbATeam\TypeCast\ITypeCast
35-
*/
36-
public $returnTypecast;
37-
3833
/**
3934
* The SAP remote function name.
4035
* @return string
@@ -44,19 +39,11 @@ public function getName()
4439
return $this->returnName;
4540
}
4641

47-
/**
48-
* Get the typecast of the expected return values.
49-
* @return \kbATeam\TypeCast\ITypeCast|null
50-
*/
51-
protected function getReturnTypecast()
52-
{
53-
return $this->returnTypecast;
54-
}
55-
5642
/**
5743
* Create a connection instance using the given config.
5844
* @param \phpsap\interfaces\IConfig $config
5945
* @return \phpsap\interfaces\IConnection
46+
* @throws \phpsap\interfaces\exceptions\IIncompleteConfigException
6047
*/
6148
protected function createConnectionInstance(IConfig $config)
6249
{
@@ -65,10 +52,10 @@ protected function createConnectionInstance(IConfig $config)
6552

6653
/**
6754
* Make protected function public for testing.
68-
* Get the function instance.
69-
* @return \tests\phpsap\classes\helper\RemoteFunction
70-
* @throws \phpsap\interfaces\IConnectionFailedException
71-
* @throws \phpsap\interfaces\IUnknownFunctionException
55+
* Get the function instance
56+
* @return \phpsap\classes\AbstractFunction
57+
* @throws \phpsap\interfaces\exceptions\IConnectionFailedException
58+
* @throws \phpsap\interfaces\exceptions\IUnknownFunctionException
7259
*/
7360
public function getFunction()
7461
{

0 commit comments

Comments
 (0)