UPDATE
This commit is contained in:
@@ -1,114 +1,41 @@
|
||||
# Testing
|
||||
|
||||
## Setup
|
||||
Last refresh: 2026-05-18.
|
||||
|
||||
- **Framework:** PHPUnit 11.5
|
||||
- **Config:** `phpunit.xml`
|
||||
- **Bootstrap:** `tests/bootstrap.php` (PSR-4 autoloader for `Tests\` namespace)
|
||||
- **Run:** `composer test` → `vendor/bin/phpunit -c phpunit.xml --testdox`
|
||||
- **Helper:** `dg/bypass-finals` — allows mocking `final` classes
|
||||
## Framework
|
||||
|
||||
## PHPUnit Configuration
|
||||
- Test framework: PHPUnit 11.5 through `phpunit.xml`.
|
||||
- Bootstrap: `tests/bootstrap.php`.
|
||||
- Test namespace: `Tests\\`.
|
||||
- Test location: `tests/Unit/`.
|
||||
- `DG\\BypassFinals::enable()` is enabled in `tests/bootstrap.php` for mocking final classes.
|
||||
- PHPUnit fails on warnings and risky tests.
|
||||
|
||||
```xml
|
||||
<phpunit bootstrap="tests/bootstrap.php"
|
||||
cacheDirectory="storage/cache/phpunit"
|
||||
colors="true"
|
||||
executionOrder="depends,defects"
|
||||
failOnWarning="true"
|
||||
failOnRisky="true">
|
||||
```
|
||||
## Commands
|
||||
|
||||
## Test Files (`tests/Unit/`)
|
||||
- Full PHP suite: `composer test`.
|
||||
- Direct PHPUnit: `vendor/bin/phpunit -c phpunit.xml --testdox`.
|
||||
- Frontend assets: `npm run build:assets`.
|
||||
- `npm test` is a placeholder that exits with an error.
|
||||
|
||||
| File | Subject | Coverage |
|
||||
|------|---------|---------|
|
||||
| `AllegroOrderImportServiceTest.php` | `AllegroOrderImportService` | Import, retry on 401, empty ID guard |
|
||||
| `AllegroShipmentServiceTest.php` | `AllegroShipmentService` | Shipment creation |
|
||||
| `AllegroStatusSyncServiceTest.php` | `AllegroStatusSyncService` | Status sync |
|
||||
| `AllegroTokenManagerTest.php` | `AllegroTokenManager` | Token refresh |
|
||||
| `ApaczkaShipmentServiceTest.php` | `ApaczkaShipmentService` | Apaczka API calls |
|
||||
| `AutomationServiceTest.php` | `AutomationService` | Email-once guard, condition evaluation |
|
||||
| `DeliveryStatusTest.php` | Delivery status mapping | Status translation |
|
||||
## Existing Coverage Shape
|
||||
|
||||
**No repository, controller, or view tests exist** — only service-layer unit tests.
|
||||
- Services/mappers/repositories: `tests/Unit/ErliOrdersSyncServiceTest.php`, `tests/Unit/ErliOrderMapperTest.php`, `tests/Unit/FakturowniaInvoiceIdempotencyTest.php`, `tests/Unit/OrdersStatisticsRepositoryTest.php`.
|
||||
- Shipping/integration services: `tests/Unit/AllegroShipmentServiceTest.php`, `tests/Unit/ApaczkaShipmentServiceTest.php`, `tests/Unit/PolkurierShipmentServiceTest.php`.
|
||||
- Security/config: `tests/Unit/SmtpSecurityContextFactoryTest.php`, `tests/Unit/AllegroTokenManagerTest.php`.
|
||||
- View-rendering style check: `tests/Unit/ShipmentPreparePolkurierMappingTest.php`.
|
||||
|
||||
## Test Patterns
|
||||
## Gaps
|
||||
|
||||
### Mock Setup
|
||||
- No dedicated browser/e2e suite found.
|
||||
- No frontend JS test suite found for `public/assets/js/modules/*.js`.
|
||||
- No controller HTTP integration test suite found for `routes/web.php` and controllers.
|
||||
- No migration integration test suite found for `database/migrations/`.
|
||||
- Windows print client under `clients/windows/OrderPROPrint/` has no obvious automated tests.
|
||||
|
||||
```php
|
||||
final class AllegroOrderImportServiceTest extends TestCase {
|
||||
private AllegroIntegrationRepository&MockObject $integrationRepository;
|
||||
private AllegroApiClient&MockObject $apiClient;
|
||||
## Practical Verification Guidance
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->apiClient = $this->createMock(AllegroApiClient::class);
|
||||
$this->service = new AllegroOrderImportService(
|
||||
$this->integrationRepository, $this->tokenManager, $this->apiClient, ...
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Behavior Verification
|
||||
|
||||
```php
|
||||
$this->emailOnceRepository
|
||||
->expects($this->exactly(2))
|
||||
->method('wasSent')
|
||||
->willReturnOnConsecutiveCalls(false, true);
|
||||
|
||||
$this->emailService
|
||||
->expects($this->once())
|
||||
->method('send');
|
||||
```
|
||||
|
||||
### Exception Testing
|
||||
|
||||
```php
|
||||
$this->expectException(AllegroApiException::class);
|
||||
$this->expectExceptionMessage('Podaj ID zamowienia');
|
||||
$this->service->importSingleOrder('');
|
||||
```
|
||||
|
||||
### Retry Logic Testing
|
||||
|
||||
```php
|
||||
$callCount = 0;
|
||||
$this->apiClient->method('getCheckoutForm')
|
||||
->willReturnCallback(function () use (&$callCount): array {
|
||||
if (++$callCount === 1) {
|
||||
throw new RuntimeException('ALLEGRO_HTTP_401');
|
||||
}
|
||||
return $payload;
|
||||
});
|
||||
|
||||
$this->service->importSingleOrder($id);
|
||||
$this->assertSame(2, $callCount); // retry happened
|
||||
```
|
||||
|
||||
### Test Data Builders
|
||||
|
||||
```php
|
||||
private function buildMinimalPayload(string $id): array {
|
||||
return [
|
||||
'id' => $id,
|
||||
'status' => 'READY_FOR_PROCESSING',
|
||||
'payment' => ['id' => 'pay-1', 'type' => 'allegro', ...],
|
||||
// all required nested fields
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
## What Is Not Tested
|
||||
|
||||
- Controllers (no HTTP integration tests)
|
||||
- Repositories (no DB integration tests — no test database configured)
|
||||
- Views (no rendering tests)
|
||||
- Cron handlers
|
||||
- Migration scripts
|
||||
|
||||
## Manual UAT
|
||||
|
||||
Phase summaries note manual UAT steps after feature implementation (e.g., Phase 104 — Apaczka weekend delivery tested via UI). No documented UAT scripts or Postman collections.
|
||||
- For narrow service/repository changes, run the nearest `tests/Unit/*Test.php` first.
|
||||
- For shared behavior, integration wiring, or risky changes, run `composer test`.
|
||||
- For UI/SCSS changes, run `npm run build:assets` and manually verify the affected view.
|
||||
- For cron/integration work, test the target service/repository and smoke the relevant handler in `src/Modules/Cron/`.
|
||||
|
||||
Reference in New Issue
Block a user