1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SomeWork\Minjust\Tests\Unit\Entity; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use ReflectionClass; |
7
|
|
|
use ReflectionObject; |
8
|
|
|
use SomeWork\Minjust\Entity\DetailLawyer; |
9
|
|
|
use SomeWork\Minjust\Entity\LawFormation; |
10
|
|
|
use SomeWork\Minjust\Entity\Lawyer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @coversDefaultClass \SomeWork\Minjust\Entity\DetailLawyer |
14
|
|
|
* @covers \SomeWork\Minjust\Entity\DetailLawyer |
15
|
|
|
*/ |
16
|
|
|
class DetailLawyerTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testEmpty(): DetailLawyer |
19
|
|
|
{ |
20
|
|
|
$lawyer = new DetailLawyer(); |
21
|
|
|
$this->assertIsString($this->getPropertyValue($lawyer, 'chamberOfLaw')); |
22
|
|
|
$this->assertNull($this->getPropertyValue($lawyer, 'lawFormation')); |
23
|
|
|
|
24
|
|
|
return $lawyer; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function getPropertyValue(object $object, string $property) |
28
|
|
|
{ |
29
|
|
|
$ref = new ReflectionObject($object); |
30
|
|
|
$property = $ref->getProperty($property); |
31
|
|
|
$property->setAccessible(true); |
32
|
|
|
|
33
|
|
|
return $property->getValue($object); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @depends testEmpty |
38
|
|
|
* |
39
|
|
|
* @param \SomeWork\Minjust\Entity\DetailLawyer $lawyer |
40
|
|
|
* |
41
|
|
|
* @return \SomeWork\Minjust\Entity\DetailLawyer |
42
|
|
|
*/ |
43
|
|
|
public function testSet(DetailLawyer $lawyer): DetailLawyer |
44
|
|
|
{ |
45
|
|
|
$lawFormation = (new LawFormation())->setName('testLawFormation'); |
46
|
|
|
|
47
|
|
|
$lawyer |
48
|
|
|
->setChamberOfLaw('testChamberOfLaw') |
49
|
|
|
->setLawFormation($lawFormation); |
50
|
|
|
|
51
|
|
|
$this->assertEquals('testChamberOfLaw', $this->getPropertyValue($lawyer, 'chamberOfLaw')); |
52
|
|
|
$this->assertEquals($lawFormation, $this->getPropertyValue($lawyer, 'lawFormation')); |
53
|
|
|
|
54
|
|
|
return $lawyer; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @depends testSet |
59
|
|
|
* |
60
|
|
|
* @param \SomeWork\Minjust\Entity\DetailLawyer $lawyer |
61
|
|
|
*/ |
62
|
|
|
public function testGet(DetailLawyer $lawyer): void |
63
|
|
|
{ |
64
|
|
|
$lawFormation = $this->getPropertyValue($lawyer, 'lawFormation'); |
65
|
|
|
|
66
|
|
|
$this->assertEquals('testChamberOfLaw', $lawyer->getChamberOfLaw()); |
67
|
|
|
$this->assertEquals($lawFormation, $lawyer->getLawFormation()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testLoadFromLawyer(): void |
71
|
|
|
{ |
72
|
|
|
$lawyer = (new Lawyer()) |
73
|
|
|
->setUrl('testUrl') |
74
|
|
|
->setFullName('testFullName') |
75
|
|
|
->setStatus('testStatus') |
76
|
|
|
->setRegisterNumber('testRegisterNumber') |
77
|
|
|
->setCertificateNumber('testCertificateNumber') |
78
|
|
|
->setTerritorialSubject('testTerritorialSubject'); |
79
|
|
|
|
80
|
|
|
$detailLawyer = (new DetailLawyer())->loadFromLawyer($lawyer); |
81
|
|
|
|
82
|
|
|
$this->assertEquals($lawyer->getUrl(), $detailLawyer->getUrl()); |
83
|
|
|
$this->assertEquals($lawyer->getFullName(), $detailLawyer->getFullName()); |
84
|
|
|
$this->assertEquals($lawyer->getStatus(), $detailLawyer->getStatus()); |
85
|
|
|
$this->assertEquals($lawyer->getRegisterNumber(), $detailLawyer->getRegisterNumber()); |
86
|
|
|
$this->assertEquals($lawyer->getCertificateNumber(), $detailLawyer->getCertificateNumber()); |
87
|
|
|
$this->assertEquals($lawyer->getTerritorialSubject(), $detailLawyer->getTerritorialSubject()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @covers ::__construct |
92
|
|
|
*/ |
93
|
|
|
public function testConstruct(): void |
94
|
|
|
{ |
95
|
|
|
$lawyer = (new Lawyer()) |
96
|
|
|
->setUrl('testUrl') |
97
|
|
|
->setFullName('testFullName') |
98
|
|
|
->setStatus('testStatus') |
99
|
|
|
->setRegisterNumber('testRegisterNumber') |
100
|
|
|
->setCertificateNumber('testCertificateNumber') |
101
|
|
|
->setTerritorialSubject('testTerritorialSubject'); |
102
|
|
|
|
103
|
|
|
$detailLawyer = $this->createPartialMock(DetailLawyer::class, ['loadFromLawyer']); |
104
|
|
|
|
105
|
|
|
$detailLawyer |
106
|
|
|
->expects($this->once()) |
107
|
|
|
->method('loadFromLawyer') |
108
|
|
|
->with($lawyer) |
109
|
|
|
->willReturn($detailLawyer); |
110
|
|
|
|
111
|
|
|
$reflectedClass = new ReflectionClass(DetailLawyer::class); |
112
|
|
|
$constructor = $reflectedClass->getConstructor(); |
113
|
|
|
$constructor->invoke($detailLawyer, $lawyer); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|