From 926037f8aa9aad5349a57b794d7421e8a1e84ca0 Mon Sep 17 00:00:00 2001 From: Ahmed Elsayed Date: Wed, 4 Dec 2024 19:11:55 +0200 Subject: [PATCH 1/4] feat: add compatibility for Laravel 11 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba177c3..66700b9 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-json": "*", "ext-simplexml": "*", "guzzlehttp/guzzle": "^7.5", - "illuminate/support": "^9.0|^10" + "illuminate/support": "^9.0|^10|^11.0" }, "require-dev": { "orchestra/testbench": "^8.0.8", From 866fd2ac175b51c439b7acdfd7db2e937cc9b431 Mon Sep 17 00:00:00 2001 From: Ahmed Elsayed Date: Wed, 11 Dec 2024 12:55:03 +0200 Subject: [PATCH 2/4] test: Implement mock testing for SMSDriverFactory --- tests/SMSDriverFactoryTest.php | 32 ++++++++++++++++++++++++++++++++ tests/SMSTest.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/SMSDriverFactoryTest.php create mode 100644 tests/SMSTest.php diff --git a/tests/SMSDriverFactoryTest.php b/tests/SMSDriverFactoryTest.php new file mode 100644 index 0000000..7d4d882 --- /dev/null +++ b/tests/SMSDriverFactoryTest.php @@ -0,0 +1,32 @@ +shouldReceive('create') + ->once() + ->andReturn(\Mockery::mock(SMSDriverInterface::class));; + + SMSDriverFactory::create(); + } +} diff --git a/tests/SMSTest.php b/tests/SMSTest.php new file mode 100644 index 0000000..edc0268 --- /dev/null +++ b/tests/SMSTest.php @@ -0,0 +1,32 @@ +smsMock = \Mockery::mock(SMS::class)->shouldReceive('via','to','message','send') + ->andReturn(\Mockery::mock(SMSDriverResponseInterface::class));; + (new SMS)->via('vodafone')->to('01000000000')->message("test")->send(); + + } +} From cd429977bc642612a25eea33a89de075a45b26fd Mon Sep 17 00:00:00 2001 From: Ahmed Elsayed Date: Wed, 11 Dec 2024 15:57:45 +0200 Subject: [PATCH 3/4] test: Implement mock test for SMS class --- tests/SMSTest.php | 73 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/tests/SMSTest.php b/tests/SMSTest.php index edc0268..ad53796 100644 --- a/tests/SMSTest.php +++ b/tests/SMSTest.php @@ -1,15 +1,19 @@ smsMock = \Mockery::mock(SMS::class)->shouldReceive('via','to','message','send') - ->andReturn(\Mockery::mock(SMSDriverResponseInterface::class));; - (new SMS)->via('vodafone')->to('01000000000')->message("test")->send(); + $sms = $this->createMockXMLResponse() + ->createMockStream() + ->createMockResponse() + ->mockHTTP() + ->sendSMS(); + + $this->assertInstanceOf(SMSDriverResponseInterface::class, $sms); + + } + + private function createMockXMLResponse(): self + { + $this->mockXmlResponse = << + + + XML; + return $this; + } + + private function createMockStream(): self + { + $this->mockStream = Mockery::mock(StreamInterface::class); + $this->mockStream->shouldReceive('__toString') + ->andReturn($this->mockXmlResponse); + $this->mockStream->shouldReceive('getContents') + ->andReturn($this->mockXmlResponse); + return $this; + } + + private function createMockResponse(): self + { + $this->mockResponse = Mockery::mock(ResponseInterface::class); + $this->mockResponse + ->shouldReceive('getBody') + ->andReturn($this->mockStream); + $this->mockResponse + ->shouldReceive('getStatusCode') + ->andReturn(200); + $this->mockResponse + ->shouldReceive('getHeaders') + ->andReturn([ + 'Content-Type' => ['application/xml; charset=UTF8'] + ]); + return $this; + } + private function mockHTTP(): self + { + Mockery::mock('alias:RobustTools\Resala\Support\HTTP') + ->shouldReceive('post') + ->andReturn($this->mockResponse); + return $this; + } + + private function sendSMS() + { + return SMSFacade::via('vodafone') + ->to('01000000000') + ->message("test") + ->send(); } } From 891a4f2397d8216dbdb7ed1ab3f3efa63299de1d Mon Sep 17 00:00:00 2001 From: Ahmed Elsayed Date: Wed, 11 Dec 2024 16:06:36 +0200 Subject: [PATCH 4/4] chore: Remove unnecessary class imports --- tests/SMSTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/SMSTest.php b/tests/SMSTest.php index ad53796..68ee801 100644 --- a/tests/SMSTest.php +++ b/tests/SMSTest.php @@ -5,7 +5,6 @@ use Orchestra\Testbench\TestCase as OrchestraTestCase; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; -use RobustTools\Resala\Contracts\SMSDriverInterface; use RobustTools\Resala\Contracts\SMSDriverResponseInterface; use RobustTools\Resala\Facades\SMS as SMSFacade; use RobustTools\Resala\SMSServiceProvider;