Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagof committed Sep 5, 2024
1 parent b01baad commit 8d2b623
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ phpstan.neon
testbench.yaml
vendor
node_modules
.DS_Store
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^8.2",
"illuminate/contracts": "^10.0",
"spatie/laravel-data": "^3.5",
"spatie/laravel-data": "^4",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion database/factories/IxItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function definition()
return [

Check failure on line 17 in database/factories/IxItemFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Squarebit\InvoiceXpress\Database\Factories\IxItemFactory::definition() should return array<model property of Squarebit\InvoiceXpress\Models\IxItem, mixed> but returns array<string, array|float|string>.
'name' => fake()->name,
'description' => fake()->text,
'unitPrice' => fake()->randomFloat(2),
'unit_price' => fake()->randomFloat(2),
'unit' => 'unit',
'tax' => IxTaxFactory::new()->make()->toArray(),
];
Expand Down
5 changes: 2 additions & 3 deletions src/API/Data/ClientData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClientData extends EntityData
'unitPrice',
'unit',
'quantity',
'tax.name',
// 'tax.name',
];

public function __construct(
Expand All @@ -44,8 +44,7 @@ public function __construct(
#[WithCast(EnumCast::class)]
public null|Optional|TaxExemptionCodeEnum $taxExemptionCode,
public null|Optional|string $openAccountLink,
) {
}
) {}

public static function getUseProperties(): array
{
Expand Down
3 changes: 2 additions & 1 deletion src/API/Data/Transformers/BoolToIntTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Squarebit\InvoiceXpress\API\Data\Transformers;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

class BoolToIntTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): int
public function transform(DataProperty $property, mixed $value, TransformationContext $context): int
{
return (int) $value;
}
Expand Down
3 changes: 2 additions & 1 deletion src/API/Data/Transformers/BoolToNumericStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Squarebit\InvoiceXpress\API\Data\Transformers;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

class BoolToNumericStringTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): string
public function transform(DataProperty $property, mixed $value, TransformationContext $context): string
{
return $value;
}
Expand Down
3 changes: 2 additions & 1 deletion src/API/Data/Transformers/BoolToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Squarebit\InvoiceXpress\API\Data\Transformers;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

class BoolToStringTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): string
public function transform(DataProperty $property, mixed $value, TransformationContext $context): string
{
return $value ? 'true' : 'false';
}
Expand Down
3 changes: 2 additions & 1 deletion src/API/Data/Transformers/EnumArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Squarebit\InvoiceXpress\API\Data\Transformers;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

class EnumArrayTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): array
public function transform(DataProperty $property, mixed $value, TransformationContext $context): array
{
return array_map(fn ($case) => $case->value, $value);
}
Expand Down
3 changes: 2 additions & 1 deletion src/API/Data/Transformers/FloatToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Squarebit\InvoiceXpress\API\Data\Transformers;

use Spatie\LaravelData\Support\DataProperty;
use Spatie\LaravelData\Support\Transformation\TransformationContext;
use Spatie\LaravelData\Transformers\Transformer;

class FloatToStringTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): string
public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
{
return number_format($value, 2, '.', '');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/API_REAL/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
->toThrow(RequestException::class);

// list invoices
expect(fn () => InvoiceXpress::clients()->listInvoices())
expect(fn () => InvoiceXpress::clients()->listInvoices($client->id))
->not()->toThrow(RequestException::class);

// list
Expand Down
2 changes: 1 addition & 1 deletion tests/API_REAL/EstimateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
[
'date' => now()->format(\Squarebit\InvoiceXpress\InvoiceXpress::DATE_FORMAT),
'due_date' => now()->addDays(random_int(10, 30))->format(\Squarebit\InvoiceXpress\InvoiceXpress::DATE_FORMAT),
'reference' => fake()->colorName,
'reference' => fake()->colorName(),
'observations' => fake()->text(128),
'client' => [
'name' => 'Some Client Name',
Expand Down
2 changes: 1 addition & 1 deletion tests/API_REAL/GuideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
'date' => now()->addDay()->format(\Squarebit\InvoiceXpress\InvoiceXpress::DATE_FORMAT),
'due_date' => now()->addDays(random_int(10,
30))->format(\Squarebit\InvoiceXpress\InvoiceXpress::DATE_FORMAT),
'reference' => fake()->colorName,
'reference' => fake()->colorName(),
'observations' => fake()->text(128),
'address_from' => [
'detail' => 'Rua 5',
Expand Down
2 changes: 1 addition & 1 deletion tests/API_REAL/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
})->with([
[
[
'name' => fake()->colorName,
'name' => fake()->colorName(),
'description' => fake()->text(128),
'unit_price' => fake()->randomFloat(2, 0, 100),
'unit' => collect(ItemUnitEnum::values())->random(),
Expand Down
2 changes: 1 addition & 1 deletion tests/API_REAL/SequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
->not()->toThrow(RequestException::class);

})->with([
fake()->colorName,
fake()->colorName(),
])->skip(! TEST_REAL_API);
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function setUp(): void
fn (string $modelName) => 'Squarebit\\InvoiceXpress\\Database\\Factories\\'.class_basename($modelName).'Factory'
);

Http::preventStrayRequests()->fake([]);
TEST_REAL_API === false && Http::preventStrayRequests()->fake([]);
}

protected function getPackageProviders($app)
Expand Down
22 changes: 20 additions & 2 deletions tests/Unit/HasClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,34 @@

it('can set a client', function () {

$invoice = new IxSimplifiedInvoice();
$invoice = new IxSimplifiedInvoice;
$client = IxClientFactory::new()->make();

expect($invoice->setClient($client))
->client->toBeInstanceOf(ClientData::class);
});

it('can set a client from ClientData', function () {

$invoice = new IxSimplifiedInvoice;
$client = IxClientFactory::new()->make()->getData();

expect($invoice->setClient($client))
->client->toBeInstanceOf(ClientData::class);
});

it('can set a client from array', function () {

$invoice = new IxSimplifiedInvoice;
$client = IxClientFactory::new()->make()->toArray();

expect($invoice->setClient($client))
->client->toBeInstanceOf(ClientData::class);
});

it('can get a client', function () {

$invoice = new IxSimplifiedInvoice();
$invoice = new IxSimplifiedInvoice;
$client = IxClientFactory::new()->make();
$invoice->client = $client->getData();

Expand Down
15 changes: 13 additions & 2 deletions tests/Unit/HasItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

it('can add an Item', function () {

$invoice = new IxSimplifiedInvoice();
$invoice = new IxSimplifiedInvoice;
$item = IxItemFactory::new()->make();

$invoice->addItem($item);
Expand All @@ -14,9 +14,20 @@
->items->toHaveCount(1);
});

it('can add an Item from array', function () {

$invoice = new IxSimplifiedInvoice;
$item = IxItemFactory::new()->make()->toArray();

$invoice->addItem($item);

expect($invoice)
->items->toHaveCount(1);
});

it('can add Items', function () {

$invoice = new IxSimplifiedInvoice();
$invoice = new IxSimplifiedInvoice;
$item = IxItemFactory::new()->make();

$invoice->addItems([$item, $item, $item]);
Expand Down

0 comments on commit 8d2b623

Please sign in to comment.