-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathProxyTest.php
131 lines (110 loc) · 4.03 KB
/
ProxyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Upward\Test\Resolver;
use Laminas\Http\Client;
use Laminas\Http\Response;
use Magento\Upward\Definition;
use Magento\Upward\DefinitionIterator;
use Magento\Upward\Resolver\Proxy;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\TestCase;
use function BeBat\Verify\verify;
/**
* @runTestsInSeparateProcesses
*/
class ProxyTest extends TestCase
{
use MockeryPHPUnitIntegration;
/**
* @var DefinitionIterator|Mockery\MockInterface
*/
private $definitionIteratorMock;
/**
* @var Proxy
*/
private $resolver;
protected function setUp(): void
{
$this->resolver = new Proxy();
$this->definitionIteratorMock = Mockery::mock(DefinitionIterator::class);
$this->resolver->setIterator($this->definitionIteratorMock);
}
public function isValidDataProvider()
{
return [
'Valid' => [
'definition' => new Definition([
'target' => 'https://google.com',
]),
'expected' => true,
],
'Invalid - No Target' => [
'definition' => new Definition([]),
'expected' => false,
],
'Invalid - Wrong ignoreSSLErrors Type' => [
'definition' => new Definition([
'target' => 'https://google.com',
'ignoreSSLErrors' => [
'inline' => 'yes please',
],
]),
'expected' => false,
],
];
}
public function testIndicator(): void
{
verify($this->resolver->getIndicator())->is()->sameAs('target');
}
/**
* @dataProvider isValidDataProvider
*/
public function testIsValid(Definition $definition, bool $expected): void
{
$this->definitionIteratorMock->shouldReceive('get')
->with('ignoreSSLErrors', $definition)
->andReturn($definition->get('ignoreSSLErrors'));
verify($this->resolver->isValid($definition))->is()->sameAs($expected);
}
public function testResolve(): void
{
$definition = new Definition(['target' => 'https://google.com', 'ignoreSSLErrors' => true]);
$this->definitionIteratorMock->shouldReceive('get')
->with('target', $definition)
->andReturn('https://google.com');
$this->definitionIteratorMock->shouldReceive('get')
->with('ignoreSSLErrors', $definition)
->andReturn(true);
$responseMock = Mockery::mock(Response::class);
$zendClientMock = Mockery::mock('overload:' . Client::class);
$zendClientMock->shouldReceive('send')->andReturn($responseMock);
$resolverResponse = $this->resolver->resolve($definition);
verify($resolverResponse)->is()->sameAs($responseMock);
}
public function testResolveThrowsException(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('$definition must be an instance of Magento\\Upward\\Definition');
$this->resolver->resolve('Not a Definition');
}
public function testResolveValidateSSL(): void
{
$definition = new Definition(['target' => 'https://google.com']);
$this->definitionIteratorMock->shouldReceive('get')
->with('target', $definition)
->andReturn('https://google.com');
$this->definitionIteratorMock->shouldNotReceive('get')
->with('ignoreSSLErrors', $definition);
$responseMock = Mockery::mock(Response::class);
$zendClientMock = Mockery::mock('overload:' . Client::class);
$zendClientMock->shouldReceive('send')->andReturn($responseMock);
$resolverResponse = $this->resolver->resolve($definition);
verify($resolverResponse)->is()->sameAs($responseMock);
}
}