Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

melhorenvio/shipment-sdk-php 2.0.0 requires php 7.4.* which does not match your installed version 8.1.4. #14

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
86a0474
Merged in feature/INTG-14 (pull request #1)
pedrobarrosme05 Sep 4, 2020
b7568a4
primeiro documento de testes
pedrobarrosme05 Oct 21, 2020
25a9bdf
correções no readme
pedrobarrosme05 Oct 22, 2020
e97f9ad
segundo documente de teste
pedrobarrosme05 Oct 27, 2020
cf60a70
terceiro documento de teste e correção no readme
pedrobarrosme05 Oct 28, 2020
ef14b47
resolvendo problemas nos testes do calculate
pedrobarrosme05 Nov 16, 2020
73cecc6
mudanças nos nomes das funções para padrão camelCase
pedrobarros05 Dec 3, 2020
d11f6b5
Merged in feature/PTI-49 (pull request #2)
pedrobarrosme05 Dec 4, 2020
0c1ac64
Merged in develop (pull request #3)
andrevpde90 Dec 9, 2020
594e73b
adição de serviços disponíveis no Readme
pedrobarros05 Dec 17, 2020
773b765
adição no Readme do exemplo de uso de todas os serviços.
pedrobarros05 Dec 17, 2020
32b2a36
Merged in fix/PTI-322 (pull request #4)
pedrobarrosme05 Dec 18, 2020
2d966a2
Merged in develop (pull request #5)
andrevpde90 Dec 18, 2020
b0ef735
Merge pull request #1 from melhorenvio/master
andrevpde90 Dec 21, 2020
6878a5f
correção no composer json para publicação
pedrobarros05 Dec 21, 2020
8f7c9c8
correção no composer.json
pedrobarros05 Dec 21, 2020
d2406c9
Merge pull request #2 from melhorenvio/hotfix/atualizando-pacote
andrevpde90 Dec 21, 2020
9d72a1b
Merge pull request #3 from melhorenvio/develop
andrevpde90 Dec 21, 2020
aed38a7
ajuste no readme
pedrobarros05 Dec 22, 2020
5ef339b
Merge pull request #4 from melhorenvio/hotfix/ajuste-readme
andrevpde90 Dec 22, 2020
8a82b4e
Merge pull request #5 from melhorenvio/master
andrevpde90 Dec 22, 2020
8127a01
ajuste composer.json
pedrobarros05 Dec 22, 2020
ce128e0
Merge pull request #6 from melhorenvio/hotfix/ajuste-composer
andrevpde90 Dec 22, 2020
997d5b7
Merge pull request #7 from melhorenvio/master
andrevpde90 Dec 22, 2020
7a57e08
fix:modifing the payload format for the calculate request
marcalpizzi Jul 7, 2021
bbf979c
Merge pull request #10 from melhorenvio/fix/payload-on-calculate-request
marcalpizzi Jul 7, 2021
9caf3bb
Merge pull request #11 from melhorenvio/master
marcalpizzi Jul 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
);
```

Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand Down
6 changes: 0 additions & 6 deletions src/Enums/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Shipment/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
53 changes: 53 additions & 0 deletions tests/Enums/EndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace MelhorEnvio\Tests\Enums;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;


/**
* This test is a example for consult
*/
class EndpointTest extends TestCase
{
/**
* @var Client
*/
private $client;

protected function setUp()
{
$mockHandler = new MockHandler([
new Response(200, ['Foo' => '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());
}
}
4 changes: 2 additions & 2 deletions tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class EnvironmentTest extends TestCase
const TOKEN = 'token-testing';

/** @test */
public function is_invalid_environment()
public function isInvalidEnvironment()
{
$this->expectException(InvalidEnvironmentException::class);

new Shipment(self::TOKEN, 'invalid-environment');
}

/** @test */
public function is_valid_environment()
public function isValidEnvironment()
{
foreach (Environment::ENVIRONMENTS as $environment) {
$shipment = new Shipment(self::TOKEN, $environment);
Expand Down
80 changes: 80 additions & 0 deletions tests/Resources/Shipment/CalculatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace MelhorEnvio\Tests\Resources\Shipment;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\InvalidArgumentException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use MelhorEnvio\Exceptions\InvalidCalculatorPayloadException;
use MelhorEnvio\Resources\Resource;
use MelhorEnvio\Resources\Shipment\Calculator;
use MelhorEnvio\Resources\Shipment\Product;
use PHPUnit\Framework\TestCase;

class CalculatorTest extends TestCase
{
/**
* @var Client
*/
protected $client;

protected function setUp()
{
parent::setUp();

$mock = new MockHandler([
new Response(200, ['payload'], '[{"id":1,"name":"PAC","price":"27.48","custom_price":"27.48","discount":"0.00","currency":"R$","delivery_time":10,"delivery_range":{"min":9,"max":10},"custom_delivery_time":10,"custom_delivery_range":{"min":9,"max":10},"packages":[{"price":"27.48","discount":"0.00","format":"box","dimensions":{"height":6,"width":11,"length":18},"weight":"0.40","insurance_value":"0.00"}],"additional_services":{"receipt":false,"own_hand":true,"collect":false},"company":{"id":1,"name":"Correios","picture":"https:\/\/logistic.melhorenvio.work\/images\/shipping-companies\/correios.png"}}]'),
new Response(200, ['payload'], '[{"id":1,"name":"PAC","price":"27.48","custom_price":"27.48","discount":"0.00","currency":"R$","delivery_time":10,"delivery_range":{"min":9,"max":10},"custom_delivery_time":10,"custom_delivery_range":{"min":9,"max":10},"packages":[{"price":"27.48","discount":"0.00","format":"box","dimensions":{"height":6,"width":11,"length":18},"weight":"0.40","insurance_value":"0.00"}],"additional_services":{"receipt":false,"own_hand":true,"collect":false},"company":{"id":1,"name":"Correios","picture":"https:\/\/logistic.melhorenvio.work\/images\/shipping-companies\/correios.png"}}]'),
]);

$handlerStack = HandlerStack::create($mock);

$httpClient = new Client([
'handler' => $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();
}
}
48 changes: 48 additions & 0 deletions tests/Resources/Shipment/ProductTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace MelhorEnvio\Tests\Resources\Shipment;

use InvalidArgumentException;
use MelhorEnvio\Resources\Shipment\Product;
use PHPUnit\Framework\TestCase;

class ProductTest extends TestCase
{
/**
* @var Product
*/
private $product;

protected function setUp()
{
$this->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);
}


}