From 7e1ed1a2411d180ade8718d6c8fb67b46855a4a6 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 22 Dec 2022 15:21:14 +0300 Subject: [PATCH] additional fixes --- .gitignore | 1 + src/Bot/HttpClient.php | 15 ++++++++------- .../Model/Request/UploadFileByUrlRequest.php | 2 +- tests/Bot/Tests/FileTest.php | 17 ++++++++++++++++- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 1e13333..064fe5f 100644 --- a/.gitignore +++ b/.gitignore @@ -195,3 +195,4 @@ build/* # Test report & coverage test-report.xml clover.xml +composer.lock diff --git a/src/Bot/HttpClient.php b/src/Bot/HttpClient.php index 5d91594..6c76a68 100644 --- a/src/Bot/HttpClient.php +++ b/src/Bot/HttpClient.php @@ -13,7 +13,12 @@ namespace RetailCrm\Mg\Bot; use BadMethodCallException; use ErrorException; use Exception; +use GuzzleHttp\Client; +use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Psr7\Utils; use InvalidArgumentException; +use Psr\Http\Message\ResponseInterface; use RetailCrm\Common\Exception\InvalidJsonException; use RetailCrm\Common\Exception\LimitException; use RetailCrm\Common\Exception\NotFoundException; @@ -22,11 +27,6 @@ use RetailCrm\Common\Serializer; use RetailCrm\Common\Url; use RuntimeException; use Symfony\Component\Validator\Validation; -use GuzzleHttp\Client; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Utils; -use GuzzleHttp\Exception\GuzzleException; -use Psr\Http\Message\ResponseInterface; /** * Class HttpClient @@ -216,14 +216,15 @@ class HttpClient /** * Validate given class * - * @param string $class + * @param object $class * * @return void */ - private function validateRequest($class) + private function validateRequest(object $class) { $validator = Validation::createValidatorBuilder() ->enableAnnotationMapping() + ->addDefaultDoctrineAnnotationReader() ->getValidator(); $errors = $validator->validate($class); diff --git a/src/Bot/Model/Request/UploadFileByUrlRequest.php b/src/Bot/Model/Request/UploadFileByUrlRequest.php index 8951812..f780de9 100644 --- a/src/Bot/Model/Request/UploadFileByUrlRequest.php +++ b/src/Bot/Model/Request/UploadFileByUrlRequest.php @@ -27,7 +27,7 @@ class UploadFileByUrlRequest implements ModelInterface * * @Type("string") * @Accessor(getter="getUrl",setter="setUrl") - * @Assert\NotBlank() + * @Assert\NotBlank(allowNull=false) * @Assert\Url() */ private $url; diff --git a/tests/Bot/Tests/FileTest.php b/tests/Bot/Tests/FileTest.php index fe28ff2..d90e584 100644 --- a/tests/Bot/Tests/FileTest.php +++ b/tests/Bot/Tests/FileTest.php @@ -27,7 +27,7 @@ class FileTest extends TestCase * @group("upload") * @throws \Exception */ - public function testUploadFileByUrlException() + public function testUploadFileByUrlEmpty() { $client = self::getApiClient( null, @@ -38,6 +38,21 @@ class FileTest extends TestCase self::expectException(\InvalidArgumentException::class); $client->uploadFileByUrl(''); + } + /** + * @group("upload") + * @throws \Exception + */ + public function testUploadFileByUrlInvalid() + { + $client = self::getApiClient( + null, + null, + false, + $this->getErrorsResponse(400, 'Something is not quite right.') + ); + + self::expectException(\InvalidArgumentException::class); $client->uploadFileByUrl('rar'); }