44
55use GuzzleHttp \Client ;
66use GuzzleHttp \Psr7 \Response ;
7- use Illuminate \Support \Str ;
7+ use Illuminate \Support \Facades \ Event ;
88use Mockery ;
99use Mockery \Adapter \Phpunit \MockeryPHPUnitIntegration ;
10+ use NotificationChannels \Pushwoosh \Events \UnknownDevices ;
1011use NotificationChannels \Pushwoosh \Exceptions \PushwooshException ;
11- use NotificationChannels \Pushwoosh \Exceptions \UnknownDeviceException ;
1212use NotificationChannels \Pushwoosh \Pushwoosh ;
1313use NotificationChannels \Pushwoosh \PushwooshPendingMessage ;
14- use PHPUnit \ Framework \TestCase ;
14+ use NotificationChannels \ Pushwoosh \ Tests \TestCase ;
1515
1616class PushwooshTest extends TestCase
1717{
@@ -32,8 +32,12 @@ class PushwooshTest extends TestCase
3232 */
3333 protected function setUp (): void
3434 {
35- $ this ->client = Mockery::mock (Client::class);
36- $ this ->pushwoosh = new Pushwoosh ($ this ->client , Str::random (8 ), Str::random (24 ));
35+ parent ::setUp ();
36+
37+ Event::fake ();
38+
39+ $ this ->app ->instance (Client::class, $ this ->client = Mockery::mock (Client::class));
40+ $ this ->pushwoosh = $ this ->app ->make (Pushwoosh::class);
3741 }
3842
3943 /**
@@ -84,11 +88,13 @@ public function testUnknownDevices()
8488 new Response (200 , [], file_get_contents (__DIR__ . '/../Fixtures/unknown-devices.json ' ))
8589 );
8690
87- $ this ->expectException (UnknownDeviceException::class);
88- $ this ->expectExceptionMessage ('Unknown device(s) referenced: foo, bar ' );
89-
9091 $ this ->pushwoosh ->createMessage (
9192 new PushwooshPendingMessage ($ this ->pushwoosh )
9293 );
94+
95+ Event::assertDispatched (UnknownDevices::class, function (UnknownDevices $ event ) {
96+ return $ event ->message === 'AF0B-EEFE4D5E-E445B2E9 '
97+ && $ event ->devices === ['foo ' , 'bar ' ];
98+ });
9399 }
94100}
0 commit comments