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", 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..68ee801 --- /dev/null +++ b/tests/SMSTest.php @@ -0,0 +1,92 @@ +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(); + } +}