Author: Piotr Olaszewski (piotroo89@gmail.com)
 /**
  * @test
  */
 public function shouldCreateParameterFromTokensWhenParameterIsHeader()
 {
     //given
     $tokenizer = new Tokenizer();
     //when
     $parameter = Parameter::fromTokens($tokenizer->lex('int[] $numbers'), true);
     //then
     $this->assertTrue($parameter->isHeader());
 }
 /**
  * @return Method[]
  * @throws Exception
  */
 public static function get()
 {
     $tokenizer = new Tokenizer();
     $parameters1 = [Parameter::fromTokens($tokenizer->lex('string $userName'))];
     $return1 = Parameter::fromTokens($tokenizer->lex('string $uppercasedUserName'));
     $parameters2 = [Parameter::fromTokens($tokenizer->lex('int[] $numbers')), Parameter::fromTokens($tokenizer->lex('string $prefix'))];
     $return2 = Parameter::fromTokens($tokenizer->lex('string[] $numbersWithPrefix'));
     $parameters3 = [Parameter::fromTokens($tokenizer->lex('object $user { string $name int $age }'))];
     $return3 = Parameter::fromTokens($tokenizer->lex('object $userContext { int $id object $userInfo { string $name int $age } }'));
     $parameters4 = [Parameter::fromTokens($tokenizer->lex('object[] $companies { string $name int $postcode }'))];
     $return4 = Parameter::fromTokens($tokenizer->lex('string[] $companiesNames'));
     $parameters5 = [Parameter::fromTokens($tokenizer->lex('string[] $errors'))];
     $return5 = Parameter::fromTokens($tokenizer->lex('object $result { boolean $result string[] $errors }'));
     $parameters6 = [Parameter::fromTokens($tokenizer->lex('object $serviceAuth { string $token int $id }'), true), Parameter::fromTokens($tokenizer->lex('string $name')), Parameter::fromTokens($tokenizer->lex('string $surname'))];
     $return6 = Parameter::fromTokens($tokenizer->lex('string $nameWithSurname'));
     $parameters7 = [Parameter::fromTokens($tokenizer->lex('string $userToken'))];
     $return8 = Parameter::fromTokens($tokenizer->lex('string $responseForMethodWithoutParameters'));
     return [new Method('uppercaseUserName', $parameters1, $return1), new Method('appendPrefixToNumbers', $parameters2, $return2), new Method('getUserContext', $parameters3, $return3), new Method('extractCompaniesNames', $parameters4, $return4), new Method('wrapErrors', $parameters5, $return5), new Method('authorizedMethod', $parameters6, $return6), new Method('methodWithoutReturn', $parameters7, null), new Method('methodWithoutParameters', [], $return8)];
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function build(MethodBuilder $builder, ReflectionMethod $method)
 {
     $tokenizer = new Tokenizer();
     $builder->setParameter(Parameter::fromTokens($tokenizer->lex($this->param), $this->header));
 }
Beispiel #4
0
 private function parser($string)
 {
     $tokenizer = new Tokenizer();
     $tokens = $tokenizer->lex($string);
     return new Parser($tokens);
 }
 /**
  * @test
  */
 public function shouldGenerateCorrectXML()
 {
     //given
     $tokenizer = new Tokenizer();
     $parameters1 = [Parameter::fromTokens($tokenizer->lex('string $userName'))];
     $return1 = Parameter::fromTokens($tokenizer->lex('string $uppercasedUserName'));
     $parameters2 = [Parameter::fromTokens($tokenizer->lex('int[] $numbers')), Parameter::fromTokens($tokenizer->lex('string $prefix'))];
     $return2 = Parameter::fromTokens($tokenizer->lex('string[] $numbersWithPrefix'));
     $parameters3 = [Parameter::fromTokens($tokenizer->lex('object $user { string $name int $age }'))];
     $return3 = Parameter::fromTokens($tokenizer->lex('object $userContext { int $id object $userInfo { string $name int $age } }'));
     $parameters4 = [Parameter::fromTokens($tokenizer->lex('object[] $companies { string $name int $postcode }'))];
     $return4 = Parameter::fromTokens($tokenizer->lex('string[] $companiesNames'));
     $parameters5 = [Parameter::fromTokens($tokenizer->lex('string[] $errors'))];
     $return5 = Parameter::fromTokens($tokenizer->lex('object $result { boolean $result string[] $errors }'));
     $parameters6 = [Parameter::fromTokens($tokenizer->lex('object $serviceAuth { string $token int $id }'), true), Parameter::fromTokens($tokenizer->lex('string $name')), Parameter::fromTokens($tokenizer->lex('string $surname'))];
     $return6 = Parameter::fromTokens($tokenizer->lex('string $nameWithSurname'));
     $parameters7 = [Parameter::fromTokens($tokenizer->lex('string $userToken'))];
     $return8 = Parameter::fromTokens($tokenizer->lex('string $responseForMethodWithoutParameters'));
     $builder = WSDLBuilder::instance()->setName('RpcLiteralService')->setTargetNamespace('http://foo.bar/rpcliteralservice')->setNs('http://foo.bar/rpcliteralservice/types')->setLocation('http://localhost:7777/wsdl-creator/examples/rpc_literal/service.php')->setStyle(SoapBinding::RPC)->setUse(SoapBinding::LITERAL)->setSoapVersion(BindingType::SOAP_11)->setMethod(new Method('uppercaseUserName', $parameters1, $return1))->setMethod(new Method('appendPrefixToNumbers', $parameters2, $return2))->setMethod(new Method('getUserContext', $parameters3, $return3))->setMethod(new Method('extractCompaniesNames', $parameters4, $return4))->setMethod(new Method('wrapErrors', $parameters5, $return5))->setMethod(new Method('authorizedMethod', $parameters6, $return6))->setMethod(new Method('methodWithoutReturn', $parameters7, null))->setMethod(new Method('methodWithoutParameters', [], $return8));
     $XMLProvider = new XMLProvider($builder);
     $XMLProvider->generate();
     //when
     $xml = $XMLProvider->getXml();
     //then
     $this->assertXmlStringEqualsXmlFile(Path::join(__DIR__, 'xml_file_asserts', 'correct_xml.wsdl'), $xml);
 }
 /**
  * @test
  */
 public function shouldTokenizeClassWrapperWithoutFirstBackSlash()
 {
     //given
     $param = 'object $name { className Foo\\Bar\\Baz }';
     $tokenizer = new Tokenizer();
     //when
     $tokens = $tokenizer->lex($param);
     //then
     Assert::thatArray($tokens)->extracting('getName()', 'getValue()')->containsExactly([Token::TYPE, Token::NAME, Token::OPEN_OBJECT, Token::TYPE, Token::CLASS_NAME, Token::CLOSE_OBJECT, Token::EOF], ['object', '$name', '{', 'className', 'Foo\\Bar\\Baz', '}', 'eof']);
 }