Completed
Push — master ( 988df8...b0f242 )
by Piotr
03:56
created

shouldThrowExceptionWhenStyleIsInValid()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 3
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 InvalidArgumentException;
27
use PHPUnit_Framework_TestCase;
28
use WSDL\Annotation\BindingType;
29
use WSDL\Annotation\SoapBinding;
30
use WSDL\Builder\IsValid;
31
32
/**
33
 * IsValidTest
34
 *
35
 * @author Piotr Olaszewski <[email protected]>
36
 */
37
class IsValidTest extends PHPUnit_Framework_TestCase
38
{
39
    /**
40
     * @test
41
     * @dataProvider validStyles
42
     * @param string $style
43
     */
44
    public function shouldNotThrowExceptionWhenStyleIsValid($style)
45
    {
46
        //when
47
        IsValid::style($style);
48
49
        //then no exception
50
    }
51
52
    public function validStyles()
53
    {
54
        return [
55
            [SoapBinding::RPC],
56
            [SoapBinding::DOCUMENT]
57
        ];
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function shouldThrowExceptionWhenStyleIsInValid()
64
    {
65
        //when
66
        try {
67
            IsValid::style('INVALID_STYLE');
68
            $this->assertFalse(true, 'Triggered when exception is not throw');
69
        } catch (InvalidArgumentException $e) {//then
70
            $this->assertEquals('Invalid style [INVALID_STYLE] available styles: [RPC, DOCUMENT]', $e->getMessage());
71
            $this->assertInstanceOf('\InvalidArgumentException', $e);
72
        }
73
    }
74
75
    /**
76
     * @test
77
     * @dataProvider validUses
78
     * @param string $use
79
     */
80
    public function shouldNotThrowExceptionWhenUseIsValid($use)
81
    {
82
        //when
83
        IsValid::useStyle($use);
84
85
        //then no exception
86
    }
87
88
    public function validUses()
89
    {
90
        return [
91
            [SoapBinding::LITERAL],
92
            [SoapBinding::ENCODED]
93
        ];
94
    }
95
96
    /**
97
     * @test
98
     */
99
    public function shouldThrowExceptionWhenUseIsInValid()
100
    {
101
        //when
102
        try {
103
            IsValid::useStyle('INVALID_USE');
104
            $this->assertFalse(true, 'Triggered when exception is not throw');
105
        } catch (InvalidArgumentException $e) {//then
106
            $this->assertEquals('Invalid use [INVALID_USE] available uses: [LITERAL, ENCODED]', $e->getMessage());
107
            $this->assertInstanceOf('\InvalidArgumentException', $e);
108
        }
109
    }
110
111
    /**
112
     * @test
113
     * @dataProvider validSoapVersions
114
     * @param string $soapVersion
115
     */
116
    public function shouldNotThrowExceptionWhenSoapVersionIsValid($soapVersion)
117
    {
118
        //when
119
        IsValid::soapVersion($soapVersion);
120
121
        //then no exception
122
    }
123
124
    public function validSoapVersions()
125
    {
126
        return [
127
            [BindingType::SOAP_11],
128
            [BindingType::SOAP_12]
129
        ];
130
    }
131
132
    /**
133
     * @test
134
     */
135
    public function shouldThrowExceptionWhenSoapVersionIsInValid()
136
    {
137
        //when
138
        try {
139
            IsValid::soapVersion('INVALID_SOAP_VERSION');
140
            $this->assertFalse(true, 'Triggered when exception is not throw');
141
        } catch (InvalidArgumentException $e) {//then
142
            $this->assertEquals('Invalid binding type [INVALID_SOAP_VERSION] available types: [SOAP_11, SOAP_12]', $e->getMessage());
143
            $this->assertInstanceOf('\InvalidArgumentException', $e);
144
        }
145
    }
146
147
    /**
148
     * @test
149
     */
150
    public function shouldNotThrowExceptionWhenValueIsNotEmpty()
151
    {
152
        //when
153
        IsValid::notEmpty('some value');
154
155
        //then no exception
156
    }
157
158
    /**
159
     * @test
160
     * @dataProvider emptyValues
161
     * @param mixed $value
162
     */
163 View Code Duplication
    public function shouldThrowExceptionWhenValueIsEmpty($value)
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...
164
    {
165
        //when
166
        try {
167
            IsValid::notEmpty($value);
168
            $this->assertFalse(true, 'Triggered when exception is not throw');
169
        } catch (InvalidArgumentException $e) {//then
170
            $this->assertEquals('Value cannot be empty', $e->getMessage());
171
            $this->assertInstanceOf('\InvalidArgumentException', $e);
172
        }
173
    }
174
175
    /**
176
     * @test
177
     * @dataProvider emptyValues
178
     * @param mixed $value
179
     * @param string $customMessage
180
     */
181 View Code Duplication
    public function shouldThrowExceptionWithCustomMessageWhenValueIsEmpty($value, $customMessage)
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...
182
    {
183
        //when
184
        try {
185
            IsValid::notEmpty($value, $customMessage);
186
            $this->assertFalse(true, 'Triggered when exception is not throw');
187
        } catch (InvalidArgumentException $e) {//then
188
            $this->assertEquals($customMessage, $e->getMessage());
189
            $this->assertInstanceOf('\InvalidArgumentException', $e);
190
        }
191
    }
192
193
    public function emptyValues()
194
    {
195
        return [
196
            ['', 'First empty value'],
197
            [null, 'Second empty value']
198
        ];
199
    }
200
}
201