|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PROCERGS\LoginCidadao\NfgBundle\Tests\EventListener; |
|
12
|
|
|
|
|
13
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
14
|
|
|
use libphonenumber\PhoneNumber; |
|
15
|
|
|
use LoginCidadao\CoreBundle\Entity\Person; |
|
16
|
|
|
use LoginCidadao\CoreBundle\Model\PersonInterface; |
|
17
|
|
|
use PROCERGS\LoginCidadao\CoreBundle\Entity\PersonMeuRS; |
|
18
|
|
|
use PROCERGS\LoginCidadao\NfgBundle\Entity\NfgProfile; |
|
19
|
|
|
use PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent; |
|
20
|
|
|
use PROCERGS\LoginCidadao\NfgBundle\EventListener\NfgSubscriber; |
|
21
|
|
|
use PROCERGS\LoginCidadao\NfgBundle\NfgEvents; |
|
22
|
|
|
use Psr\Log\LoggerInterface; |
|
23
|
|
|
|
|
24
|
|
|
class NfgSubscriberTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testGetSubscribedEvents() |
|
27
|
|
|
{ |
|
28
|
|
|
$events = NfgSubscriber::getSubscribedEvents(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertCount(1, $events); |
|
31
|
|
|
$this->assertEquals([ |
|
32
|
|
|
NfgEvents::CONNECT_CALLBACK_RESPONSE => 'onConnectCallbackResponse', |
|
33
|
|
|
], $events); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testOnConnectCallbackResponseNoPersonOrNfgProfile() |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */ |
|
39
|
|
|
$em = $this->getMock('Doctrine\ORM\EntityManagerInterface'); |
|
40
|
|
|
$em->expects($this->never())->method('persist'); |
|
|
|
|
|
|
41
|
|
|
$em->expects($this->never())->method('flush'); |
|
42
|
|
|
|
|
43
|
|
|
/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */ |
|
44
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
|
45
|
|
|
$logger->expects($this->never())->method('notice'); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$personMeuRS = new PersonMeuRS(); |
|
48
|
|
|
|
|
49
|
|
|
/** @var GetConnectCallbackResponseEvent|\PHPUnit_Framework_MockObject_MockObject $event */ |
|
50
|
|
|
$event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent') |
|
51
|
|
|
->disableOriginalConstructor()->getMock(); |
|
52
|
|
|
$event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$subscriber = new NfgSubscriber($em); |
|
55
|
|
|
$subscriber->setLogger($logger); |
|
56
|
|
|
|
|
57
|
|
|
$subscriber->onConnectCallbackResponse($event); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testOnConnectCallbackResponseDoNothing() |
|
61
|
|
|
{ |
|
62
|
|
|
/** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */ |
|
63
|
|
|
$em = $this->getMock('Doctrine\ORM\EntityManagerInterface'); |
|
64
|
|
|
$em->expects($this->never())->method('persist'); |
|
|
|
|
|
|
65
|
|
|
$em->expects($this->never())->method('flush'); |
|
66
|
|
|
|
|
67
|
|
|
/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */ |
|
68
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
|
69
|
|
|
$logger->expects($this->never())->method('notice'); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$person = new Person(); |
|
72
|
|
|
$person->setBirthdate(new \DateTime()); |
|
73
|
|
|
$person->setMobile(new PhoneNumber()); |
|
74
|
|
|
|
|
75
|
|
|
$personMeuRS = new PersonMeuRS(); |
|
76
|
|
|
$personMeuRS->setPerson($person); |
|
77
|
|
|
|
|
78
|
|
|
/** @var GetConnectCallbackResponseEvent|\PHPUnit_Framework_MockObject_MockObject $event */ |
|
79
|
|
|
$event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent') |
|
80
|
|
|
->disableOriginalConstructor()->getMock(); |
|
81
|
|
|
$event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
$subscriber = new NfgSubscriber($em); |
|
84
|
|
|
$subscriber->setLogger($logger); |
|
85
|
|
|
|
|
86
|
|
|
$subscriber->onConnectCallbackResponse($event); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testOnConnectCallbackResponseUpdate() |
|
90
|
|
|
{ |
|
91
|
|
|
$personInterface = 'LoginCidadao\CoreBundle\Model\PersonInterface'; |
|
92
|
|
|
/** @var EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject $em */ |
|
93
|
|
|
$em = $this->getMock('Doctrine\ORM\EntityManagerInterface'); |
|
94
|
|
|
$em->expects($this->once())->method('persist') |
|
|
|
|
|
|
95
|
|
|
->with($this->isInstanceOf($personInterface)); |
|
96
|
|
|
$em->expects($this->once())->method('flush'); |
|
97
|
|
|
|
|
98
|
|
|
/** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $logger */ |
|
99
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
|
100
|
|
|
$logger->expects($this->exactly(2))->method('notice'); |
|
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
$phoneNumber = new PhoneNumber(); |
|
103
|
|
|
|
|
104
|
|
|
/** @var PersonInterface|\PHPUnit_Framework_MockObject_MockObject $person */ |
|
105
|
|
|
$person = $this->getMock($personInterface); |
|
106
|
|
|
$person->expects($this->once())->method('setBirthdate'); |
|
|
|
|
|
|
107
|
|
|
$person->expects($this->once())->method('setMobile')->with($phoneNumber); |
|
108
|
|
|
|
|
109
|
|
|
$nfgProfile = new NfgProfile(); |
|
110
|
|
|
$nfgProfile->setMobile($phoneNumber); |
|
111
|
|
|
$nfgProfile->setBirthdate(new \DateTime()); |
|
112
|
|
|
|
|
113
|
|
|
$personMeuRS = new PersonMeuRS(); |
|
114
|
|
|
$personMeuRS->setPerson($person); |
|
115
|
|
|
$personMeuRS->setNfgProfile($nfgProfile); |
|
116
|
|
|
|
|
117
|
|
|
$event = $this->getMockBuilder('PROCERGS\LoginCidadao\NfgBundle\Event\GetConnectCallbackResponseEvent') |
|
118
|
|
|
->disableOriginalConstructor()->getMock(); |
|
119
|
|
|
$event->expects($this->exactly(2))->method('getPersonMeuRS')->willReturn($personMeuRS); |
|
120
|
|
|
|
|
121
|
|
|
$subscriber = new NfgSubscriber($em); |
|
122
|
|
|
$subscriber->setLogger($logger); |
|
123
|
|
|
|
|
124
|
|
|
$subscriber->onConnectCallbackResponse($event); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: