Skip to content

Commit

Permalink
Merge pull request #2 from alhoqbani/analysis-q2JJnl
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
alhoqbani committed Aug 15, 2017
2 parents ca0a4f5 + 3461385 commit c675f1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function mobilyWsRespondedWithAnError($code, $message)
$message
));
}

/**
* Thrown when GuzzleHttp throw a request exception.
*
Expand Down Expand Up @@ -56,14 +56,13 @@ public static function someErrorWhenSendingSms(Response $response)
sprintf('Could not send sms notification to mobily.ws. Status code %s and message: %s', $code, $message)
);
}

/**
* Thrown when any other errors occur.
*
* @param $message
*
* @return static
*
*/
public static function withErrorMessage($message)
{
Expand Down
6 changes: 3 additions & 3 deletions src/MobilyWsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace NotificationChannels\MobilyWs;

use Illuminate\Events\Dispatcher;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Events\NotificationFailed;
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;

class MobilyWsChannel
Expand Down Expand Up @@ -39,7 +39,7 @@ public function __construct(MobilyWsApi $mobilyWs, Dispatcher $events)
*/
public function send($notifiable, Notification $notification)
{
if ( ! method_exists($notification, 'toMobilyWs')) {
if (! method_exists($notification, 'toMobilyWs')) {
throw CouldNotSendNotification::withErrorMessage('MobilyWs notifications must have toMobilyWs method');
}
$number = $notifiable->routeNotificationFor('MobilyWs') ?: $notifiable->phone_number;
Expand All @@ -55,7 +55,7 @@ public function send($notifiable, Notification $notification)
$this->events->fire(
new NotificationFailed($notifiable, $notification, 'mobily-ws', $response)
);

throw CouldNotSendNotification::mobilyWsRespondedWithAnError($response['code'], $response['message']);
}
}
1 change: 1 addition & 0 deletions src/MobilyWsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function boot()
if (is_null($mobilyWsConfig)) {
throw CouldNotSendNotification::withErrorMessage('Config file was not found. Please publish the config file');
}

return new MobilyWsApi(
new MobilyWsConfig($mobilyWsConfig),
new Client(
Expand Down
21 changes: 10 additions & 11 deletions tests/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\Notification;
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;
use NotificationChannels\MobilyWs\MobilyWsApi;
use NotificationChannels\MobilyWs\MobilyWsChannel;
use Illuminate\Notifications\Events\NotificationFailed;
use NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;

/**
* @property \Mockery\MockInterface api
Expand Down Expand Up @@ -54,7 +53,7 @@ public function it_can_send_a_notification()
$response = $this->channel->send($this->notifiable, $this->notification);
$this->assertEquals('تمت عملية الإرسال بنجاح', $response);
}

/** @test
* @expectedException \NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification;
*/
Expand All @@ -66,13 +65,13 @@ public function it_fires_failure_event_on_failure()
];
$this->api->shouldReceive('send')->with($params)->andReturn(['code' => 5, 'message' => 'كلمة المرور الخاصة بالحساب غير صحيحة']);

try{
try {
$this->channel->send($this->notifiable, $this->notification);
} catch (CouldNotSendNotification $e) {
$this->events->shouldHaveReceived('fire');
}
}

/** @test */
public function it_throw_an_exception_when_mobily_ws_return_an_error()
{
Expand All @@ -81,31 +80,31 @@ public function it_throw_an_exception_when_mobily_ws_return_an_error()
'numbers' => '966550000000',
];
$this->api->shouldReceive('send')->with($params)->andReturn(['code' => 3, 'message' => 'رصيدك غير كافي لإتمام عملية الإرسال']);

try {
$this->channel->send($this->notifiable, $this->notification);
} catch (CouldNotSendNotification $e) {
$this->assertContains('رصيدك غير كافي لإتمام عملية الإرسال', $e->getMessage());

return;
}

$this->fail('CouldNotSendNotification exception was not raised');
}

/** @test */
public function it_throw_an_exception_when_toMobilyWs_method_does_not_exist()
{
try {
$this->channel->send($this->notifiable, new Notification());
} catch (CouldNotSendNotification $e) {
$this->assertContains('MobilyWs notifications must have toMobilyWs method', $e->getMessage());

return;
}

$this->fail('CouldNotSendNotification exception was not raised');

}

}

class TestNotifiable
Expand Down
4 changes: 2 additions & 2 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function it_gives_an_instantiated_mobily_ws_api_object_when_the_channel_a

$this->provider->boot();
}

/** @test
* @expectedException \NotificationChannels\MobilyWs\Exceptions\CouldNotSendNotification
*/
Expand All @@ -57,7 +57,7 @@ public function it_throw_an_exception_when_there_is_no_config_file()
$this->app->shouldReceive('offsetGet')
->with('config')
->andReturnNull();

$this->app->shouldReceive('when')->with(MobilyWsChannel::class)->once()->andReturn($this->app);
$this->app->shouldReceive('needs')->with(MobilyWsApi::class)->once()->andReturn($this->app);
$this->app->shouldReceive('give')->with(Mockery::on(function ($mobilyWsApi) {
Expand Down

0 comments on commit c675f1b

Please sign in to comment.