1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Happyr\ApiClient\Test; |
4
|
|
|
|
5
|
|
|
use Happyr\ApiClient\HttpClientConfigurator; |
6
|
|
|
use Http\Client\Common\Plugin\HeaderAppendPlugin; |
7
|
|
|
use Nyholm\NSA; |
8
|
|
|
|
9
|
|
|
final class HttpClientConfiguratorTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
View Code Duplication |
public function testAppendPlugin() |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$hcc = new HttpClientConfigurator(); |
14
|
|
|
$plugin0 = new HeaderAppendPlugin(['plugin0']); |
15
|
|
|
|
16
|
|
|
$hcc->appendPlugin($plugin0); |
17
|
|
|
$plugins = NSA::getProperty($hcc, 'appendPlugins'); |
18
|
|
|
$this->assertCount(1, $plugins); |
19
|
|
|
$this->assertEquals($plugin0, $plugins[0]); |
20
|
|
|
|
21
|
|
|
$plugin1 = new HeaderAppendPlugin(['plugin1']); |
22
|
|
|
$hcc->appendPlugin($plugin1); |
23
|
|
|
$plugins = NSA::getProperty($hcc, 'appendPlugins'); |
24
|
|
|
$this->assertCount(2, $plugins); |
25
|
|
|
$this->assertEquals($plugin1, $plugins[1]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testAppendPluginMultiple() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$hcc = new HttpClientConfigurator(); |
31
|
|
|
$plugin0 = new HeaderAppendPlugin(['plugin0']); |
32
|
|
|
$plugin1 = new HeaderAppendPlugin(['plugin1']); |
33
|
|
|
|
34
|
|
|
$hcc->appendPlugin($plugin0, $plugin1); |
35
|
|
|
$plugins = NSA::getProperty($hcc, 'appendPlugins'); |
36
|
|
|
$this->assertCount(2, $plugins); |
37
|
|
|
$this->assertEquals($plugin0, $plugins[0]); |
38
|
|
|
$this->assertEquals($plugin1, $plugins[1]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testPrependPlugin() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$hcc = new HttpClientConfigurator(); |
44
|
|
|
$plugin0 = new HeaderAppendPlugin(['plugin0']); |
45
|
|
|
|
46
|
|
|
$hcc->prependPlugin($plugin0); |
47
|
|
|
$plugins = NSA::getProperty($hcc, 'prependPlugins'); |
48
|
|
|
$this->assertCount(1, $plugins); |
49
|
|
|
$this->assertEquals($plugin0, $plugins[0]); |
50
|
|
|
|
51
|
|
|
$plugin1 = new HeaderAppendPlugin(['plugin1']); |
52
|
|
|
$hcc->prependPlugin($plugin1); |
53
|
|
|
$plugins = NSA::getProperty($hcc, 'prependPlugins'); |
54
|
|
|
$this->assertCount(2, $plugins); |
55
|
|
|
$this->assertEquals($plugin1, $plugins[0]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testPrependPluginMultiple() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$hcc = new HttpClientConfigurator(); |
61
|
|
|
$plugin0 = new HeaderAppendPlugin(['plugin0']); |
62
|
|
|
$plugin1 = new HeaderAppendPlugin(['plugin1']); |
63
|
|
|
|
64
|
|
|
$hcc->prependPlugin($plugin0, $plugin1); |
65
|
|
|
$plugins = NSA::getProperty($hcc, 'prependPlugins'); |
66
|
|
|
$this->assertCount(2, $plugins); |
67
|
|
|
$this->assertEquals($plugin0, $plugins[0]); |
68
|
|
|
$this->assertEquals($plugin1, $plugins[1]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.