shouldCreateBuilderForWebServiceAnnotation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) 2013-2020
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\Builder;
25
26
use Fixtures\ServiceAllAnnotations;
27
use Fixtures\ServiceClassNameAnnotations;
28
use Fixtures\ServiceWebMethods;
29
use Fixtures\ServiceWithoutWebServiceAnnotation;
30
use Ouzo\Tests\Assert;
31
use Ouzo\Tests\CatchException;
32
use PHPUnit\Framework\TestCase;
33
use WSDL\Annotation\BindingType;
34
use WSDL\Annotation\SoapBinding;
35
use WSDL\Builder\AnnotationWSDLBuilder;
36
37
/**
38
 * AnnotationWSDLBuilderTest
39
 *
40
 * @author Piotr Olaszewski <[email protected]>
41
 */
42
class AnnotationWSDLBuilderTest extends TestCase
43
{
44
    /**
45
     * @test
46
     */
47
    public function shouldCreateBuilderForWebServiceAnnotation()
48
    {
49
        //given
50
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceAllAnnotations::class);
51
52
        //when
53
        $annotationWSDLBuilder->build();
54
55
        //then
56
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
57
        $this->assertEquals('WebServiceAnnotations', $WSDLBuilder->getName());
58
        $this->assertEquals('http://foo.bar/webserviceannotations', $WSDLBuilder->getTargetNamespace());
59
        $this->assertEquals('http://foo.bar/webserviceannotations/types', $WSDLBuilder->getNs());
60
        $this->assertEquals('http://localhost/wsdl-creator/service.php', $WSDLBuilder->getLocation());
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function shouldCreateBuilderForBindingTypeAnnotation()
67
    {
68
        //given
69
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceAllAnnotations::class);
70
71
        //when
72
        $annotationWSDLBuilder->build();
73
74
        //then
75
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
76
        $this->assertEquals(BindingType::SOAP_12, $WSDLBuilder->getSoapVersion());
77
    }
78
79
    /**
80
     * @test
81
     */
82
    public function shouldCreateBuilderForSoapBindingAnnotation()
83
    {
84
        //given
85
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceAllAnnotations::class);
86
87
        //when
88
        $annotationWSDLBuilder->build();
89
90
        //then
91
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
92
        $this->assertEquals(SoapBinding::DOCUMENT, $WSDLBuilder->getStyle());
93
        $this->assertEquals(SoapBinding::ENCODED, $WSDLBuilder->getUse());
94
        $this->assertEquals(SoapBinding::WRAPPED, $WSDLBuilder->getParameterStyle());
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function shouldCreateBuilderWithClassNameWhenNameIsNotPass()
101
    {
102
        //given
103
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceClassNameAnnotations::class);
104
105
        //when
106
        $annotationWSDLBuilder->build();
107
108
        //then
109
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
110
        $this->assertEquals('ServiceClassNameAnnotations', $WSDLBuilder->getName());
111
    }
112
113
    /**
114
     * @test
115
     */
116 View Code Duplication
    public function shouldCreateBuilderWithMethods()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        //given
119
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceAllAnnotations::class);
120
121
        //when
122
        $annotationWSDLBuilder->build();
123
124
        //then
125
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
126
        Assert::thatArray($WSDLBuilder->getMethods())
127
            ->extracting('name')
128
            ->containsOnly('uppercaseUserName', 'appendPrefixToNumbers', 'getUserContext');
129
    }
130
131
    /**
132
     * @test
133
     */
134
    public function shouldThrowExceptionWhenWebServiceAnnotationIsNotSet()
135
    {
136
        //given
137
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceWithoutWebServiceAnnotation::class);
138
139
        //when
140
        CatchException::when($annotationWSDLBuilder)->build();
141
142
        //then
143
        CatchException::assertThat()
144
            ->isInstanceOf('\WSDL\Builder\AnnotationBuilderException')
145
            ->hasMessage('Class must have @WebService annotation');
146
    }
147
148
    /**
149
     * @test
150
     */
151 View Code Duplication
    public function shouldCreateBuilderWithWebMethodsOnly()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        //given
154
        $annotationWSDLBuilder = new AnnotationWSDLBuilder(ServiceWebMethods::class);
155
156
        //when
157
        $annotationWSDLBuilder->build();
158
159
        //then
160
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
161
        Assert::thatArray($WSDLBuilder->getMethods())
162
            ->extracting('name')
163
            ->containsOnly('uppercaseUserName', 'methodWithoutParameters', 'emptyResult');
164
    }
165
166
    /**
167
     * @test
168
     */
169
    public function shouldThrowExceptionWhenClassNotExists()
170
    {
171
        //given
172
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Non\Exists\Class');
173
174
        //when
175
        CatchException::when($annotationWSDLBuilder)->build();
176
177
        //then
178
        CatchException::assertThat()->hasMessage('Class [\Non\Exists\Class] not exists');
179
    }
180
}
181