From 75130455eb80d065cc41cd0b79f785c346b1d9d9 Mon Sep 17 00:00:00 2001 From: takdeniz Date: Fri, 6 Mar 2020 22:03:35 +0300 Subject: [PATCH] added translator mock (#17) --- composer.json | 1 + src/Exceptions/AbstractNetgsmException.php | 2 +- src/NetgsmChannel.php | 2 +- src/Sms/AbstractNetgsmMessage.php | 2 +- tests/BaseTestCase.php | 11 +++++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e180d72..640bbbf 100755 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "guzzlehttp/guzzle": "^6.5", "illuminate/support": "^6.0|^7.0", "illuminate/notifications": "^6.0|^7.0", + "illuminate/translation": "^6.0|^7.0", "nesbot/carbon": "^2.0", "ext-simplexml": "*" }, diff --git a/src/Exceptions/AbstractNetgsmException.php b/src/Exceptions/AbstractNetgsmException.php index a77e515..eccef16 100644 --- a/src/Exceptions/AbstractNetgsmException.php +++ b/src/Exceptions/AbstractNetgsmException.php @@ -9,6 +9,6 @@ abstract class AbstractNetgsmException extends Exception { public function __construct($message = '', $code = 0, Throwable $previous = null) { - parent::__construct(\Lang::get($message), $code, $previous); + parent::__construct(trans($message), $code, $previous); } } diff --git a/src/NetgsmChannel.php b/src/NetgsmChannel.php index 49c4d41..d3ed363 100644 --- a/src/NetgsmChannel.php +++ b/src/NetgsmChannel.php @@ -32,7 +32,7 @@ public function send($notifiable, Notification $notification) $message = $notification->toNetgsm($notifiable); if (! $message instanceof AbstractNetgsmMessage) { - throw new Exception(\Lang::get('netgsm::errors.invalid_netgsm_message')); + throw new Exception(trans('netgsm::errors.invalid_netgsm_message')); } if (! $message->getRecipients()) { diff --git a/src/Sms/AbstractNetgsmMessage.php b/src/Sms/AbstractNetgsmMessage.php index f83e9ac..715fc91 100644 --- a/src/Sms/AbstractNetgsmMessage.php +++ b/src/Sms/AbstractNetgsmMessage.php @@ -209,7 +209,7 @@ public function getSendMethod(): string public function setSendMethod(string $sendMethod): self { if (! in_array($sendMethod, $this->sendMethods)) { - throw new Exception(\Lang::get('method_not_allowed', ['method' => $sendMethod])); + throw new Exception(trans('method_not_allowed', ['method' => $sendMethod])); } $this->sendMethod = $sendMethod; diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 285dae1..5ab5f0f 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -3,6 +3,8 @@ namespace TarfinLabs\Netgsm\Tests; use Faker\Factory; +use Illuminate\Foundation\Application; +use Mockery; use PHPUnit\Framework\TestCase; class BaseTestCase extends TestCase @@ -14,6 +16,15 @@ class BaseTestCase extends TestCase public function setUp(): void { + parent::setUp(); $this->faker = Factory::create(); + + $app = new Application(); + $app->singleton('translator', function () { + $translate = Mockery::mock(); + $translate->shouldReceive('get')->andReturnArg(0); + + return $translate; + }); } }