| @@ 33-208 (lines=176) @@ | ||
| 30 | * |
|
| 31 | * @author Piotr Olaszewski <[email protected]> |
|
| 32 | */ |
|
| 33 | class RpcEncodedTest extends PHPUnit_Framework_TestCase |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * @var RpcEncoded |
|
| 37 | */ |
|
| 38 | private $_rpcEncoded; |
|
| 39 | ||
| 40 | protected function setUp() |
|
| 41 | { |
|
| 42 | parent::setUp(); |
|
| 43 | $this->_rpcEncoded = new RpcEncoded(); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @test |
|
| 48 | */ |
|
| 49 | public function shouldReturnCorrectBindingStyle() |
|
| 50 | { |
|
| 51 | //when |
|
| 52 | $style = $this->_rpcEncoded->bindingStyle(); |
|
| 53 | ||
| 54 | //then |
|
| 55 | $this->assertEquals('rpc', $style); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @test |
|
| 60 | */ |
|
| 61 | public function shouldReturnCorrectBindingUse() |
|
| 62 | { |
|
| 63 | //when |
|
| 64 | $style = $this->_rpcEncoded->bindingUse(); |
|
| 65 | ||
| 66 | //then |
|
| 67 | $this->assertEquals('encoded', $style); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @test |
|
| 72 | */ |
|
| 73 | public function shouldParseArrayWithSimpleType() |
|
| 74 | { |
|
| 75 | //given |
|
| 76 | $method = ParameterFactory::createParameterForSimpleArray(); |
|
| 77 | ||
| 78 | //when |
|
| 79 | $types = $this->_rpcEncoded->typeParameters($method); |
|
| 80 | ||
| 81 | //then |
|
| 82 | $type = $types[0]; |
|
| 83 | $this->assertEquals('ArrayOfNames', $type->getName()); |
|
| 84 | $this->assertEquals('xsd:string[]', $type->getArrayType()); |
|
| 85 | $this->assertNull($type->getComplex()); |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * @test |
|
| 90 | */ |
|
| 91 | public function shouldParseSimpleObject() |
|
| 92 | { |
|
| 93 | //given |
|
| 94 | $parameter = ParameterFactory::createParameterForSimpleObject(); |
|
| 95 | ||
| 96 | //when |
|
| 97 | $types = $this->_rpcEncoded->typeParameters($parameter); |
|
| 98 | ||
| 99 | //then |
|
| 100 | $type = $types[0]; |
|
| 101 | $this->assertEquals('Info', $type->getName()); |
|
| 102 | $this->assertEquals(array( |
|
| 103 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 104 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 105 | ), $type->getElementAttributes()); |
|
| 106 | // $this->assertNull($type->getComplex()); |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * @test |
|
| 111 | */ |
|
| 112 | public function shouldParseObjectWithWrapper() |
|
| 113 | { |
|
| 114 | //given |
|
| 115 | $parameter = ParameterFactory::createParameterForObjectWithWrapper(); |
|
| 116 | ||
| 117 | //when |
|
| 118 | $types = $this->_rpcEncoded->typeParameters($parameter); |
|
| 119 | ||
| 120 | //then |
|
| 121 | $type = $types[0]; |
|
| 122 | $this->assertEquals('AgentNameWithId', $type->getName()); |
|
| 123 | $this->assertEquals(array( |
|
| 124 | array('type' => 'element', 'value' => 'ns:MocksMockUserWrapper', 'name' => 'agent'), |
|
| 125 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 126 | ), $type->getElementAttributes()); |
|
| 127 | Assert::thatArray($type->getComplex())->onMethod('getName')->containsExactly('MocksMockUserWrapper'); |
|
| 128 | Assert::thatArray($type->getComplex())->onMethod('getElementAttributes') |
|
| 129 | ->containsKeyAndValue(array(array( |
|
| 130 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'), |
|
| 131 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 132 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 133 | ))); |
|
| 134 | } |
|
| 135 | ||
| 136 | /** |
|
| 137 | * @test |
|
| 138 | */ |
|
| 139 | public function shouldParseObjectWithArrayOfElement() |
|
| 140 | { |
|
| 141 | //given |
|
| 142 | $parameter = ParameterFactory::createParameterForObjectWithArrayOfSimpleType(); |
|
| 143 | ||
| 144 | //when |
|
| 145 | $types = $this->_rpcEncoded->typeParameters($parameter); |
|
| 146 | ||
| 147 | //then |
|
| 148 | $type = $types[0]; |
|
| 149 | $this->assertEquals('NamesInfo', $type->getName()); |
|
| 150 | $this->assertEquals(array( |
|
| 151 | array('type' => 'type', 'value' => 'ns:ArrayOfNames', 'name' => 'names'), |
|
| 152 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 153 | ), $type->getElementAttributes()); |
|
| 154 | Assert::thatArray($type->getComplex())->onMethod('getName')->containsExactly('ArrayOfNames'); |
|
| 155 | Assert::thatArray($type->getComplex())->onMethod('getArrayType')->containsExactly('xsd:string[]'); |
|
| 156 | } |
|
| 157 | ||
| 158 | /** |
|
| 159 | * @test |
|
| 160 | */ |
|
| 161 | public function shouldParseArrayOfObjects() |
|
| 162 | { |
|
| 163 | //given |
|
| 164 | $parameter = ParameterFactory::createParameterForArrayOfObjects(); |
|
| 165 | ||
| 166 | //when |
|
| 167 | $types = $this->_rpcEncoded->typeParameters($parameter); |
|
| 168 | ||
| 169 | //then |
|
| 170 | $type = $types[0]; |
|
| 171 | $this->assertEquals('ArrayOfCompanies', $type->getName()); |
|
| 172 | $this->assertEquals('ns:Companies[]', $type->getArrayType()); |
|
| 173 | $this->assertEquals('Companies', $type->getComplex()->getName()); |
|
| 174 | $this->assertEquals(array( |
|
| 175 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 176 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 177 | ), $type->getComplex()->getElementAttributes()); |
|
| 178 | } |
|
| 179 | ||
| 180 | /** |
|
| 181 | * @test |
|
| 182 | */ |
|
| 183 | public function shouldParseObjectWithArrayOfWrapper() |
|
| 184 | { |
|
| 185 | //given |
|
| 186 | $parameter = ParameterFactory::createParameterObjectWithArrayOfWrapper(); |
|
| 187 | ||
| 188 | //when |
|
| 189 | $types = $this->_rpcEncoded->typeParameters($parameter); |
|
| 190 | ||
| 191 | //then |
|
| 192 | $type = $types[0]; |
|
| 193 | $this->assertEquals('ListOfAgents', $type->getName()); |
|
| 194 | $this->assertEquals(array( |
|
| 195 | array('type' => 'type', 'value' => 'ns:ArrayOfAgents', 'name' => 'agents'), |
|
| 196 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 197 | ), $type->getElementAttributes()); |
|
| 198 | $actualComplex = $type->getComplex(); |
|
| 199 | Assert::thatArray($actualComplex)->onMethod('getName')->containsExactly('ArrayOfAgents'); |
|
| 200 | Assert::thatArray($actualComplex)->onMethod('getArrayType')->containsExactly('ns:MocksMockUserWrapper[]'); |
|
| 201 | $this->assertEquals('MocksMockUserWrapper', $actualComplex[0]->getComplex()->getName()); |
|
| 202 | $this->assertEquals(array( |
|
| 203 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'), |
|
| 204 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 205 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 206 | ), $actualComplex[0]->getComplex()->getElementAttributes()); |
|
| 207 | } |
|
| 208 | } |
|
| 209 | ||
| @@ 33-209 (lines=177) @@ | ||
| 30 | * |
|
| 31 | * @author Piotr Olaszewski <[email protected]> |
|
| 32 | */ |
|
| 33 | class RpcLiteralTest extends PHPUnit_Framework_TestCase |
|
| 34 | { |
|
| 35 | /** |
|
| 36 | * @var RpcLiteral |
|
| 37 | */ |
|
| 38 | private $_rpcLiteral; |
|
| 39 | ||
| 40 | protected function setUp() |
|
| 41 | { |
|
| 42 | parent::setUp(); |
|
| 43 | $this->_rpcLiteral = new RpcLiteral(); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @test |
|
| 48 | */ |
|
| 49 | public function shouldReturnCorrectBindingStyle() |
|
| 50 | { |
|
| 51 | //when |
|
| 52 | $style = $this->_rpcLiteral->bindingStyle(); |
|
| 53 | ||
| 54 | //then |
|
| 55 | $this->assertEquals('rpc', $style); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @test |
|
| 60 | */ |
|
| 61 | public function shouldReturnCorrectBindingUse() |
|
| 62 | { |
|
| 63 | //when |
|
| 64 | $style = $this->_rpcLiteral->bindingUse(); |
|
| 65 | ||
| 66 | //then |
|
| 67 | $this->assertEquals('literal', $style); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @test |
|
| 72 | */ |
|
| 73 | public function shouldParseArrayWithSimpleType() |
|
| 74 | { |
|
| 75 | //given |
|
| 76 | $parameter = ParameterFactory::createParameterForSimpleArray(); |
|
| 77 | ||
| 78 | //when |
|
| 79 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 80 | ||
| 81 | //then |
|
| 82 | $type = $types[0]; |
|
| 83 | $this->assertEquals('ArrayOfNames', $type->getName()); |
|
| 84 | $this->assertEquals('xsd:string[]', $type->getArrayType()); |
|
| 85 | $this->assertNull($type->getComplex()); |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * @test |
|
| 90 | */ |
|
| 91 | public function shouldParseSimpleObject() |
|
| 92 | { |
|
| 93 | //given |
|
| 94 | $parameter = ParameterFactory::createParameterForSimpleObject(); |
|
| 95 | ||
| 96 | //when |
|
| 97 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 98 | ||
| 99 | //then |
|
| 100 | $type = $types[0]; |
|
| 101 | $this->assertEquals('Info', $type->getName()); |
|
| 102 | $this->assertEquals(array( |
|
| 103 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 104 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 105 | ), $type->getElementAttributes()); |
|
| 106 | // $this->assertNull($type->getComplex()); |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * @test |
|
| 111 | */ |
|
| 112 | public function shouldParseObjectWithWrapper() |
|
| 113 | { |
|
| 114 | //given |
|
| 115 | $parameter = ParameterFactory::createParameterForObjectWithWrapper(); |
|
| 116 | ||
| 117 | //when |
|
| 118 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 119 | ||
| 120 | //then |
|
| 121 | $type = $types[0]; |
|
| 122 | $this->assertEquals('AgentNameWithId', $type->getName()); |
|
| 123 | $this->assertEquals(array( |
|
| 124 | array('type' => 'element', 'value' => 'ns:MocksMockUserWrapper', 'name' => 'agent'), |
|
| 125 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 126 | ), $type->getElementAttributes()); |
|
| 127 | $actualComplex = $type->getComplex(); |
|
| 128 | Assert::thatArray($actualComplex)->onMethod('getName')->containsExactly('MocksMockUserWrapper'); |
|
| 129 | Assert::thatArray($type->getComplex())->onMethod('getElementAttributes') |
|
| 130 | ->containsKeyAndValue(array(array( |
|
| 131 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'), |
|
| 132 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 133 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 134 | ))); |
|
| 135 | } |
|
| 136 | ||
| 137 | /** |
|
| 138 | * @test |
|
| 139 | */ |
|
| 140 | public function shouldParseObjectWithArrayOfElement() |
|
| 141 | { |
|
| 142 | //given |
|
| 143 | $parameter = ParameterFactory::createParameterForObjectWithArrayOfSimpleType(); |
|
| 144 | ||
| 145 | //when |
|
| 146 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 147 | ||
| 148 | //then |
|
| 149 | $type = $types[0]; |
|
| 150 | $this->assertEquals('NamesInfo', $type->getName()); |
|
| 151 | $this->assertEquals(array( |
|
| 152 | array('type' => 'type', 'value' => 'ns:ArrayOfNames', 'name' => 'names'), |
|
| 153 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 154 | ), $type->getElementAttributes()); |
|
| 155 | Assert::thatArray($type->getComplex())->onMethod('getName')->containsExactly('ArrayOfNames'); |
|
| 156 | Assert::thatArray($type->getComplex())->onMethod('getArrayType')->containsExactly('xsd:string[]'); |
|
| 157 | } |
|
| 158 | ||
| 159 | /** |
|
| 160 | * @test |
|
| 161 | */ |
|
| 162 | public function shouldParseArrayOfObjects() |
|
| 163 | { |
|
| 164 | //given |
|
| 165 | $parameter = ParameterFactory::createParameterForArrayOfObjects(); |
|
| 166 | ||
| 167 | //when |
|
| 168 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 169 | ||
| 170 | //then |
|
| 171 | $type = $types[0]; |
|
| 172 | $this->assertEquals('ArrayOfCompanies', $type->getName()); |
|
| 173 | $this->assertEquals('ns:Companies[]', $type->getArrayType()); |
|
| 174 | $this->assertEquals('Companies', $type->getComplex()->getName()); |
|
| 175 | $this->assertEquals(array( |
|
| 176 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 177 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 178 | ), $type->getComplex()->getElementAttributes()); |
|
| 179 | } |
|
| 180 | ||
| 181 | /** |
|
| 182 | * @test |
|
| 183 | */ |
|
| 184 | public function shouldParseObjectWithArrayOfWrapper() |
|
| 185 | { |
|
| 186 | //given |
|
| 187 | $parameter = ParameterFactory::createParameterObjectWithArrayOfWrapper(); |
|
| 188 | ||
| 189 | //when |
|
| 190 | $types = $this->_rpcLiteral->typeParameters($parameter); |
|
| 191 | ||
| 192 | //then |
|
| 193 | $type = $types[0]; |
|
| 194 | $this->assertEquals('ListOfAgents', $type->getName()); |
|
| 195 | $this->assertEquals(array( |
|
| 196 | array('type' => 'type', 'value' => 'ns:ArrayOfAgents', 'name' => 'agents'), |
|
| 197 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id') |
|
| 198 | ), $type->getElementAttributes()); |
|
| 199 | $actualComplex = $type->getComplex(); |
|
| 200 | Assert::thatArray($actualComplex)->onMethod('getName')->containsExactly('ArrayOfAgents'); |
|
| 201 | Assert::thatArray($actualComplex)->onMethod('getArrayType')->containsExactly('ns:MocksMockUserWrapper[]'); |
|
| 202 | $this->assertEquals('MocksMockUserWrapper', $actualComplex[0]->getComplex()->getName()); |
|
| 203 | $this->assertEquals(array( |
|
| 204 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'), |
|
| 205 | array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'), |
|
| 206 | array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age') |
|
| 207 | ), $actualComplex[0]->getComplex()->getElementAttributes()); |
|
| 208 | } |
|
| 209 | } |
|
| 210 | ||