Skip to content

Commit d83a4ed

Browse files
committed
added tests
1 parent 5500f86 commit d83a4ed

File tree

14 files changed

+322
-84
lines changed

14 files changed

+322
-84
lines changed

.github/workflows/tests.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
name: Tests
22

3-
on: ['push', 'pull_request']
3+
on: [ 'push', 'pull_request' ]
44

55
jobs:
66
ci:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
fail-fast: true
1010
matrix:
11-
os: [ubuntu-latest, macos-latest, windows-latest]
12-
php: [8.4]
13-
dependency-version: [prefer-lowest, prefer-stable]
11+
os: [ ubuntu-latest, macos-latest, windows-latest ]
12+
php: [ 8.4 ]
13+
dependency-version: [ prefer-lowest, prefer-stable ]
1414

1515
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
1616

1717
steps:
1818

19-
- name: Checkout
20-
uses: actions/checkout@v4
21-
22-
- name: Setup PHP
23-
uses: shivammathur/setup-php@v2
24-
with:
25-
php-version: ${{ matrix.php }}
26-
extensions: dom, mbstring, zip
27-
coverage: none
28-
29-
- name: Get Composer cache directory
30-
id: composer-cache
31-
shell: bash
32-
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
33-
34-
- name: Cache dependencies
35-
uses: actions/cache@v4
36-
with:
37-
path: ${{ steps.composer-cache.outputs.dir }}
38-
key: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }}
39-
restore-keys: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-
40-
41-
- name: Install Composer dependencies
42-
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
43-
44-
- name: Integration Tests
45-
run: php ./vendor/bin/pest
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
extensions: dom, mbstring, zip
27+
coverage: none
28+
29+
- name: Get Composer cache directory
30+
id: composer-cache
31+
shell: bash
32+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
33+
34+
- name: Cache dependencies
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.composer-cache.outputs.dir }}
38+
key: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-${{ hashFiles('composer.json') }}
39+
restore-keys: dependencies-php-${{ matrix.php }}-os-${{ matrix.os }}-version-${{ matrix.dependency-version }}-composer-
40+
41+
- name: Install Composer dependencies
42+
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
43+
44+
- name: Integration Tests
45+
run: php ./vendor/bin/pest --coverage --exactly=100

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ $organizations = RegistroSportESalute::filterByDenominazione('Sport Club')->get(
8484
$organizations = RegistroSportESalute::filterByCodiceFiscale('12345678901')->get();
8585

8686
// Chain filters
87-
$organizations = RegistroSportESalute::builder()
87+
//💡 Tip: the `builder` method is an eye candy for when you have multiple statements
88+
$organizations = RegistroSportESalute::builder()
8889
->filterByDenominazione('Sport Club')
8990
->filterByCodiceFiscale('12345678901')
9091
->get();
@@ -112,7 +113,6 @@ $organizations = RegistroSportESalute::filterByDenominazione('Sport Club')
112113
->get();
113114
```
114115

115-
116116
### Order
117117

118118
Order feature is not present. If you need it please create an issue or submit a PR.

composer.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
"php": "^8.4.0",
1818
"illuminate/cache": "^12.16",
1919
"illuminate/http": "^12.15",
20-
"illuminate/support": "^12.15"
20+
"illuminate/support": "^12.15",
21+
"illuminate/testing": "^12.16"
2122
},
2223
"require-dev": {
2324
"laravel/pint": "^1.22.1",
25+
"orchestra/testbench": "^10.3",
2426
"pestphp/pest": "^4.0.0",
2527
"pestphp/pest-plugin-type-coverage": "^4.0.0",
2628
"phpstan/phpstan": "^2.1.16",
@@ -34,7 +36,10 @@
3436
},
3537
"autoload-dev": {
3638
"psr-4": {
37-
"Tests\\": "tests/"
39+
"Tests\\": "tests/",
40+
"Workbench\\App\\": "workbench/app/",
41+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
42+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
3843
}
3944
},
4045
"minimum-stability": "dev",
@@ -51,7 +56,7 @@
5156
"refactor": "rector",
5257
"test:type-coverage": "pest",
5358
"test:lint": "pint --test",
54-
"test:unit": "pest --coverage",
59+
"test:unit": "pest --coverage --exactly=100",
5560
"test:types": "phpstan",
5661
"test:refactor": "rector --dry-run",
5762
"test": [
@@ -60,6 +65,18 @@
6065
"@test:unit",
6166
"@test:types",
6267
"@test:refactor"
68+
],
69+
"post-autoload-dump": [
70+
"@clear",
71+
"@prepare"
72+
],
73+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
74+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
75+
"build": "@php vendor/bin/testbench workbench:build --ansi",
76+
"serve": [
77+
"Composer\\Config::disableProcessTimeout",
78+
"@build",
79+
"@php vendor/bin/testbench serve --ansi"
6380
]
6481
}
65-
}
82+
}

docs/example.png

-109 KB
Binary file not shown.

phpunit.xml.dist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4-
colors="true"
5-
cacheDirectory=".phpunit.cache">
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
4+
colors="true"
5+
cacheDirectory=".phpunit.cache">
66
<source>
77
<include>
88
<directory suffix=".php">./src</directory>
99
</include>
1010
</source>
1111
<testsuites>
12-
<testsuite name="default">
13-
<directory suffix=".php">./tests</directory>
12+
<testsuite name="Feature">
13+
<directory suffix="Test.php">./tests/Feature</directory>
1414
</testsuite>
1515
</testsuites>
1616
</phpunit>

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
])
1313
->withSkip([
1414
AddOverrideAttributeToOverriddenMethodsRector::class,
15+
\Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector::class,
1516
])
1617
->withPreparedSets(
1718
deadCode: true,

src/Facades/RegistroSportESalute.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44

55
namespace CarloEusebi\RegistroSportESalute\Facades;
66

7+
use CarloEusebi\RegistroSportESalute\Organization;
8+
use Illuminate\Support\Collection;
79
use Illuminate\Support\Facades\Facade;
810

11+
/**
12+
* Facade for the RegistroSportESalute service.
13+
*
14+
* @see \CarloEusebi\RegistroSportESalute\RegistroSportESalute
15+
*
16+
* @method static \CarloEusebi\RegistroSportESalute\RegistroSportESalute builder()
17+
* @method static \CarloEusebi\RegistroSportESalute\RegistroSportESalute filterByDenominazione(?string $denominazione)
18+
* @method static \CarloEusebi\RegistroSportESalute\RegistroSportESalute filterByCodiceFiscale(?string $codiceFiscale)
19+
* @method static \CarloEusebi\RegistroSportESalute\RegistroSportESalute page(int $page = 1, int $pageSize = 10)
20+
* @method static Collection<int, Organization> get()
21+
* @method static array<string, int|string> getById(int $id)
22+
*/
923
final class RegistroSportESalute extends Facade
1024
{
1125
protected static function getFacadeAccessor(): string

src/Organization.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace CarloEusebi\RegistroSportESalute;
66

7-
use BladeUI\Icons\Components\Icon;
87
use Carbon\Carbon;
98
use Illuminate\Contracts\Support\Arrayable;
109
use JsonSerializable;
@@ -249,29 +248,29 @@ public function jsonSerialize(): array
249248
public function toArray(): array
250249
{
251250
return [
252-
'id' => $this->id,
253-
'denominazione' => $this->societa__denominazione,
254-
'id_pad' => $this->id_pad,
251+
'id' => $this->getId(),
252+
'denominazione' => $this->getDenominazione(),
253+
'id_pad' => $this->getIdPad(),
255254
'presentazione_data' => $this->getPresentazioneData()->toISOString(),
256-
'natura_giuridica' => $this->societa__natura_giuridica,
255+
'natura_giuridica' => $this->getNaturaGiuridica(),
257256
'approvazione_data' => $this->getDataApprovazione()->toISOString(),
258-
'codice_fiscale' => $this->societa__codiceFiscale,
257+
'codice_fiscale' => $this->getCodiceFiscale(),
259258
'societa_icona_vcf' => $this->getSocietaIconaVcf(),
260259
'organismi_affiliazioni_attive' => $this->getOrganismiAffiliazioniAttive(),
261-
'stato_istruttoria_descrizione' => $this->statoIstruttoria__descrizione,
262-
'utenza' => $this->utenza,
263-
'sede_legale_regione' => $this->societa__sedeLegale__regione__denominazione,
264-
'sede_legale_comune' => $this->societa__sedeLegale__comune__denominazione,
265-
'affiliazione_scaduta_organismo_icona' => $this->affiliazione_scaduta_organismo_icona,
266-
'richiesta_integrazioni_prima_data' => $this->richiestaIntegrazioni_prima_data,
267-
'richiesta_integrazioni_ultima_data' => $this->richiestaIntegrazioni_ultima_data,
268-
'invio_integrazioni_prima_data' => $this->invioIntegrazioni_prima_data,
269-
'invio_integrazioni_ultima_data' => $this->invioIntegrazioni_ultima_data,
270-
'richiesta_aggiornamenti_ultima_data' => $this->richiestaAggiornamenti_ultima_data,
271-
'richiesta_aggiornamenti_icona' => $this->richiestaAggiornamenti_icona,
272-
'invio_aggiornamenti_ultima_data' => $this->invioAggiornamenti_ultima_data,
273-
'tipo_istruttoria' => $this->tipoIstruttoria,
274-
'stato_istruttoria_icona' => $this->statoIstruttoria_icona,
260+
'stato_istruttoria_descrizione' => $this->getStatoIstruttoriaDescrizione(),
261+
'utenza' => $this->getUtenza(),
262+
'sede_legale_regione' => $this->getRegioneSedeLegale(),
263+
'sede_legale_comune' => $this->getComuneSedeLegale(),
264+
'affiliazione_scaduta_organismo_icona' => $this->getAffiliazioneSCadutaOrganismoIcona(),
265+
'richiesta_integrazioni_prima_data' => $this->getRichiestaIntegrazioniPrimaData(),
266+
'richiesta_integrazioni_ultima_data' => $this->getRichiestaAggiornamentiUltimaData(),
267+
'invio_integrazioni_prima_data' => $this->getInvioIntegrazioniPrimaData(),
268+
'invio_integrazioni_ultima_data' => $this->getInvioIntegrazioniUltimaData(),
269+
'richiesta_aggiornamenti_ultima_data' => $this->getRichiestaIntegrazioniUltimaData(),
270+
'richiesta_aggiornamenti_icona' => $this->getRichiestaAggiornamentiIcona(),
271+
'invio_aggiornamenti_ultima_data' => $this->getInvioAggiornamentiUltimaData(),
272+
'tipo_istruttoria' => $this->getTipoIstruttoria(),
273+
'stato_istruttoria_icona' => $this->getStatoIstruttoriaIcona(),
275274
];
276275
}
277276
}

src/RegistroSportESalute.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,10 @@ public function filterByCodiceFiscale(?string $codiceFiscale): self
6868
return $this;
6969
}
7070

71-
public function page(int $page): self
71+
public function page(int $page = 1, int $pageSize = 10): self
7272
{
73-
$this->start = ($page - 1) * $this->length;
74-
75-
return $this;
76-
}
77-
78-
public function pageSize(int $length): self
79-
{
80-
$page = ($this->start / $length) + 1;
81-
$this->length = $length;
82-
83-
$this->page($page);
73+
$this->start = ($page - 1) * $pageSize;
74+
$this->length = $pageSize;
8475

8576
return $this;
8677
}
@@ -93,7 +84,7 @@ public function pageSize(int $length): self
9384
public function get(): Collection
9485
{
9586
$key = 'registro-sport-e-salute.list.';
96-
$key .= md5(json_encode([$this->filters, $this->start, $this->length, $this->orderBy], JSON_THROW_ON_ERROR));
87+
$key .= md5((string) json_encode([$this->filters, $this->start, $this->length, $this->orderBy]));
9788

9889
// @phpstan-ignore-next-line
9990
return Cache::remember($key, Carbon::now()->addMinutes(5), function () {
@@ -106,7 +97,7 @@ public function get(): Collection
10697
'order_by' => $this->orderBy,
10798
...$this->filters,
10899
])
109-
->throw()
100+
->throwUnlessStatus(200)
110101
->json();
111102

112103
return collect($res['payload']['data'])
@@ -128,7 +119,7 @@ public function getById(int $id): array
128119
'chiamante' => 'registroPubblico_n',
129120
])
130121

131-
->throw()
122+
->throwUnlessStatus(200)
132123
->json();
133124

134125
return Arr::mapWithKeys($res['payload']['corpo']['dati'], fn (array $dato) => [$dato['label'] => $dato['value']]);

tests/ExampleTest.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)