Skip to content

Commit

Permalink
Merge pull request #25 from AlexandreBellas/develop
Browse files Browse the repository at this point in the history
feat: atualizar para v310
  • Loading branch information
AlexandreBellas authored Oct 5, 2024
2 parents 2d8fce7 + af2e48f commit 887905b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
para PHP 8.2+. O mais completo existente.

Atualizado com a versão `v308` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-09-04)).
Atualizado com a versão `v310` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-10-02)).

## Instalação

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "alebatistella/bling-erp-api",
"description": "Pacote de integração com a API do Bling ERP",
"type": "library",
"version": "1.16.0",
"version": "1.17.0",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/Contatos/Schema/Get/GetParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function __construct(
) {
$this->criterio = $criterio instanceof Criterio ? $criterio->value : $criterio;

$this->dataInclusaoInicial = $this->prepareStringOrDateParam($dataInclusaoInicial);
$this->dataInclusaoFinal = $this->prepareStringOrDateParam($dataInclusaoFinal);
$this->dataAlteracaoInicial = $this->prepareStringOrDateParam($dataAlteracaoInicial);
$this->dataAlteracaoFinal = $this->prepareStringOrDateParam($dataAlteracaoFinal);
$this->dataInclusaoInicial = $this->prepareStringOrDateParam($dataInclusaoInicial, true);
$this->dataInclusaoFinal = $this->prepareStringOrDateParam($dataInclusaoFinal, true);
$this->dataAlteracaoInicial = $this->prepareStringOrDateParam($dataAlteracaoInicial, true);
$this->dataAlteracaoFinal = $this->prepareStringOrDateParam($dataAlteracaoFinal, true);

$this->uf = $uf instanceof UF ? $uf->value : $uf;

Expand Down
10 changes: 3 additions & 7 deletions src/Entities/Nfses/Nfses.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\Find\FindResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\Get\GetResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\GetConfigurations\GetConfigurationsResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\PostAccounts\PostAccountsResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\PostStock\PostStockResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\PostStockToDeposit\PostStockToDepositResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\ReverseAccounts\ReverseAccountsResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\ReverseStock\ReverseStockResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\Send\SendResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\Update\UpdateResponse;
use AleBatistella\BlingErpApi\Entities\Nfses\Schema\UpdateConfigurations\UpdateConfigurationsResponse;
use AleBatistella\BlingErpApi\Entities\Shared\BaseEntity;
use AleBatistella\BlingErpApi\Entities\Shared\DTO\Request\RequestOptions;
Expand Down Expand Up @@ -159,17 +153,19 @@ public function send(int $idNotaServico): SendResponse
* Cancela uma nota de serviço.
*
* @param int $idNotaServico ID da nota de serviço
* @param array $body Corpo da requisição
*
* @return null
* @throws BlingApiException|BlingInternalException
*
* @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Servi%C3%A7o%20Eletr%C3%B4nicas/post_nfse__idNotaServico__cancelar
*/
public function cancel(int $idNotaServico): null
public function cancel(int $idNotaServico, array $body): null
{
$response = $this->repository->store(
new RequestOptions(
endpoint: "nfse/$idNotaServico/cancelar",
body: $body
)
);

Expand Down
22 changes: 13 additions & 9 deletions src/Entities/Nfses/__tests__/NfsesTest.spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testShouldDeleteSuccessfully(): void
->method('destroy')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/$idNotaServico"
)
)
Expand All @@ -72,7 +72,7 @@ public function testShouldGetSuccessfully(): void
->method('index')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse"
&& is_null($requestOptions->queryParams)
)
Expand Down Expand Up @@ -100,7 +100,7 @@ public function testShouldFindSuccessfully(): void
->method('show')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/$idNotaServico"
)
)
Expand Down Expand Up @@ -129,7 +129,7 @@ public function testShouldGetConfigurationsSuccessfully(): void
->method('index')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/configurations"
)
)
Expand All @@ -156,7 +156,7 @@ public function testShouldCreateSuccessfully(): void
->method('store')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse"
)
)
Expand All @@ -183,7 +183,7 @@ public function testShouldSendSuccessfully(): void
->method('store')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/$idNotaServico/enviar"
)
)
Expand All @@ -204,20 +204,24 @@ public function testShouldSendSuccessfully(): void
public function testShouldCancelSuccessfully(): void
{
$idNotaServico = fake()->randomNumber();
$cancelRequest = json_decode(file_get_contents(__DIR__ . '/cancel/request.json'), true);
$cancelResponse = json_decode(file_get_contents(__DIR__ . '/cancel/response.json'), true);
$repository = $this->getMockBuilder(IBlingRepository::class)->getMock();
$repository->expects($this->once())
->method('store')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/$idNotaServico/cancelar"
)
)
->willReturn($this->buildResponse(status: 200, body: $this->buildBody($cancelResponse)));

/** @var IBlingRepository $repository */
$response = $this->getInstance($repository)->cancel($idNotaServico);
$response = $this->getInstance($repository)->cancel(
$idNotaServico,
$cancelRequest
);

$this->assertNull($response);
}
Expand All @@ -242,7 +246,7 @@ public function testShouldUpdateConfigurationsSuccessfully(): void
->method('replace')
->with(
$this->callback(
fn (RequestOptions $requestOptions) =>
fn(RequestOptions $requestOptions) =>
$requestOptions->endpoint === "nfse/configuracoes"
)
)
Expand Down
4 changes: 4 additions & 0 deletions src/Entities/Nfses/__tests__/cancel/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"codigoMotivo": 1,
"justificativa": "Cancelamento de NFS-e"
}
6 changes: 3 additions & 3 deletions src/Entities/PedidosVendas/Schema/Get/GetParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ public function __construct(
public ?array $numerosLojas = null,
) {
$this->situacoes = array_map(
fn (Situacao|int|null $situacao) => $situacao instanceof Situacao
fn(Situacao|int|null $situacao) => $situacao instanceof Situacao
? $situacao->value
: $situacao,
$situacoes
);

$this->dataInicial = $this->prepareStringOrDateParam($dataInicial);
$this->dataFinal = $this->prepareStringOrDateParam($dataFinal);
$this->dataAlteracaoInicial = $this->prepareStringOrDateParam($dataAlteracaoInicial);
$this->dataAlteracaoFinal = $this->prepareStringOrDateParam($dataAlteracaoFinal);
$this->dataAlteracaoInicial = $this->prepareStringOrDateParam($dataAlteracaoInicial, true);
$this->dataAlteracaoFinal = $this->prepareStringOrDateParam($dataAlteracaoFinal, true);
$this->dataPrevistaInicial = $this->prepareStringOrDateParam($dataPrevistaInicial);
$this->dataPrevistaFinal = $this->prepareStringOrDateParam($dataPrevistaFinal);

Expand Down

0 comments on commit 887905b

Please sign in to comment.