From a0a92dd1b419f632566f8ab8bb789ff5e4c0ce73 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Tue, 13 Sep 2011 21:34:39 +0200 Subject: [PATCH] Added fixtures files --- .../RpcLiteralRequestMessageBinderTest.php | 2 +- .../RpcLiteralResponseMessageBinderTest.php | 227 ------------------ .../fixtures/ServiceBinding/BarRecursive.php | 13 + .../fixtures/ServiceBinding/FooRecursive.php | 8 + 4 files changed, 22 insertions(+), 228 deletions(-) delete mode 100644 Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php create mode 100644 Tests/fixtures/ServiceBinding/BarRecursive.php create mode 100644 Tests/fixtures/ServiceBinding/FooRecursive.php diff --git a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php index e021e94..c656611 100644 --- a/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php +++ b/Tests/ServiceBinding/RpcLiteralRequestMessageBinderTest.php @@ -136,7 +136,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase $foo = new Fixtures\FooRecursive('foo', ''); $bar = new Fixtures\BarRecursive($foo, 10394); - $foo->setBar($bar); + $foo->bar = $bar; $result = $messageBinder->processMessage( new Definition\Method('prevent_infinite_recursion', null, array(), array( diff --git a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php b/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php deleted file mode 100644 index 9da41e8..0000000 --- a/Tests/ServiceBinding/RpcLiteralResponseMessageBinderTest.php +++ /dev/null @@ -1,227 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace BeSimple\SoapBundle\Tests\ServiceBinding; - -use BeSimple\SoapBundle\ServiceDefinition\Method; -use BeSimple\SoapBundle\ServiceDefinition\Type; -use BeSimple\SoapBundle\ServiceDefinition\Strategy\PropertyComplexType; -use BeSimple\SoapBundle\ServiceDefinition\Strategy\MethodComplexType; -use BeSimple\SoapBundle\ServiceBinding\RpcLiteralResponseMessageBinder; -use BeSimple\SoapBundle\Util\Collection; -use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes; -use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType; -use BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters; - -/** - * UnitTest for \BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder. - * - * @author Francis Besset - */ -class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase -{ - /** - * @dataProvider messageProvider - */ - public function testProcessMessage(Method $method, $message, $assert) - { - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage($method, $message); - - $this->assertSame($assert, $result); - } - - public function testProcessMessageWithComplexType() - { - $definitionComplexTypes = $this->getDefinitionComplexTypes(); - - $attributes = new Attributes(); - $attributes->foo = 'foobar'; - $attributes->bar = 20349; - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage( - new Method('complextype', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')), - $attributes, - $definitionComplexTypes - ); - - $this->assertInstanceOf('stdClass', $result); - $this->assertSame('foobar', $result->foo); - $this->assertSame(20349, $result->bar); - - $attributes1 = new Attributes(); - $attributes1->foo = 'bar'; - $attributes1->bar = 2929; - $attributes2 = new Attributes(); - $attributes2->foo = 'foo'; - $attributes2->bar = 123992; - $message = array($attributes1, $attributes2); - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage( - new Method('complextype_argument', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), - $message, - $definitionComplexTypes - ); - - $this->assertTrue(is_array($result)); - - $this->assertInstanceOf('stdClass', $result[0]); - $this->assertSame('bar', $result[0]->foo); - $this->assertSame(2929, $result[0]->bar); - - $this->assertInstanceOf('stdClass', $result[1]); - $this->assertSame('foo', $result[1]->foo); - $this->assertSame(123992, $result[1]->bar); - } - - public function testProcessMessageWithComplexTypeMethods() - { - $setters = new Setters(); - $setters->setFoo('foobar'); - $setters->setBar(42); - - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage( - new Method('complextype_methods', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')), - $setters, - $this->getDefinitionComplexTypes() - ); - - $this->assertInstanceOf('stdClass', $result); - $this->assertSame('foobar', $result->foo); - $this->assertSame(42, $result->bar); - } - - public function testProcessMessageWithComplexTypeIntoComplexType() - { - $complexType = new ComplexType(); - - $foo = new Attributes(); - $foo->foo = 'Hello world!'; - $foo->bar = 4242; - $complexType->setFoo($foo); - - $bar = new Setters(); - $bar->setFoo('bar foo'); - $bar->setBar(2424); - $complexType->bar = $bar; - - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage( - new Method('complextype_complextype', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')), - $complexType, - $this->getDefinitionComplexTypes() - ); - - $this->assertInstanceOf('stdClass', $result); - - $this->assertInstanceOf('stdClass', $result->foo); - $this->assertSame('Hello world!', $result->foo->foo); - $this->assertSame(4242, $result->foo->bar); - - $this->assertInstanceOf('stdClass', $result->bar); - $this->assertSame('bar foo', $result->bar->foo); - $this->assertSame(2424, $result->bar->bar); - } - - public function testProcessMessageWithComplexTypeReferences() - { - $attributes = new Attributes(); - $attributes->foo = 'bar'; - $attributes->bar = 2929; - - $message = array($attributes, $attributes); - $messageBinder = new RpcLiteralResponseMessageBinder(); - $result = $messageBinder->processMessage( - new Method('complextype_argument', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')), - $message, - $this->getDefinitionComplexTypes() - ); - - $this->assertInstanceOf('stdClass', $result[0]); - $this->assertSame($result[0], $result[1]); - } - - public function messageProvider() - { - $messages = array(); - - $messages[] = array( - new Method('boolean', null, array(), array(), new Type('boolean')), - true, - true, - ); - - $messages[] = array( - new Method('strings', null, array(), array(), new Type('string[]')), - array('hello', 'world'), - array('hello', 'world'), - ); - - return $messages; - } - - private function getDefinitionComplexTypes() - { - $this->definitionComplexTypes = array(); - - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes'] = $this->createPropertiesCollection(array( - array('foo', 'string'), - array('bar', 'int'), - )); - - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'] = $this->createMethodsCollection(array( - array('foo', 'string', 'getFoo', 'setFoo'), - array('bar', 'int', 'getBar', 'setBar'), - )); - - $collection = $this->createMethodsCollection(array( - array('foo', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes', 'getFoo', 'setFoo'), - )); - $this->createPropertiesCollection(array( - array('bar', '\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters'), - ), $collection); - $this->definitionComplexTypes['\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType'] = $collection; - - return $this->definitionComplexTypes; - } - - private function createPropertiesCollection(array $properties, Collection $collection = null) - { - $collection = $collection ?: new Collection('getName'); - - foreach ($properties as $property) { - $collectionProperty = new PropertyComplexType(); - $collectionProperty->setName($property[0]); - $collectionProperty->setValue($property[1]); - - $collection->add($collectionProperty); - } - - return $collection; - } - - private function createMethodsCollection(array $methods, Collection $collection = null) - { - $collection = $collection ?: new Collection('getName'); - - foreach ($methods as $method) { - $collectionMethod = new MethodComplexType(); - $collectionMethod->setName($method[0]); - $collectionMethod->setValue($method[1]); - $collectionMethod->setOriginalName($method[2]); - $collectionMethod->setSetter($method[3]); - - $collection->add($collectionMethod); - } - - return $collection; - } -} diff --git a/Tests/fixtures/ServiceBinding/BarRecursive.php b/Tests/fixtures/ServiceBinding/BarRecursive.php new file mode 100644 index 0000000..c7d3d14 --- /dev/null +++ b/Tests/fixtures/ServiceBinding/BarRecursive.php @@ -0,0 +1,13 @@ +foo = $foo; + } +} \ No newline at end of file diff --git a/Tests/fixtures/ServiceBinding/FooRecursive.php b/Tests/fixtures/ServiceBinding/FooRecursive.php new file mode 100644 index 0000000..b39c9f1 --- /dev/null +++ b/Tests/fixtures/ServiceBinding/FooRecursive.php @@ -0,0 +1,8 @@ +