Skip to content

Commit

Permalink
Trying to get RPC adapters working in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Sep 29, 2013
1 parent deb611d commit 4c624b0
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 114 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ before_script:
script:
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml --exclude-group Functional,Performance
- ./vendor/bin/phpunit --group=Functional
- sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.4' ]; then echo 'starting PHP server on port 8080'; php -S localhost:8080 -t tests/server/ & fi"
- ./vendor/bin/phpunit ./tests/language-feature-scripts/
- php -n ./vendor/bin/phpunit --group=Performance
- ./vendor/bin/phpcs --standard=PSR2 ./src/ ./tests/
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"phpunit/phpunit": ">=3.7",
"phpmd/phpmd": "1.4.*",
"squizlabs/php_codesniffer": "1.4.*",
"satooshi/php-coveralls": "~0.6"
"satooshi/php-coveralls": "~0.6",
"zendframework/zend-json": "2.*",
"zendframework/zend-xmlrpc": "2.*",
"zendframework/zend-soap": "2.*"
},
"suggest": {
"zendframework/zend-stdlib": "To use the hydrator proxy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function generateMethod(
$list = array();

foreach ($parameters as $parameter) {
$list[] = '$' . $parameter->getName();
$list[] = /*var_export($parameter->getName(), true) . ' => $'*/ '$' . $parameter->getName();
}

$body = 'return $this->' . $adapterName . '->call("' . $className . '"';
Expand Down
35 changes: 35 additions & 0 deletions tests/ProxyManagerTestAsset/RemoteProxy/BazServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ProxyManagerTestAsset\RemoteProxy;

/**
* Simple interface for a remote API
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface BazServiceInterface
{
/**
* @param mixed $param
*
* @return mixed
*/
public function baz($param);
}
52 changes: 52 additions & 0 deletions tests/ProxyManagerTestAsset/RemoteProxy/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ProxyManagerTestAsset\RemoteProxy;

/**
* Simple interface for a remote API
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
class Foo implements FooServiceInterface, BazServiceInterface
{
/**
* {@inheritDoc}
*/
public function foo()
{
return 'bar remote';
}

/**
* {@inheritDoc}
*/
public function baz($param)
{
return $param . ' remote';
}

/**
* {@inheritDoc}
*/
public function __get($name)
{
return $name . ' remote';
}
}
33 changes: 33 additions & 0 deletions tests/ProxyManagerTestAsset/RemoteProxy/FooServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

namespace ProxyManagerTestAsset\RemoteProxy;

/**
* Simple interface for a remote API
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*/
interface FooServiceInterface
{
/**
* @return mixed
*/
public function foo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Foo implements FooServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc(
'http://127.0.0.1/jsonrpc.php' // host to /tests/server/jsonrpc.php
'http://127.0.0.1:8080/jsonrpc.php' // host to /tests/server/jsonrpc.php
);

$proxy = $factory->createProxy('FooServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', $adapter);

var_dump($proxy->foo);
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ interface BazServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc(
'http://127.0.0.1/jsonrpc.php' // host to /tests/server/jsonrpc.php
'http://127.0.0.1:8080/jsonrpc.php' // host to /tests/server/jsonrpc.php
);

$proxy = $factory->createProxy('BazServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\BazServiceInterface', $adapter);

var_dump($proxy->baz('baz'));
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ interface FooServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\JsonRpc(
'http://127.0.0.1/jsonrpc.php' // host to /tests/server/jsonrpc.php
'http://127.0.0.1:8080/jsonrpc.php' // host to /tests/server/jsonrpc.php
);

$proxy = $factory->createProxy('FooServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', $adapter);

var_dump($proxy->foo());
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ interface FooServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\Soap(
'http://127.0.0.1/soap.wsdl' // host to /tests/server/soap.php
'http://127.0.0.1:8080/soap.wsdl' // host to /tests/server/soap.php
);
$adapter->getClient()->setSoapVersion(SOAP_1_1);

$proxy = $factory->createProxy('FooServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', $adapter);

var_dump($proxy->foo());
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ interface BazServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(
'http://127.0.0.1/xmlrpc.php' // host to /tests/server/xmlrpc.php
'http://127.0.0.1:8080/xmlrpc.php' // host to /tests/server/xmlrpc.php
);

$proxy = $factory->createProxy('BazServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\BazServiceInterface', $adapter);

var_dump($proxy->baz('baz'));
?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ interface FooServiceInterface

$factory = new \ProxyManager\Factory\RemoteObjectFactory($configuration);
$adapter = new \ProxyManager\Factory\RemoteObject\Adapter\XmlRpc(
'http://127.0.0.1/xmlrpc.php' // host to /tests/server/xmlrpc.php
'http://127.0.0.1:8080/xmlrpc.php' // host to /tests/server/xmlrpc.php
);

$proxy = $factory->createProxy('FooServiceInterface', $adapter);
$proxy = $factory->createProxy('ProxyManagerTestAsset\RemoteProxy\FooServiceInterface', $adapter);

var_dump($proxy->foo());
?>
Expand Down
45 changes: 10 additions & 35 deletions tests/server/jsonrpc.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
<?php

require __DIR__ . '/../../vendor/autoload.php';

interface FooServiceInterface
{
public function foo();
}

interface BazServiceInterface
{
public function baz($param);
}

class Foo implements FooServiceInterface, BazServiceInterface
{
public function foo()
{
return 'bar remote';
}

public function baz($param)
{
return $param . ' remote';
}

public function __get($name)
{
return $name . ' remote';
}
}
require_once __DIR__ . '/../Bootstrap.php';

$server = new Zend\Json\Server\Server();
$server->setClass('Foo', 'FooServiceInterface'); // my FooServiceInterface implementation
$server->setClass('Foo', 'BazServiceInterface'); // my BazServiceInterface implementation
$server->setClass('ProxyManagerTestAsset\RemoteProxy\Foo', 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface');
$server->setClass('ProxyManagerTestAsset\RemoteProxy\Foo', 'ProxyManagerTestAsset\RemoteProxy\BazServiceInterface');

$callback = new Zend\Server\Method\Callback();
$callback->setType('instance')
->setClass('Foo')
->setMethod('__get');

$callback
->setType('instance')
->setClass('ProxyManagerTestAsset\RemoteProxy\Foo')
->setMethod('__get');

$server->loadFunctions(
array(
new Zend\Server\Method\Definition(
array(
'name' => 'FooServiceInterface.__get',
'name' => 'ProxyManagerTestAsset\RemoteProxy\FooServiceInterface.__get',
'invokeArguments' => array('name'),
'callback' => $callback,
)
)
)
);

$server->handle();
17 changes: 3 additions & 14 deletions tests/server/soap.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
<?php

require __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../Bootstrap.php';

interface FooServiceInterface
{
public function foo();
}
$server = new Zend\Soap\Server(__DIR__ . '/soap.wsdl');

class Foo implements FooServiceInterface
{
public function foo()
{
return 'bar remote';
}
}
$server->setClass('ProxyManagerTestAsset\RemoteProxy\Foo');

$server = new Zend\Soap\Server('soap.wsdl');
$server->setClass('Foo'); // my FooServiceInterface implementation
$server->handle();
32 changes: 15 additions & 17 deletions tests/server/soap.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension"
xmlns="http://schemas.xmlsoap.org/wsdl/">

<message name="foo">
</message>
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<message name="foo"/>

<message name="fooResponse">
<part name="result" type="xsd:string"/>
Expand All @@ -22,23 +21,22 @@
</portType>

<binding name="FooBinding" type="FooPort">
<stk:binding preferredEncoding="UTF-8" />
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="foo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
<stk:binding preferredEncoding="UTF-8" />
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="foo">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>

<service name="FooService">
<port name="FooPort" binding="wsdlns:FooBinding">
<soap:address location="http://127.0.0.1/soap.php"/>
<soap:address location="http://127.0.0.1:8080/soap.php"/>
</port>
</service>
</definitions>
Loading

0 comments on commit 4c624b0

Please sign in to comment.