Completed
Push — master ( 2488f0...066cec )
by Piotr
03:30
created

shouldThrowExceptionWhenWebServiceAnnotationIsNotSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
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\Builder;
25
26
use Ouzo\Tests\Assert;
27
use Ouzo\Tests\CatchException;
28
use PHPUnit_Framework_TestCase;
29
use WSDL\Annotation\BindingType;
30
use WSDL\Annotation\SoapBinding;
31
use WSDL\Builder\AnnotationWSDLBuilder;
32
33
/**
34
 * AnnotationWSDLBuilderTest
35
 *
36
 * @author Piotr Olaszewski <[email protected]>
37
 */
38
class AnnotationWSDLBuilderTest extends PHPUnit_Framework_TestCase
39
{
40
    /**
41
     * @test
42
     */
43
    public function shouldCreateBuilderForWebServiceAnnotation()
44
    {
45
        //given
46
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceAllAnnotations');
47
48
        //when
49
        $annotationWSDLBuilder->build();
50
51
        //then
52
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
53
        $this->assertEquals('WebServiceAnnotations', $WSDLBuilder->getName());
54
        $this->assertEquals('http://foo.bar/webserviceannotations', $WSDLBuilder->getTargetNamespace());
55
        $this->assertEquals('http://foo.bar/webserviceannotations/types', $WSDLBuilder->getNs());
56
        $this->assertEquals('http://localhost/wsdl-creator/service.php', $WSDLBuilder->getLocation());
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function shouldCreateBuilderForBindingTypeAnnotation()
63
    {
64
        //given
65
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceAllAnnotations');
66
67
        //when
68
        $annotationWSDLBuilder->build();
69
70
        //then
71
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
72
        $this->assertEquals(BindingType::SOAP_12, $WSDLBuilder->getSoapVersion());
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function shouldCreateBuilderForSoapBindingAnnotation()
79
    {
80
        //given
81
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceAllAnnotations');
82
83
        //when
84
        $annotationWSDLBuilder->build();
85
86
        //then
87
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
88
        $this->assertEquals(SoapBinding::DOCUMENT, $WSDLBuilder->getStyle());
89
        $this->assertEquals(SoapBinding::ENCODED, $WSDLBuilder->getUse());
90
        $this->assertEquals(SoapBinding::WRAPPED, $WSDLBuilder->getParameterStyle());
91
    }
92
93
    /**
94
     * @test
95
     */
96
    public function shouldCreateBuilderWithClassNameWhenNameIsNotPass()
97
    {
98
        //given
99
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceClassNameAnnotations');
100
101
        //when
102
        $annotationWSDLBuilder->build();
103
104
        //then
105
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
106
        $this->assertEquals('ServiceClassNameAnnotations', $WSDLBuilder->getName());
107
    }
108
109
    /**
110
     * @test
111
     */
112 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...
113
    {
114
        //given
115
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceAllAnnotations');
116
117
        //when
118
        $annotationWSDLBuilder->build();
119
120
        //then
121
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
122
        Assert::thatArray($WSDLBuilder->getMethods())
123
            ->extracting('name')
124
            ->containsOnly('uppercaseUserName', 'appendPrefixToNumbers', 'getUserContext');
125
    }
126
127
    /**
128
     * @test
129
     */
130
    public function shouldThrowExceptionWhenWebServiceAnnotationIsNotSet()
131
    {
132
        //given
133
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceWithoutWebServiceAnnotation');
134
135
        //when
136
        CatchException::when($annotationWSDLBuilder)->build();
137
138
        //then
139
        CatchException::assertThat()
140
            ->isInstanceOf('\WSDL\Builder\AnnotationBuilderException')
141
            ->hasMessage('Class must have @WebService annotation');
142
    }
143
144
    /**
145
     * @test
146
     */
147 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...
148
    {
149
        //given
150
        $annotationWSDLBuilder = new AnnotationWSDLBuilder('\Fixtures\ServiceWebMethods');
151
152
        //when
153
        $annotationWSDLBuilder->build();
154
155
        //then
156
        $WSDLBuilder = $annotationWSDLBuilder->getBuilder();
157
        Assert::thatArray($WSDLBuilder->getMethods())
158
            ->extracting('name')
159
            ->containsOnly('uppercaseUserName', 'methodWithoutParameters', 'methodWithoutResult');
160
    }
161
}
162