Completed
Push — master ( e8793f...9ffb77 )
by Piotr
06:43
created

shouldHandleMethodUppercaseUserName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 3
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 Clients;
25
26
use Fixtures\WsdlProvider;
27
use Ouzo\Tests\Assert;
28
use PHPUnit_Framework_TestCase;
29
use SoapClient;
30
use SoapHeader;
31
use stdClass;
32
33
/**
34
 * SoapRpcClientTest
35
 *
36
 * @author Piotr Olaszewski <[email protected]>
37
 */
38
class SoapRpcClientTest extends PHPUnit_Framework_TestCase
39
{
40
    /**
41
     * @var SoapClient
42
     */
43
    private $soapClient;
44
45
    protected function setUp()
46
    {
47
        parent::setUp();
48
        $this->markTestSkipped('Integration tests');
49
        $this->soapClient = new SoapClient(WsdlProvider::rpcLiteral(), [
50
            'cache_wsdl' => WSDL_CACHE_NONE,
51
            'trace' => true
52
        ]);
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function shouldHandleMethodUppercaseUserName()
59
    {
60
        //when
61
        $uppercasedName = $this->soapClient->uppercaseUserName('Piotr');
62
63
        //then
64
        $this->assertEquals('PIOTR', $uppercasedName);
65
    }
66
67
    /**
68
     * @test
69
     */
70 View Code Duplication
    public function shouldHandleMethodAppendPrefixToNumbers()
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...
71
    {
72
        //given
73
        $numbers = [1, 2, 3];
74
75
        //when
76
        $numbersWithPrefix = $this->soapClient->appendPrefixToNumbers($numbers, 'PREF - ');
77
78
        //then
79
        Assert::thatArray($numbersWithPrefix)->containsExactly('PREF - 1', 'PREF - 2', 'PREF - 3');
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function shouldHandleMethodGetUserContext()
86
    {
87
        //given
88
        $user = new stdClass();
89
        $user->name = 'Piotr';
90
        $user->age = '27';
91
92
        //when
93
        $userContext = $this->soapClient->getUserContext($user);
94
95
        //then
96
        $this->assertNotEmpty($userContext->id);
97
        $this->assertEquals('Piotr', $userContext->userInfo->name);
98
        $this->assertEquals(27, $userContext->userInfo->age);
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function shouldHandleMethodExtractCompaniesNames()
105
    {
106
        //given
107
        $companies = [];
108
        $companies[0] = new stdClass();
109
        $companies[0]->name = 'Company 1';
110
        $companies[0]->postcode = '11-111';
111
        $companies[1] = new stdClass();
112
        $companies[1]->name = 'Company 2';
113
        $companies[1]->postcode = '22-222';
114
115
        //when
116
        $companiesNames = $this->soapClient->extractCompaniesNames($companies);
117
118
        //then
119
        Assert::thatArray($companiesNames)->containsExactly('Company 1', 'Company 2');
120
    }
121
122
    /**
123
     * @test
124
     */
125 View Code Duplication
    public function shouldHandleMethodWrapErrors()
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...
126
    {
127
        //given
128
        $errors = ['error 1', 'error 2', 'error 3'];
129
130
        //when
131
        $result = $this->soapClient->wrapErrors($errors);
132
133
        //then
134
        $this->assertFalse($result->result);
135
        Assert::thatArray($result->errors)->containsExactly('error 1', 'error 2', 'error 3');
136
    }
137
138
    /**
139
     * @test
140
     */
141
    public function shouldHandleMethodAuthorizedMethod()
142
    {
143
        //given
144
        $data = new stdClass();
145
        $data->token = 'test_token';
146
        $data->id = '31242';
147
        $this->soapClient->__setSoapHeaders(new SoapHeader('http://foo.bar/rpcliteralservice', 'ServiceAuth', $data));
148
149
        //when
150
        $nameWithSurname = $this->soapClient->authorizedMethod('Piotr', 'Olaszewski');
151
152
        //then
153
        $this->assertEquals('clientId [31242] name [Piotr] surname [Olaszewski]', $nameWithSurname);
154
    }
155
}
156