Completed
Push — master ( 67dda6...fa8d3b )
by Владислав
02:02
created

DeCaptchaAbstractTest::testGetActionUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A DeCaptchaAbstractTest::testGetFilePath() 0 13 1
1
<?php
2
3
/**
4
 * Class DeCaptchaAbstractTest.
5
 */
6
class DeCaptchaAbstractTest extends PHPUnit_Framework_TestCase
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * @return PHPUnit_Framework_MockObject_MockObject|\jumper423\decaptcha\core\DeCaptchaAbstract
10
     */
11
    public function newInstance()
12
    {
13
        $abstract = $this->getMockForAbstractClass(\jumper423\decaptcha\core\DeCaptchaAbstract::class);
14
        $abstract->setErrorLang(\jumper423\decaptcha\core\DeCaptchaErrors::LANG_RU);
15
16
        return $abstract;
17
    }
18
19
    public function testGetBaseUrl()
20
    {
21
        $abstract = $this->newInstance();
22
        $getBaseUrlCaller = function () {
23
            $this->domain = 'domain';
0 ignored issues
show
Bug introduced by
The property domain does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
24
            return $this->getBaseUrl();
1 ignored issue
show
Bug introduced by
The method getBaseUrl() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetBaseUrl()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
25
        };
26
        $bound = $getBaseUrlCaller->bindTo($abstract, $abstract);
27
        $this->assertEquals('http://domain/', $bound());
28
    }
29
30
//    public function testGetActionUrl()
1 ignored issue
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
//    {
32
//        $abstract = $this->newInstance();
33
//        $getBaseUrlGetCodeCaller = function () {
34
//            $this->captchaId = 123;
35
//
36
//            return $this->getActionUrl('get_code');
37
//        };
38
//        $getBaseUrlGetBalanceCaller = function ($action, $key, $id) {
39
//            $this->domain = 'domain';
40
//            $this->setParamSpec(\jumper423\decaptcha\core\DeCaptchaAbstract::PARAM_SPEC_KEY, $key);
41
//            $this->setParamSpec(\jumper423\decaptcha\core\DeCaptchaAbstract::PARAM_SPEC_CAPTCHA, $id);
42
//            return $this->getActionUrl('get_balance');
43
//        };
44
//        $abstract->setParamSpec(\jumper423\decaptcha\core\DeCaptchaAbstract::PARAM_SPEC_KEY '123456');
45
//        $bound = $getBaseUrlGetCodeCaller->bindTo($abstract, $abstract);
46
//        $this->assertEquals('http://domain/res.php?key=123456&action=get_code&id=123', $bound());
47
//        $bound = $getBaseUrlGetBalanceCaller->bindTo($abstract, $abstract);
48
//        $this->assertEquals('http://domain/res.php?key=123456&action=get_balance&id=234', $bound());
49
//    }
50
51
    public function testGetFilePath()
52
    {
53
        $abstract = $this->newInstance();
54
        $getFilePathCaller = function ($val) {
55
            return $this->getFilePath($val);
1 ignored issue
show
Bug introduced by
The method getFilePath() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetFilePath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
56
        };
57
        $bound = $getFilePathCaller->bindTo($abstract, $abstract);
58
        $this->assertEquals(__DIR__.'/data/Captcha.jpg', $bound(__DIR__.'/data/Captcha.jpg'));
59
        $filePathUpload = $bound('https://upload.wikimedia.org/wikipedia/commons/6/69/Captcha.jpg');
60
        $file1 = file_get_contents(__DIR__.'/data/Captcha.jpg');
61
        $file2 = file_get_contents($filePathUpload);
62
        $this->assertEquals($file1, $file2);
63
    }
64
65
    /**
66
     * @expectedException \jumper423\decaptcha\core\DeCaptchaErrors
67
     * @expectedExceptionCode 16
68
     */
69 View Code Duplication
    public function testGetFilePathErrorFileNotFound()
1 ignored issue
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...
70
    {
71
        $abstract = $this->newInstance();
72
        $getFilePathCaller = function ($val) {
73
            return $this->getFilePath($val);
1 ignored issue
show
Bug introduced by
The method getFilePath() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetFilePath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
74
        };
75
        $bound = $getFilePathCaller->bindTo($abstract, $abstract);
76
        $bound(__DIR__.'/data/Captcha1.jpg');
77
    }
78
79
    /**
80
     * @expectedException \jumper423\decaptcha\core\DeCaptchaErrors
81
     * @expectedExceptionMessage Файл не загрузился: https://upload.wikimedia.org/wikipedia/commons/6/69/Captcha46.jpg123
82
     * @expectedExceptionCode 15
83
     */
84 View Code Duplication
    public function testGetFilePathErrorFileIsNotLoaded()
1 ignored issue
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...
85
    {
86
        $abstract = $this->newInstance();
87
        $getFilePathCaller = function ($val) {
88
            return $this->getFilePath($val);
1 ignored issue
show
Bug introduced by
The method getFilePath() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetFilePath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
89
        };
90
        $bound = $getFilePathCaller->bindTo($abstract, $abstract);
91
        $bound('https://upload.wikimedia.org/wikipedia/commons/6/69/Captcha46.jpg123');
92
    }
93
94
//    public function testGetResponse()
1 ignored issue
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
//    {
96
//        $abstract = $this->newInstance();
97
//        $getResponseCaller = function ($val) {
98
//            $this->domain = 'echo.jsontest.com/aaa/bbb';
99
//            return $this->getResponse($val);
100
//        };
101
//        $bound = $getResponseCaller->bindTo($abstract, $abstract);
102
//        $res = $bound('');
103
//        $this->assertEquals('{"res.php":"","aaa":"bbb"}', str_replace("\n", '', str_replace(' ', '', $res)));
104
//    }
105
106
//    public function testExecutionDelayed()
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
//    {
108
//        $abstract = $this->newInstance();
109
//        $executionDelayedCaller = function ($second, $call = null) {
110
//            return $this->executionDelayed($second, $call);
111
//        };
112
//        $bound = $executionDelayedCaller->bindTo($abstract, $abstract);
113
//        $start = microtime(true);
114
//        $bound(0);
115
//        $bound(0.1);
116
//        $timePassed = microtime(true) - $start;
117
//        $this->assertTrue(abs($timePassed - 0.1) < 0.035);
118
//
119
//        $start = microtime(true);
120
//        $bound(0.15, function () {
121
//            sleep(0.2);
122
//        });
123
//        $bound(0.1);
124
//        $timePassed = microtime(true) - $start;
125
//        $this->assertTrue(abs($timePassed - 0.25) < 0.035);
126
//
127
//        $start = microtime(true);
128
//        $bound(0.15, function () {
129
//            sleep(0.2);
130
//        });
131
//        $bound(0.3);
132
//        $timePassed = microtime(true) - $start;
133
//        $this->assertTrue(abs($timePassed - 0.45) < 0.035);
134
//
135
//        $this->assertEquals(2, $bound(0, function () {
136
//            return 2;
137
//        }));
138
//        $this->assertEquals(null, $bound(0));
139
//    }
140
141
//    public function testGetInUrl()
1 ignored issue
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
142
//    {
143
//        $abstract = $this->newInstance();
144
//        $getInUrlCaller = function () {
145
//            $this->domain = 'domain';
146
//            return $this->getInUrl();
147
//        };
148
//        $abstract->setApiKey('123456');
149
//        $bound = $getInUrlCaller->bindTo($abstract, $abstract);
150
//        $this->assertEquals('http://domain/in.php', $bound());
151
//    }
152
153
    /**
154
     * @expectedException \jumper423\decaptcha\core\DeCaptchaErrors
155
     * @expectedExceptionCode 4
156
     */
157
    public function testIsError()
158
    {
159
        $abstract = $this->newInstance();
160
        $isErrorCaller = function ($val) {
161
            return $this->isError($val);
0 ignored issues
show
Bug introduced by
The method isError() does not exist on DeCaptchaAbstractTest. Did you maybe mean testIsError()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
162
        };
163
        $bound = $isErrorCaller->bindTo($abstract, $abstract);
164
        $bound('ERROR_IP_NOT_ALLOWED');
165
    }
166
167
    public function testIsErrorNot()
168
    {
169
        $abstract = $this->newInstance();
170
        $isErrorCaller = function ($val) {
171
            return $this->isError($val);
0 ignored issues
show
Bug introduced by
The method isError() does not exist on DeCaptchaAbstractTest. Did you maybe mean testIsError()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
172
        };
173
        $bound = $isErrorCaller->bindTo($abstract, $abstract);
174
        $this->assertNull($bound('BALANCE:56'));
175
    }
176
177
    /**
178
     * @expectedException \jumper423\decaptcha\core\DeCaptchaErrors
179
     * @expectedExceptionCode 17
180
     * @expectedExceptionMessage Ошибка CURL: Could
181
     */
182
    public function testGetCurlResponseError()
183
    {
184
        $abstract = $this->newInstance();
185
        $getCurlResponseCaller = function ($url, $val) {
186
            return $this->getCurlResponse($url, $val);
0 ignored issues
show
Bug introduced by
The method getCurlResponse() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetCurlResponseError()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
187
        };
188
        $bound = $getCurlResponseCaller->bindTo($abstract, $abstract);
189
        $bound('http://domain', ['protected' => 'value']);
190
    }
191
192
    public function testGetCurlResponse()
193
    {
194
        $abstract = $this->newInstance();
195
        $getCurlResponseCaller = function ($url, $val) {
196
            return $this->getCurlResponse($url, $val);
0 ignored issues
show
Bug introduced by
The method getCurlResponse() does not exist on DeCaptchaAbstractTest. Did you maybe mean testGetCurlResponseError()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
197
        };
198
        $bound = $getCurlResponseCaller->bindTo($abstract, $abstract);
199
        $data = $bound('http://httpbin.org/post', ['protected' => 'value']);
200
        $data = json_decode($data, true);
201
        $this->assertEquals(['protected' => 'value'], $data['form']);
202
    }
203
}
204