diff --git a/README.md b/README.md index e9f09bf..33350db 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Shipment SDK - Serviço de cotações do Melhor Envio -[![Latest Version on Packagist](https://img.shields.io/packagist/v/melhorenvio/shipment-sdk.svg?style=flat-square)](https://packagist.org/packages/melhorenvio/shipment-sdk) -[![Build Status](https://img.shields.io/travis/melhorenvio/shipment-sdk/master.svg?style=flat-square)](https://travis-ci.org/melhorenvio/shipment-sdk) -[![Quality Score](https://img.shields.io/scrutinizer/g/melhorenvio/shipment-sdk.svg?style=flat-square)](https://scrutinizer-ci.com/g/melhorenvio/shipment-sdk) -[![Total Downloads](https://img.shields.io/packagist/dt/melhorenvio/shipment-sdk.svg?style=flat-square)](https://packagist.org/packages/melhorenvio/shipment-sdk) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/melhorenvio/shipment-sdk-php.svg?style=flat-square)](https://packagist.org/packages/melhorenvio/shipment-sdk-php) +[![Build Status](https://img.shields.io/travis/melhorenvio/shipment-sdk-php/master.svg?style=flat-square)](https://travis-ci.org/melhorenvio/shipment-sdk-php) +[![Quality Score](https://img.shields.io/scrutinizer/g/melhorenvio/shipment-sdk-php.svg?style=flat-square)](https://scrutinizer-ci.com/g/melhorenvio/shipment-sdk-php) +[![Total Downloads](https://img.shields.io/packagist/dt/melhorenvio/shipment-sdk-php.svg?style=flat-square)](https://packagist.org/packages/melhorenvio/shipment-sdk-php) Agora ficou mais fácil ter o serviço de cotações do Melhor Envio no seu projeto de e-commerce. @@ -93,7 +93,7 @@ $calculator->postalCode('01010010', '20271130'); #### Adicionando os produtos para cotação -Nesta parte, você define os produtos que servião para sua cotaçãom as informações que devem ser passadas como parâmetro são as seguintes: +Nesta parte, você irá definir os produtos que servirão para a sua cotação as informações que devem ser passadas como parâmetro são as seguintes: * Altura * Largura @@ -115,7 +115,7 @@ $calculator->addProducts( #### Adicionando os pacotes para cotação -Nesta parte, você define os pacotes que servirão para sua cotação, as informações que devem ser passadas como parâmetro são as seguintes: +Nesta parte, você irá definir os pacotes que servirão para sua cotação, as informações que devem ser passadas como parâmetro são as seguintes: * Altura * Largura @@ -145,15 +145,20 @@ Se você desejar customizar, nesta parte serão escolhidos os serviços das tran * Correios * Jadlog * Via Brasil -* Azul Cargo +* Azul Cargo +* Latam Cargo ```php $calculator->addServices( Service::CORREIOS_PAC, Service::CORREIOS_SEDEX, + Service::CORREIOS_MINI, Service::JADLOG_PACKAGE, Service::JADLOG_COM, - Service::AZULCARGO_AMANHA + Service::AZULCARGO_AMANHA, + Service::AZULCARGO_ECOMMERCE, + Service::LATAMCARGO_JUNTOS, + Service::VIABRASIL_RODOVIARIO ); ``` @@ -188,9 +193,17 @@ $quotations = $calculator->calculate(); ### Testes +Dentro do projeto você encontrará alguns documentos de teste baseados em testes unitários + + +Você pode usar na aplicação tanto o comando: ``` bash composer test ``` +Quanto o comando: +```bash +vendor/bin/phpunit tests +``` ### Changelog diff --git a/composer.json b/composer.json index 8219f93..939551f 100644 --- a/composer.json +++ b/composer.json @@ -5,13 +5,13 @@ "melhorenvio", "shipment-sdk-php" ], - "homepage": "https://github.com/melhorenvio/shipment-sdk", + "homepage": "https://github.com/melhorenvio/shipment-sdk-php", "license": "MIT", "type": "library", "authors": [ { - "name": "Rodrigo Silveira", - "email": "rodrigo.silveira@melhorenvio.com", + "name": "Melhor Envio", + "email": "tecnologia@melhorenvio.com", "role": "Developer" } ], diff --git a/src/Enums/Service.php b/src/Enums/Service.php index 406f175..751237f 100644 --- a/src/Enums/Service.php +++ b/src/Enums/Service.php @@ -20,12 +20,6 @@ class Service const JADLOG_PACKAGE = 3; const JADLOG_COM = 4; - /** - * Services - JAMEF - * @var int - */ - const JAMEF_RODOVIARIO = 7; - /** * Services - VIABRASIL * @var int diff --git a/src/Resources/Shipment/Calculator.php b/src/Resources/Shipment/Calculator.php index 27c3444..79fff3b 100644 --- a/src/Resources/Shipment/Calculator.php +++ b/src/Resources/Shipment/Calculator.php @@ -276,7 +276,7 @@ public function calculate() try { $response = $this->resource->getHttp()->post('me/shipment/calculate', [ - 'form_params' => $this->payload, + 'json' => $this->payload, ]); return json_decode((string) $response->getBody(), true); diff --git a/tests/Enums/EndpointTest.php b/tests/Enums/EndpointTest.php new file mode 100644 index 0000000..1aed683 --- /dev/null +++ b/tests/Enums/EndpointTest.php @@ -0,0 +1,53 @@ + 'Bar'], 'ResponseContext'), + new RequestException('Communicating with server failed', new Request('POST', 'https://sandbox.melhorenvio.com.br')) + ]); + + $handlerStack = HandlerStack::create($mockHandler); + + $httpClient = new Client([ + 'handler' => $handlerStack + ]); + + $this->client = $httpClient; + } + + /** + * @test + */ + public function isValidEndpointSandbox() + { + $response = $this->client->post('https://sandbox.melhorenvio.com.br', array( + 'request.options' => array( + 'exceptions' => false + ) + )); + + $this->assertEquals(200, $response->getStatusCode()); + } +} diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index 637c28e..bbad795 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -15,7 +15,7 @@ class EnvironmentTest extends TestCase const TOKEN = 'token-testing'; /** @test */ - public function is_invalid_environment() + public function isInvalidEnvironment() { $this->expectException(InvalidEnvironmentException::class); @@ -23,7 +23,7 @@ public function is_invalid_environment() } /** @test */ - public function is_valid_environment() + public function isValidEnvironment() { foreach (Environment::ENVIRONMENTS as $environment) { $shipment = new Shipment(self::TOKEN, $environment); diff --git a/tests/Resources/Shipment/CalculatorTest.php b/tests/Resources/Shipment/CalculatorTest.php new file mode 100644 index 0000000..b4e3560 --- /dev/null +++ b/tests/Resources/Shipment/CalculatorTest.php @@ -0,0 +1,80 @@ + $handlerStack + ]); + + $this->client = $httpClient; + } + + /** + * @test + */ + public function isValidCalculate() + { + + $response = $this->client->request('POST', 'me/shipment/calculate'); + + $resourceStub = $this->createMock(Resource::class); + $resourceStub->method('getHttp')->willReturn($this->client); + + $calculator = new Calculator($resourceStub); + + $calculator->postalCode('96010760', '08226021'); + + $calculator->addProduct(new Product(uniqid(), 40, 30, 50, 10.00, 100.0, 1)); + + $quotation = $calculator->calculate(); + + $this->assertEquals(json_encode($quotation), $response->getBody()); + } + + /** + * @test + */ + public function isInvalidCalculate() + { + $clientStub = $this->createMock(Client::class); + $clientStub->method('send')->willReturn(function () { throw new \Exception; }); + + $resourceStub = $this->createMock(Resource::class); + $resourceStub->method('getHttp')->willReturn($clientStub); + + $calculator = new Calculator($resourceStub); + + $this->expectException(InvalidCalculatorPayloadException::class); + + $calculator->calculate(); + } +} diff --git a/tests/Resources/Shipment/ProductTest.php b/tests/Resources/Shipment/ProductTest.php new file mode 100644 index 0000000..05b815e --- /dev/null +++ b/tests/Resources/Shipment/ProductTest.php @@ -0,0 +1,48 @@ +product = new Product(uniqid(), 40, 30, 50, 10.00, 100.0, 1); + } + + /** + * @test + */ + public function isValidQuantityOfProducts() + { + $quantity = $this->product->getQuantity(); + + $this->product->setQuantity($quantity); + + self::assertEquals(1, $quantity); + } + + /** + * @test + */ + public function isInvalidQuantityOfProducts() + { + $this->expectException(InvalidArgumentException::class); + + $invalidProduct = new Product(uniqid(), 40, 30, 50, 10.00, 100.0, -2); + + $invalidQuantity = $invalidProduct->getQuantity(); + + $invalidProduct->setQuantity($invalidQuantity); + } + + +}