Skip to content

Commit ac389c4

Browse files
Add doctrine channel tests
1 parent d66a9b1 commit ac389c4

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"mockery/mockery": "~0.9",
3434
"barryvdh/laravel-debugbar": "~2.0",
3535
"itsgoingd/clockwork": "~1.9",
36-
"illuminate/log": "5.2.*"
36+
"illuminate/log": "5.2.*|5.3.*",
37+
"illuminate/notifications": "5.3.*",
38+
"illuminate/queue": "5.3.*"
3739
},
3840
"autoload": {
3941
"psr-4": {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
use Doctrine\Common\Persistence\ManagerRegistry;
4+
use Doctrine\ORM\EntityManagerInterface;
5+
use LaravelDoctrine\ORM\Exceptions\NoEntityManagerFound;
6+
use LaravelDoctrine\ORM\Notifications\DoctrineChannel;
7+
use LaravelDoctrine\ORM\Notifications\Notifiable;
8+
use Mockery\Mock;
9+
10+
class DoctrineChannelTest extends PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var DoctrineChannel
14+
*/
15+
private $channel;
16+
17+
/**
18+
* @var Mock
19+
*/
20+
private $registry;
21+
22+
/**
23+
* @var Mock
24+
*/
25+
private $em;
26+
27+
public function setUp()
28+
{
29+
$this->em = Mockery::spy(EntityManagerInterface::class);
30+
31+
$this->channel = new DoctrineChannel(
32+
$this->registry = Mockery::mock(ManagerRegistry::class)
33+
);
34+
}
35+
36+
public function test_can_send_notification_on_default_em()
37+
{
38+
$this->registry->shouldReceive('getManagerForClass')
39+
->with('LaravelDoctrine\ORM\Notifications\Notification')
40+
->andReturn($this->em);
41+
42+
$this->channel->send(new NotifiableStub, new NotificationStub);
43+
44+
$this->em->shouldHaveReceived('persist')->once();
45+
$this->em->shouldHaveReceived('flush')->once();
46+
}
47+
48+
public function test_can_send_notification_on_custom_em()
49+
{
50+
$this->registry->shouldReceive('getManager')
51+
->with('custom')
52+
->andReturn($this->em);
53+
54+
$this->channel->send(new CustomNotifiableStub, new NotificationStub);
55+
56+
$this->em->shouldHaveReceived('persist')->once();
57+
$this->em->shouldHaveReceived('flush')->once();
58+
}
59+
60+
public function test_it_should_throw_exception_when_it_does_not_find_an_em()
61+
{
62+
$this->setExpectedException(NoEntityManagerFound::class);
63+
64+
$this->registry->shouldReceive('getManager')
65+
->with('custom')
66+
->andReturnNull();
67+
68+
$this->channel->send(new CustomNotifiableStub, new NotificationStub);
69+
}
70+
}
71+
72+
class NotificationStub extends \Illuminate\Notifications\Notification
73+
{
74+
public function toEntity()
75+
{
76+
return (new \LaravelDoctrine\ORM\Notifications\Notification);
77+
}
78+
}
79+
80+
class NotifiableStub
81+
{
82+
use Notifiable;
83+
}
84+
85+
class CustomNotifiableStub
86+
{
87+
use Notifiable;
88+
89+
public function routeNotificationForDoctrine()
90+
{
91+
return 'custom';
92+
}
93+
}

0 commit comments

Comments
 (0)