|
|
@@ -4,6 +4,7 @@ namespace App\Tests\Service\Mobyt;
|
|
|
|
|
|
use App\Service\Mobyt\MobytService;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
|
|
|
@@ -62,4 +63,46 @@ class MobytServiceTest extends TestCase
|
|
|
33.0
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see MobytService::isCredentialsAreCorrect()
|
|
|
+ */
|
|
|
+ public function testIsCredentialsAreCorrect(): void {
|
|
|
+
|
|
|
+ // Mock the response that will be returned by the connection request
|
|
|
+ $connectResponse = $this->getMockBuilder(ResponseInterface::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+ $connectResponse->method('getContent')->willReturn('userId;sessionKey');
|
|
|
+
|
|
|
+ $this->client
|
|
|
+ ->method('request')
|
|
|
+ ->with("GET", "login?username=user&password=pwd")
|
|
|
+ ->willReturnOnConsecutiveCalls(
|
|
|
+ $connectResponse
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertTrue($this->mobytService->isCredentialsAreCorrect('user', 'pwd'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @see MobytService::isCredentialsAreCorrect()
|
|
|
+ */
|
|
|
+ public function testIsCredentialsUnCorrect(): void {
|
|
|
+
|
|
|
+ // Mock the response that will be returned by the connection request
|
|
|
+ $connectResponse = $this->getMockBuilder(ResponseInterface::class)
|
|
|
+ ->disableOriginalConstructor()
|
|
|
+ ->getMock();
|
|
|
+ $connectResponse->method('getContent')->willThrowException(new NotFoundHttpException());
|
|
|
+
|
|
|
+ $this->client
|
|
|
+ ->method('request')
|
|
|
+ ->with("GET", "login?username=user&password=pwd")
|
|
|
+ ->willReturnOnConsecutiveCalls(
|
|
|
+ $connectResponse
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertFalse($this->mobytService->isCredentialsAreCorrect('user', 'pwd'));
|
|
|
+ }
|
|
|
}
|