1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SomeWork\Minjust\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use DivineOmega\Psr18GuzzleAdapter\Client as GuzzleClient; |
6
|
|
|
use Http\Factory\Guzzle\RequestFactory; |
7
|
|
|
use Http\Factory\Guzzle\StreamFactory; |
8
|
|
|
use Iterator; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Psr\Http\Client\ClientExceptionInterface; |
11
|
|
|
use Psr\Http\Client\ClientInterface; |
12
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
13
|
|
|
use Psr\Http\Message\StreamFactoryInterface; |
14
|
|
|
use ReflectionClass; |
15
|
|
|
use SomeWork\Minjust\Client; |
16
|
|
|
use SomeWork\Minjust\FindRequest; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @coversDefaultClass \SomeWork\Minjust\Client |
20
|
|
|
*/ |
21
|
|
|
class ClientTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @covers ::__construct |
25
|
|
|
* @throws \ReflectionException |
26
|
|
|
*/ |
27
|
|
|
public function testConstruct(): void |
28
|
|
|
{ |
29
|
|
|
$httpClient = $this->createMock(ClientInterface::class); |
30
|
|
|
$requestFactory = $this->createMock(RequestFactoryInterface::class); |
31
|
|
|
$streamFactory = $this->createMock(StreamFactoryInterface::class); |
32
|
|
|
|
33
|
|
|
$client = new Client($httpClient, $requestFactory, $streamFactory); |
34
|
|
|
|
35
|
|
|
$ref = new ReflectionClass(Client::class); |
36
|
|
|
$clientProperty = $ref->getProperty('client'); |
37
|
|
|
$requestFactoryProperty = $ref->getProperty('requestFactory'); |
38
|
|
|
$streamFactoryProperty = $ref->getProperty('streamFactory'); |
39
|
|
|
|
40
|
|
|
$clientProperty->setAccessible(true); |
41
|
|
|
$requestFactoryProperty->setAccessible(true); |
42
|
|
|
$streamFactoryProperty->setAccessible(true); |
43
|
|
|
|
44
|
|
|
$this->assertEquals($httpClient, $clientProperty->getValue($client)); |
45
|
|
|
$this->assertEquals($requestFactory, $requestFactoryProperty->getValue($client)); |
46
|
|
|
$this->assertEquals($streamFactory, $streamFactoryProperty->getValue($client)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers ::list |
51
|
|
|
* @dataProvider listProvider |
52
|
|
|
* |
53
|
|
|
* @param array $formData |
54
|
|
|
* @param string $search |
55
|
|
|
* |
56
|
|
|
* @throws ClientExceptionInterface |
57
|
|
|
*/ |
58
|
|
|
public function testList(array $formData, string $search): void |
59
|
|
|
{ |
60
|
|
|
$client = new Client( |
61
|
|
|
new GuzzleClient(), |
62
|
|
|
new RequestFactory(), |
63
|
|
|
new StreamFactory() |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$body = $client->list($formData); |
67
|
|
|
$this->assertStringContainsString($search, $body); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function listProvider(): Iterator |
71
|
|
|
{ |
72
|
|
|
yield 'empty' => [ |
73
|
|
|
'formData' => [], |
74
|
|
|
'search' => '01/102', |
75
|
|
|
]; |
76
|
|
|
yield 'Михайлов' => [ |
77
|
|
|
'formData' => [ |
78
|
|
|
FindRequest::FULL_NAME => 'михайлов олег николаевич', |
79
|
|
|
], |
80
|
|
|
'search' => '77/2340', |
81
|
|
|
]; |
82
|
|
|
yield 'Белоусова Надежда Сергеевна' => [ |
83
|
|
|
'formData' => [ |
84
|
|
|
FindRequest::OFFSET => 20, |
85
|
|
|
FindRequest::FULL_NAME => 'б', |
86
|
|
|
FindRequest::STATUS => 4, |
87
|
|
|
], |
88
|
|
|
'search' => '03/2165', |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @covers ::detail |
94
|
|
|
* @dataProvider detailProvider |
95
|
|
|
* |
96
|
|
|
* @param string $url |
97
|
|
|
* @param string $search |
98
|
|
|
* |
99
|
|
|
* @throws ClientExceptionInterface |
100
|
|
|
*/ |
101
|
|
|
public function testDetail(string $url, string $search): void |
102
|
|
|
{ |
103
|
|
|
$client = new Client( |
104
|
|
|
new GuzzleClient(), |
105
|
|
|
new RequestFactory(), |
106
|
|
|
new StreamFactory() |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$body = $client->detail($url); |
110
|
|
|
$this->assertStringContainsString($search, $body); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function detailProvider(): Iterator |
114
|
|
|
{ |
115
|
|
|
yield 'Михайлов' => [ |
116
|
|
|
'url' => '/lawyers/show/1610663', |
117
|
|
|
'search' => 'Адвокатская палата г. Москвы', |
118
|
|
|
]; |
119
|
|
|
yield 'Белоусова Надежда Сергеевна' => [ |
120
|
|
|
'url' => '/lawyers/show/1625881', |
121
|
|
|
'search' => 'г. Уфа, ул. К.Маркса, 3б', |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|