Notifynder is a Facade Class that has
all the methods necesessary to use the library.
Notifynder allow you to have a flexible notification
management. It will provide you a nice and easy API
to store, retrieve and organise your notifications.
/** @test */ function it_store_extra_field_as_json() { $this->createCategory(['name' => 'custom']); $extra = ['notifynder' => 'amazing']; $notifications = $this->notifynder->category('custom')->extra($extra)->url('w')->from(1)->to(1); $notifications = $this->notifynder->send($notifications); $this->assertEquals(json_encode($extra), $notifications->extra); }
/** @test */ public function it_fire_a_notifynder_event(Dispatcher $dispatcher, NotifynderManager $notifynder) { $key = 'event'; $category = 'hello'; $extraValues = []; $notifyEvent = 'Notifynder.' . $key; $notificationBuilt = [0 => ['notification']]; $notifynderEvent = new NotifynderEvent($notifyEvent, $category, $extraValues); $dispatcher->fire($notifyEvent, [$notifynderEvent, $notifynder])->shouldBeCalled()->willReturn($notificationBuilt); $notifynder->send($notificationBuilt[0])->shouldBeCalled()->willReturn(1); $this->fire($notifynder, $key, $category, $extraValues)->shouldReturn(1); }
/** * It send multiple Notifications * * @method send * @group failing * @test */ function it_send_multiple_notifications() { Factory::times(10)->create(User::class); $this->createCategory(['name' => 'me']); $allUsers = User::all(); $this->notifynder->loop($allUsers, function ($builder, $user) { $builder->category('me')->url('you')->from(1)->to($user->id); })->send(); // should send 10 notifications $notifications = Notification::all(); $this->assertCount(10, $notifications); }
/** * Test send multiple notifications from * the handler. * * @param NotifynderEvent $event * @param NotifynderManager $notifynder * @return $this */ public function userMultiple(NotifynderEvent $event, NotifynderManager $notifynder) { // Retrieve users $users = [1, 2]; return $notifynder->builder()->loop($users, function (NotifynderBuilder $builder, $value, $key) { return $builder->category('activation')->url('hello')->from(1)->to($value); }); }