-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotificationListenerTest.php
127 lines (101 loc) · 3.52 KB
/
NotificationListenerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace AlfredNutileInc\DiffTool\Tests;
use AlfredNutileInc\Notifications\Notification;
use AlfredNutileInc\Notifications\NotificationCategory;
use AlfredNutileInc\DiffTool\Notifications\NotificationsListener;
use Illuminate\Support\Facades\Event;
use Mockery as m;
class NotificationListenerTest extends \TestCase {
public function setUp()
{
parent::setUp();
}
/**
* @test
*/
public function should_make_dto_from_event()
{
//Arrange
$listener = new NotificationsListener($this->app);
$message = (object) ['project_id' => 'mock-project-1', 'request_id' => 'mock-request-1', 'stage' => 1] ;
//Act
$listener->filesUploadReadyToCompareNotice($message);
//Assert
$this->assertInstanceOf('AlfredNutileInc\DiffTool\DiffToolDTO', $listener->getDto());
}
/**
* @test
*/
public function should_have_0_for_whom_and_stop()
{
//Arrange
$listener = m::mock('AlfredNutileInc\DiffTool\Notifications\NotificationsListener[setCategory]', [$this->app]);
$message = (object) ['project_id' => 'mock-project-5', 'request_id' => 'mock-request-1', 'stage' => 1] ;
$listener->shouldNotHaveReceived('setCategory');
//Act
$listener->filesUploadReadyToCompareNotice($message);
//Assert
//See shouldNot
}
/**
* @test
*/
public function should_make_category_if_does_not_exist()
{
//Arrange
$this->removeCategory('diff_tool.file_uploads_ready_to_compare');
$before = NotificationCategory::all()->count();
$listener = new NotificationsListener($this->app);
$listener->setEventName('diff_tool.file_uploads_ready_to_compare');
$message = (object) ['project_id' => 'mock-project-1', 'request_id' => 'mock-request-1', 'stage' => 1] ;
//Act
$listener->filesUploadReadyToCompareNotice($message);
//Assert
$after = NotificationCategory::all()->count();
$this->assertGreaterThan($before, $after);
}
/**
* @test
*/
public function should_make_message()
{
//Arrange
$listener = new NotificationsListener($this->app);
$listener->setEventName('diff_tool.file_uploads_ready_to_compare');
$message = (object) ['project_id' => 'mock-project-1', 'request_id' => 'mock-request-1', 'stage' => 1] ;
//Act
$listener->filesUploadReadyToCompareNotice($message);
//Assert
$this->assertNotNull($listener->getMessageId());
$this->assertNotNull($listener->getMessage());
}
/**
* @test
*/
public function should_make_many_notifications()
{
//Arrange
$before = Notification::all()->count();
$listener = new NotificationsListener($this->app);
$listener->setEventName('diff_tool.file_uploads_ready_to_compare');
$message = (object) ['project_id' => 'mock-project-1', 'request_id' => 'mock-request-1', 'stage' => 1] ;
//Act
$listener->filesUploadReadyToCompareNotice($message);
//Assert
$after = Notification::all()->count();
$this->assertGreaterThan($before, $after);
$this->assertEquals(2, count($listener->getNotificationsMade()));
}
public function removeCategory($cat_name)
{
if($results = NotificationCategory::where('name', $cat_name)->first())
{
$results->delete();
}
}
public function tearDown()
{
parent::tearDown();
m::close();
}
}