Completed
Push — master ( 9d147a...2c76b2 )
by Piotr
10:39
created

XMLProviderTest::shouldGenerateCorrectXML()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 57
rs 9.6818
cc 1
eloc 41
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Copyright (C) 2013-2016
4
 * Piotr Olaszewski <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
namespace Tests\WSDL\XML;
25
26
use Ouzo\Utilities\Path;
27
use PHPUnit_Framework_TestCase;
28
use WSDL\Annotation\BindingType;
29
use WSDL\Annotation\SoapBinding;
30
use WSDL\Builder\Method;
31
use WSDL\Builder\Parameter;
32
use WSDL\Builder\WSDLBuilder;
33
use WSDL\Lexer\Tokenizer;
34
use WSDL\XML\XMLProvider;
35
36
/**
37
 * XMLProviderTest
38
 *
39
 * @author Piotr Olaszewski <[email protected]>
40
 */
41
class XMLProviderTest extends PHPUnit_Framework_TestCase
42
{
43
    /**
44
     * @test
45
     */
46
    public function shouldGenerateCorrectXML()
47
    {
48
        //given
49
        $tokenizer = new Tokenizer();
50
        $parameters1 = [Parameter::fromTokens($tokenizer->lex('string $userName'))];
51
        $return1 = Parameter::fromTokens($tokenizer->lex('string $uppercasedUserName'));
52
53
        $parameters2 = [
54
            Parameter::fromTokens($tokenizer->lex('int[] $numbers')),
55
            Parameter::fromTokens($tokenizer->lex('string $prefix'))
56
        ];
57
        $return2 = Parameter::fromTokens($tokenizer->lex('string[] $numbersWithPrefix'));
58
59
        $parameters3 = [Parameter::fromTokens($tokenizer->lex('object $user { string $name int $age }'))];
60
        $return3 = Parameter::fromTokens($tokenizer->lex('object $userContext { int $id object $userInfo { string $name int $age } }'));
61
62
        $parameters4 = [Parameter::fromTokens($tokenizer->lex('object[] $companies { string $name int $postcode }'))];
63
        $return4 = Parameter::fromTokens($tokenizer->lex('string[] $companiesNames'));
64
65
        $parameters5 = [Parameter::fromTokens($tokenizer->lex('string[] $errors'))];
66
        $return5 = Parameter::fromTokens($tokenizer->lex('object $result { boolean $result string[] $errors }'));
67
68
        $parameters6 = [
69
            Parameter::fromTokens($tokenizer->lex('object $serviceAuth { string $token int $id }'), true),
70
            Parameter::fromTokens($tokenizer->lex('string $name')),
71
            Parameter::fromTokens($tokenizer->lex('string $surname'))
72
        ];
73
        $return6 = Parameter::fromTokens($tokenizer->lex('string $nameWithSurname'));
74
75
        $parameters7 = [Parameter::fromTokens($tokenizer->lex('string $userToken'))];
76
77
        $return8 = Parameter::fromTokens($tokenizer->lex('string $responseForMethodWithoutParameters'));
78
        $builder = WSDLBuilder::instance()
79
            ->setName('RpcLiteralService')
80
            ->setTargetNamespace('http://foo.bar/rpcliteralservice')
81
            ->setNs('http://foo.bar/rpcliteralservice/types')
82
            ->setLocation('http://localhost:7777/wsdl-creator/examples/rpc_literal/service.php')
83
            ->setStyle(SoapBinding::RPC)
84
            ->setUse(SoapBinding::LITERAL)
85
            ->setSoapVersion(BindingType::SOAP_11)
86
            ->setMethod(new Method('uppercaseUserName', $parameters1, $return1))
87
            ->setMethod(new Method('appendPrefixToNumbers', $parameters2, $return2))
88
            ->setMethod(new Method('getUserContext', $parameters3, $return3))
89
            ->setMethod(new Method('extractCompaniesNames', $parameters4, $return4))
90
            ->setMethod(new Method('wrapErrors', $parameters5, $return5))
91
            ->setMethod(new Method('authorizedMethod', $parameters6, $return6))
92
            ->setMethod(new Method('methodWithoutReturn', $parameters7, null))
93
            ->setMethod(new Method('methodWithoutParameters', [], $return8));
94
        $XMLProvider = new XMLProvider($builder);
95
        $XMLProvider->generate();
96
97
        //when
98
        $xml = $XMLProvider->getXml();
99
100
        //then
101
        $this->assertXmlStringEqualsXmlFile(Path::join(__DIR__, 'xml_file_asserts', 'correct_xml.wsdl'), $xml);
102
    }
103
}
104