1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SomeWork\Minjust\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use Iterator; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use SomeWork\Minjust\Entity\LawFormation; |
8
|
|
|
use SomeWork\Minjust\Entity\Lawyer; |
9
|
|
|
use SomeWork\Minjust\Parser\ParserInterface; |
10
|
|
|
|
11
|
|
|
abstract class AbstractParserTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var \SomeWork\Minjust\Parser\ParserInterface |
15
|
|
|
*/ |
16
|
|
|
protected static $parser; |
17
|
|
|
|
18
|
|
|
public static function setUpBeforeClass(): void |
19
|
|
|
{ |
20
|
|
|
static::$parser = static::getNewParser(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
abstract public static function getNewParser(): ParserInterface; |
24
|
|
|
|
25
|
|
|
public static function tearDownAfterClass(): void |
26
|
|
|
{ |
27
|
|
|
static::$parser = null; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @dataProvider listProvider |
32
|
|
|
* |
33
|
|
|
* @param string $resource |
34
|
|
|
* @param int $page |
35
|
|
|
* @param int $totalPages |
36
|
|
|
* @param int $count |
37
|
|
|
*/ |
38
|
|
|
public function testList(string $resource, int $page, int $totalPages, int $count): void |
39
|
|
|
{ |
40
|
|
|
$body = file_get_contents($resource); |
41
|
|
|
$response = static::$parser->list($body); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($page, $response->getPage()); |
44
|
|
|
$this->assertEquals($totalPages, $response->getTotalPage()); |
45
|
|
|
$this->assertCount($count, $response->getLawyers()); |
46
|
|
|
$this->assertContainsOnlyInstancesOf(Lawyer::class, $response->getLawyers()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @dataProvider detailProvider |
51
|
|
|
* |
52
|
|
|
* @param string $resource |
53
|
|
|
* @param string $chamberOfLaw |
54
|
|
|
* @param LawFormation|null $lawFormation |
55
|
|
|
*/ |
56
|
|
|
public function testDetail(string $resource, string $chamberOfLaw, ?LawFormation $lawFormation): void |
57
|
|
|
{ |
58
|
|
|
$body = file_get_contents($resource); |
59
|
|
|
$lawyer = static::$parser->detail($body); |
60
|
|
|
|
61
|
|
|
$this->assertIsString($lawyer->getChamberOfLaw()); |
62
|
|
|
$this->assertEquals($chamberOfLaw, $lawyer->getChamberOfLaw()); |
63
|
|
|
|
64
|
|
|
if (null === $lawFormation) { |
65
|
|
|
$this->assertNull($lawyer->getLawFormation()); |
66
|
|
|
} else { |
67
|
|
|
$this->assertIsString($lawyer->getLawFormation()->getPhone()); |
68
|
|
|
$this->assertIsString($lawyer->getLawFormation()->getEmail()); |
69
|
|
|
$this->assertIsString($lawyer->getLawFormation()->getName()); |
70
|
|
|
$this->assertIsString($lawyer->getLawFormation()->getOrganizationalForm()); |
71
|
|
|
$this->assertIsString($lawyer->getLawFormation()->getAddress()); |
72
|
|
|
|
73
|
|
|
$this->assertEquals($lawFormation->getPhone(), $lawyer->getLawFormation()->getPhone()); |
74
|
|
|
$this->assertEquals($lawFormation->getEmail(), $lawyer->getLawFormation()->getEmail()); |
75
|
|
|
$this->assertEquals($lawFormation->getName(), $lawyer->getLawFormation()->getName()); |
76
|
|
|
$this->assertEquals( |
77
|
|
|
$lawFormation->getOrganizationalForm(), |
78
|
|
|
$lawyer->getLawFormation()->getOrganizationalForm() |
79
|
|
|
); |
80
|
|
|
$this->assertEquals($lawFormation->getAddress(), $lawyer->getLawFormation()->getAddress()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function listProvider(): Iterator |
85
|
|
|
{ |
86
|
|
|
yield [ |
87
|
|
|
dirname(__DIR__) . '/data/one-page.html', |
88
|
|
|
'page' => 1, |
89
|
|
|
'totalPages' => 1, |
90
|
|
|
'count' => 12, |
91
|
|
|
]; |
92
|
|
|
yield [ |
93
|
|
|
dirname(__DIR__) . '/data/rewind-not-first.html', |
94
|
|
|
'page' => 2, |
95
|
|
|
'totalPages' => 2, |
96
|
|
|
'count' => 8, |
97
|
|
|
]; |
98
|
|
|
yield [ |
99
|
|
|
dirname(__DIR__) . '/data/many-page-not-first.html', |
100
|
|
|
'page' => 6, |
101
|
|
|
'totalPages' => 58, |
102
|
|
|
'count' => 20, |
103
|
|
|
]; |
104
|
|
|
yield [ |
105
|
|
|
dirname(__DIR__) . '/data/many-page.html', |
106
|
|
|
'page' => 1, |
107
|
|
|
'totalPages' => 6657, |
108
|
|
|
'count' => 20, |
109
|
|
|
]; |
110
|
|
|
yield 'web' => [ |
111
|
|
|
'http://lawyers.minjust.ru/Lawyers?regnumber=77/2340', |
112
|
|
|
'page' => 1, |
113
|
|
|
'totalPages' => 1, |
114
|
|
|
'count' => 1, |
115
|
|
|
]; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function detailProvider(): Iterator |
119
|
|
|
{ |
120
|
|
|
yield 'web Михайлов' => [ |
121
|
|
|
'http://lawyers.minjust.ru/lawyers/show/1610663', |
122
|
|
|
'Адвокатская палата г. Москвы', |
123
|
|
|
null, |
124
|
|
|
]; |
125
|
|
|
yield 'web Трофимова' => [ |
126
|
|
|
'http://lawyers.minjust.ru/lawyers/show/1529728', |
127
|
|
|
'Палата адвокатов Республики Алтай', |
128
|
|
|
(new LawFormation()) |
129
|
|
|
->setOrganizationalForm('Коллегии адвокатов') |
130
|
|
|
->setName('Коллегия адвокатов Республики Алтай') |
131
|
|
|
->setAddress('г.Бийск, ул.Л.Толстого, 160, кв.12') |
132
|
|
|
->setPhone('89609626799'), |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|