forked from cyklokoalicia/OpenSourceBikeShare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationsTest.php
More file actions
94 lines (82 loc) · 3.18 KB
/
Copy pathNotificationsTest.php
File metadata and controls
94 lines (82 loc) · 3.18 KB
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
<?php
namespace Tests\Unit;
use BikeShare\Domain\Bike\Bike;
use BikeShare\Domain\Stand\Stand;
use BikeShare\Domain\User\User;
use BikeShare\Http\Services\AppConfig;
use BikeShare\Notifications\Sms\Credit;
use BikeShare\Notifications\Sms\Help;
use BikeShare\Notifications\Sms\NoteForBikeSaved;
use BikeShare\Notifications\Sms\NoteForStandSaved;
use BikeShare\Notifications\Sms\StandInfo;
use BikeShare\Notifications\Sms\TagForStandSaved;
use Tests\TestCase;
/**
* Notification tests that do not require DB migrations are placed here, others are in Feature directory
*/
class NotificationsTest extends TestCase
{
/** @test */
public function help_notification_contains_commands()
{
$appConfig = $this->mockObj(AppConfig::class);
$appConfig->method('isCreditEnabled')->willReturn(true);
$user = $this->mockObj(User::class);
$user->method('hasRole')->willReturn(true);
$text = (new Help($user, $appConfig))->smsText();
// test at least these basic commands
foreach (['CREDIT', 'RENT', 'RETURN', 'FORCERENT', 'FORCERETURN', 'REVERT'] as $cmd){
self::assertContains($cmd, $text);
}
}
/** @test */
public function credit_notification_contains_user_credit()
{
$appConfig = $this->mockObj(AppConfig::class);
$appConfig->method('getCreditCurrency')->willReturn('$');
$user = factory(User::class)->make([]);
$notification = new Credit($appConfig, $user);
self::assertContains((string) $user->credit, $notification->smsText());
}
/** @test */
public function info_notification_contains_stand_name_description_and_possibly_gps()
{
$stand = make(Stand::class);
$notifText = (new StandInfo($stand))->smsText();
self::assertContains($stand->name, $notifText);
self::assertContains($stand->description, $notifText);
self::assertContains('GPS', $notifText);
$standNoGps = make(Stand::class, ['name'=>'XYZ', 'description' => 'desc', 'longitude' => null, 'latitude' => null]);
$notifText2 = (new StandInfo($standNoGps))->smsText();
self::assertContains($standNoGps->name, $notifText2);
self::assertContains($standNoGps->description, $notifText2);
self::assertNotContains('GPS', $notifText2);
}
/** @test */
public function note_notification_to_bike_contains_bike_number()
{
$bike = make(Bike::class);
$text = (new NoteForBikeSaved($bike))->smsText();
self::assertContains((string) $bike->bike_num, $text);
}
/** @test */
public function note_notification_to_stand_contains_stand_name()
{
$stand = make(Stand::class);
$text = (new NoteForStandSaved($stand))->smsText();
self::assertContains((string) $stand->name, $text);
}
/** @test */
public function tag_notification_contains_stand_name()
{
$stand = make(Stand::class);
$text = (new TagForStandSaved($stand))->smsText();
self::assertContains((string) $stand->name, $text);
}
private function mockObj($className)
{
return $this->getMockBuilder($className)
->disableOriginalConstructor()
->getMock();
}
}