diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 35acac9..c9157a8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -11,14 +11,10 @@ jobs: strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.2" deps: - "normal" - include: - - deps: "low" - php-version: "7.4" + - "low" steps: - name: "Checkout" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 7f7fb9d..f744fb4 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,9 +11,7 @@ jobs: strategy: matrix: php-version: - - "7.4" - - "8.0" - - "8.1" + - "8.2" steps: - name: "Checkout" uses: "actions/checkout@v2" diff --git a/.gitignore b/.gitignore index c4e8084..adbc2ea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock /.idea /.env* +/.phpunit.cache diff --git a/composer.json b/composer.json index e9f7a2b..d6a01fd 100755 --- a/composer.json +++ b/composer.json @@ -4,25 +4,23 @@ "type": "symfony-bundle", "license": "MIT", "require": { - "php": ">=7.4|^8.0", + "php": "^8.2", "ext-json": "*", "guzzlehttp/guzzle": "^6.0|^7.0", - "marc-mabe/php-enum": "^3.0|^4.3", - "psr/log": "^1.0", - "symfony/http-kernel": "^5.4|^6.0|^6.4", - "symfony/property-info": "^5.4|^6.0|^6.4", - "symfony/serializer": "^5.4|^6.0|^6.4", - "webmozart/assert": "^1.10" + "psr/log": "^1.1", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/property-info": "^6.4|^7.0", + "symfony/serializer": "^6.4|^7.0", + "webmozart/assert": "^1.11" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.58", - "matthiasnoback/symfony-config-test": "^4.3", + "friendsofphp/php-cs-fixer": "^3.64", "phpro/grumphp": "^1.5.0|^2.5", "phpstan/phpstan": "^1.11", "phpstan/phpstan-webmozart-assert": "^1.0", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^10.5", "roave/security-advisories": "dev-master", - "symfony/phpunit-bridge": "6.4.*" + "symfony/phpunit-bridge": "6.4.*|^7.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 50e5a10..12bcc5f 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,21 @@ + - ./tests - - - - diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index be5c6f5..8b63ac2 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -6,37 +6,24 @@ use Answear\AcsBundle\Request\BaseInputParameters; -class ConfigProvider +readonly class ConfigProvider { private const API_URL = 'https://webservices.acscourier.net/ACSRestServices/api/ACSAutoRest'; - private string $apiKey; - private string $companyId; - private string $companyPassword; - private string $userId; - private string $userPassword; - private string $language; - public function __construct( - string $apiKey, - string $companyId, - string $companyPassword, - string $userId, - string $userPassword, - string $language + private string $apiKey, + private string $companyId, + private string $companyPassword, + private string $userId, + private string $userPassword, + private string $language, ) { - $this->apiKey = $apiKey; - $this->companyId = $companyId; - $this->companyPassword = $companyPassword; - $this->userId = $userId; - $this->userPassword = $userPassword; - $this->language = $language; } public function getRequestHeaders(): array { return [ - 'AcsApiKey' => $this->getApiKey(), + 'AcsApiKey' => $this->apiKey, 'Content-Type' => 'application/json', ]; } @@ -50,9 +37,4 @@ public function getUrl(): string { return self::API_URL; } - - private function getApiKey(): string - { - return $this->apiKey; - } } diff --git a/src/Enum/CountryIdEnum.php b/src/Enum/CountryIdEnum.php index 7a91233..d109ce1 100644 --- a/src/Enum/CountryIdEnum.php +++ b/src/Enum/CountryIdEnum.php @@ -4,20 +4,8 @@ namespace Answear\AcsBundle\Enum; -use MabeEnum\Enum; - -class CountryIdEnum extends Enum +enum CountryIdEnum: string { - public const GREECE = 'GR'; - public const CYPRUS = 'CY'; - - public static function greece(): self - { - return static::get(static::GREECE); - } - - public static function cyprus(): self - { - return static::get(static::CYPRUS); - } + case Greece = 'GR'; + case Cyprus = 'CY'; } diff --git a/src/Request/BaseInputParameters.php b/src/Request/BaseInputParameters.php index bbbcd56..80eaf68 100644 --- a/src/Request/BaseInputParameters.php +++ b/src/Request/BaseInputParameters.php @@ -6,19 +6,13 @@ class BaseInputParameters { - protected string $companyId; - protected string $companyPassword; - protected string $userId; - protected string $userPassword; - protected string $language; - - public function __construct(string $companyId, string $companyPassword, string $userId, string $userPassword, string $language) - { - $this->companyId = $companyId; - $this->companyPassword = $companyPassword; - $this->userId = $userId; - $this->userPassword = $userPassword; - $this->language = $language; + public function __construct( + protected string $companyId, + protected string $companyPassword, + protected string $userId, + protected string $userPassword, + protected string $language, + ) { } public function toArray(): array diff --git a/src/Request/StationsRequest.php b/src/Request/StationsRequest.php index edff47f..62ec1b0 100644 --- a/src/Request/StationsRequest.php +++ b/src/Request/StationsRequest.php @@ -10,30 +10,29 @@ class StationsRequest implements Request { private const ALIAS = 'ACS_Stations'; - private BaseInputParameters $baseInputParameters; - private CountryIdEnum $countryId; - private ?int $kind; - - public function __construct(BaseInputParameters $baseInputParameters, CountryIdEnum $countryId, ?int $kind = null) - { - $this->baseInputParameters = $baseInputParameters; - $this->countryId = $countryId; - $this->kind = $kind; + public function __construct( + private readonly BaseInputParameters $baseInputParameters, + private readonly CountryIdEnum $countryId, + private readonly ?int $kind = null, + ) { } public function toJson(): string { $parameters = [ - 'ACS_SHOP_COUNTRY_ID' => $this->countryId->getValue(), + 'ACS_SHOP_COUNTRY_ID' => $this->countryId->value, ]; if (null !== $this->kind) { $parameters['ACS_SHOP_KIND'] = $this->kind; } - return json_encode([ - 'ACSAlias' => self::ALIAS, - 'ACSInputParameters' => array_merge($parameters, $this->baseInputParameters->toArray()), - ], JSON_THROW_ON_ERROR); + return json_encode( + [ + 'ACSAlias' => self::ALIAS, + 'ACSInputParameters' => array_merge($parameters, $this->baseInputParameters->toArray()), + ], + JSON_THROW_ON_ERROR + ); } } diff --git a/src/Response/DTO/Address.php b/src/Response/DTO/Address.php index 5ae1885..2992f91 100644 --- a/src/Response/DTO/Address.php +++ b/src/Response/DTO/Address.php @@ -6,29 +6,16 @@ use Webmozart\Assert\Assert; -class Address +readonly class Address { - private string $street; - private string $zipCode; - private string $city; - private string $phones; - private string $email; - private string $fax; - public function __construct( - string $street, - string $zipCode, - string $city, - string $phones, - string $email, - string $fax + public string $street, + public string $zipCode, + public string $city, + public string $phones, + public string $email, + public string $fax, ) { - $this->street = $street; - $this->zipCode = $zipCode; - $this->city = $city; - $this->phones = $phones; - $this->email = $email; - $this->fax = $fax; } public static function fromArray(array $parcelShopArray): self @@ -49,34 +36,4 @@ public static function fromArray(array $parcelShopArray): self $parcelShopArray['ACS_SHOP_FAX'] ); } - - public function getZipCode(): string - { - return $this->zipCode; - } - - public function getCity(): string - { - return $this->city; - } - - public function getStreet(): string - { - return $this->street; - } - - public function getFax(): ?string - { - return $this->fax; - } - - public function getPhones(): ?string - { - return $this->phones; - } - - public function getEmail(): ?string - { - return $this->email; - } } diff --git a/src/Response/DTO/Coordinates.php b/src/Response/DTO/Coordinates.php index 9d0296f..6d353a1 100644 --- a/src/Response/DTO/Coordinates.php +++ b/src/Response/DTO/Coordinates.php @@ -8,16 +8,12 @@ class Coordinates { - public float $latitude; - public float $longitude; - - public function __construct(float $latitude, float $longitude) - { + public function __construct( + public float $latitude, + public float $longitude, + ) { Assert::range($latitude, -90, 90); Assert::range($longitude, -180, 180); - - $this->latitude = $latitude; - $this->longitude = $longitude; } public static function fromArray(array $parcelShopArray): self diff --git a/src/Response/DTO/ParcelShop.php b/src/Response/DTO/ParcelShop.php index 03434ab..6959b2c 100644 --- a/src/Response/DTO/ParcelShop.php +++ b/src/Response/DTO/ParcelShop.php @@ -6,80 +6,33 @@ use Webmozart\Assert\Assert; -class ParcelShop +readonly class ParcelShop { - private int $countryId; - private string $countryDescription; - private int $areaId; - private string $areaDescription; - private string $stationId; - private string $stationIdEn; - private string $stationDescription; - private int $branchId; - private string $workingHours; - private string $workingHoursSaturday; - private string $truckPickupHours; - private string $truckPickupHoursSaturday; - private string $deliveryStartHour; - private int $coordinatesVerified; - private int $kind; - private string $services; - private string $paymentTypes; - private string $idCode; - private string $smartpointKind; - private string $workingHoursJson; - private string $message; - private Address $address; - private Coordinates $coordinates; - public function __construct( - int $countryId, - string $countryDescription, - int $areaId, - string $areaDescription, - string $stationId, - string $stationIdEn, - string $stationDescription, - int $branchId, - string $workingHours, - string $workingHoursSaturday, - string $truckPickupHours, - string $truckPickupHoursSaturday, - string $deliveryStartHour, - int $coordinatesVerified, - int $kind, - string $services, - string $paymentTypes, - string $idCode, - string $smartpointKind, - string $workingHoursJson, - string $message, - Address $address, - Coordinates $coordinates + public int $countryId, + public string $countryDescription, + public int $areaId, + public string $areaDescription, + public string $stationId, + public string $stationIdEn, + public string $stationDescription, + public int $branchId, + public string $workingHours, + public string $workingHoursSaturday, + public string $truckPickupHours, + public string $truckPickupHoursSaturday, + public string $deliveryStartHour, + public int $coordinatesVerified, + public int $kind, + public string $services, + public string $paymentTypes, + public string $idCode, + public string $smartpointKind, + public string $workingHoursJson, + public string $message, + public Address $address, + public Coordinates $coordinates, ) { - $this->countryId = $countryId; - $this->countryDescription = $countryDescription; - $this->areaId = $areaId; - $this->areaDescription = $areaDescription; - $this->stationId = $stationId; - $this->stationIdEn = $stationIdEn; - $this->stationDescription = $stationDescription; - $this->branchId = $branchId; - $this->workingHours = $workingHours; - $this->workingHoursSaturday = $workingHoursSaturday; - $this->truckPickupHours = $truckPickupHours; - $this->truckPickupHoursSaturday = $truckPickupHoursSaturday; - $this->deliveryStartHour = $deliveryStartHour; - $this->coordinatesVerified = $coordinatesVerified; - $this->kind = $kind; - $this->services = $services; - $this->paymentTypes = $paymentTypes; - $this->idCode = $idCode; - $this->smartpointKind = $smartpointKind; - $this->workingHoursJson = $workingHoursJson; - $this->message = $message; - $this->address = $address; - $this->coordinates = $coordinates; } public static function fromArray(array $parcelShopArray): self @@ -132,119 +85,4 @@ public static function fromArray(array $parcelShopArray): self Coordinates::fromArray($parcelShopArray) ); } - - public function getCountryId(): int - { - return $this->countryId; - } - - public function getCountryDescription(): string - { - return $this->countryDescription; - } - - public function getAreaId(): int - { - return $this->areaId; - } - - public function getAreaDescription(): string - { - return $this->areaDescription; - } - - public function getStationId(): string - { - return $this->stationId; - } - - public function getStationIdEn(): string - { - return $this->stationIdEn; - } - - public function getStationDescription(): string - { - return $this->stationDescription; - } - - public function getBranchId(): int - { - return $this->branchId; - } - - public function getWorkingHours(): string - { - return $this->workingHours; - } - - public function getWorkingHoursSaturday(): string - { - return $this->workingHoursSaturday; - } - - public function getTruckPickupHours(): string - { - return $this->truckPickupHours; - } - - public function getTruckPickupHoursSaturday(): string - { - return $this->truckPickupHoursSaturday; - } - - public function getDeliveryStartHour(): string - { - return $this->deliveryStartHour; - } - - public function getCoordinatesVerified(): int - { - return $this->coordinatesVerified; - } - - public function getKind(): int - { - return $this->kind; - } - - public function getServices(): string - { - return $this->services; - } - - public function getPaymentTypes(): string - { - return $this->paymentTypes; - } - - public function getIdCode(): string - { - return $this->idCode; - } - - public function getSmartpointKind(): string - { - return $this->smartpointKind; - } - - public function getWorkingHoursJson(): string - { - return $this->workingHoursJson; - } - - public function getMessage(): string - { - return $this->message; - } - - public function getAddress(): Address - { - return $this->address; - } - - public function getCoordinates(): Coordinates - { - return $this->coordinates; - } } diff --git a/src/Response/StationsResponse.php b/src/Response/StationsResponse.php index 66c3296..2509418 100644 --- a/src/Response/StationsResponse.php +++ b/src/Response/StationsResponse.php @@ -10,18 +10,13 @@ class StationsResponse { - /** - * @var ParcelShop[] - */ - private array $parcelShops; - /** * @param ParcelShop[] $parcelShops */ - public function __construct(array $parcelShops) - { + public function __construct( + public array $parcelShops, + ) { Assert::allIsInstanceOf($parcelShops, ParcelShop::class); - $this->parcelShops = $parcelShops; } public static function fromArray(array $response): StationsResponse @@ -44,12 +39,4 @@ static function ($item) { throw new MalformedResponse($e->getMessage(), $response, $e); } } - - /** - * @return ParcelShop[] - */ - public function getParcelShops(): array - { - return $this->parcelShops; - } } diff --git a/src/Service/Client.php b/src/Service/Client.php index 571c622..c4bf9e3 100644 --- a/src/Service/Client.php +++ b/src/Service/Client.php @@ -19,12 +19,12 @@ class Client private const CONNECTION_TIMEOUT = 10; private const TIMEOUT = 30; - protected ConfigProvider $configProvider; protected ClientInterface $guzzle; - public function __construct(ConfigProvider $configProvider, ?ClientInterface $client = null) - { - $this->configProvider = $configProvider; + public function __construct( + protected ConfigProvider $configProvider, + ?ClientInterface $client = null, + ) { $this->guzzle = $client ?? new \GuzzleHttp\Client(['timeout' => self::TIMEOUT, 'connect_timeout' => self::CONNECTION_TIMEOUT]); } diff --git a/src/Service/ParcelShopsService.php b/src/Service/ParcelShopsService.php index 4a872ca..f34a87d 100644 --- a/src/Service/ParcelShopsService.php +++ b/src/Service/ParcelShopsService.php @@ -11,11 +11,9 @@ class ParcelShopsService { - private Client $client; - - public function __construct(Client $client) - { - $this->client = $client; + public function __construct( + private Client $client, + ) { } /** @@ -25,6 +23,6 @@ public function getList(CountryIdEnum $countryId, ?int $kind = null): array { $response = $this->client->request(new StationsRequest($this->client->getBaseInputParameters(), $countryId, $kind)); - return StationsResponse::fromArray($response)->getParcelShops(); + return StationsResponse::fromArray($response)->parcelShops; } } diff --git a/tests/Integration/Service/ParcelShopsServiceTest.php b/tests/Integration/Service/ParcelShopsServiceTest.php index dc31a81..5423b03 100644 --- a/tests/Integration/Service/ParcelShopsServiceTest.php +++ b/tests/Integration/Service/ParcelShopsServiceTest.php @@ -12,6 +12,7 @@ use Answear\AcsBundle\Tests\Unit\Response\StationsResponseTrait; use Answear\AcsBundle\Tests\Util\FileTestUtil; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class ParcelShopsServiceTest extends TestCase @@ -36,12 +37,9 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function successfulGetParcelShop(): void { - $parcelShops = FileTestUtil::decodeJsonFromFile(__DIR__ . '/data/parcelShops.json'); $this->client = $this->getClient(); $service = $this->getService(); @@ -49,7 +47,7 @@ public function successfulGetParcelShop(): void new Response(200, [], FileTestUtil::getFileContents(__DIR__ . '/data/parcelShops.json')) ); - $result = $service->getList(CountryIdEnum::cyprus()); + $result = $service->getList(CountryIdEnum::Cyprus); $this->assertEquals($this->getExpectedParcelShops(), $result); } diff --git a/tests/MockGuzzleTrait.php b/tests/MockGuzzleTrait.php index 611e33c..ecacdb2 100644 --- a/tests/MockGuzzleTrait.php +++ b/tests/MockGuzzleTrait.php @@ -27,7 +27,7 @@ public function setupGuzzleClient(): Client return new Client(['handler' => $handlerStack]); } - public function mockGuzzleResponse(Response $response) + public function mockGuzzleResponse(Response $response): void { $this->guzzleHandler->append($response); } diff --git a/tests/Unit/ConfigProviderTest.php b/tests/Unit/ConfigProviderTest.php index 4f96d4d..e9ffa43 100644 --- a/tests/Unit/ConfigProviderTest.php +++ b/tests/Unit/ConfigProviderTest.php @@ -5,6 +5,7 @@ namespace Answear\AcsBundle\Tests\Unit; use Answear\AcsBundle\ConfigProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class ConfigProviderTest extends TestCase @@ -25,9 +26,7 @@ public function setUp(): void ); } - /** - * @test - */ + #[Test] public function returnsCorrectRequestHeaders(): void { self::assertSame( @@ -39,9 +38,7 @@ public function returnsCorrectRequestHeaders(): void ); } - /** - * @test - */ + #[Test] public function returnCorrectBaseInputParameters(): void { self::assertEquals( @@ -52,6 +49,7 @@ public function returnCorrectBaseInputParameters(): void 'User_Password' => 'userPassword', 'language' => 'EN', ], - $this->configProvider->getBaseInputParameters()->toArray()); + $this->configProvider->getBaseInputParameters()->toArray() + ); } } diff --git a/tests/Unit/Request/BaseInputParametersTest.php b/tests/Unit/Request/BaseInputParametersTest.php index f75b35b..4cefab3 100644 --- a/tests/Unit/Request/BaseInputParametersTest.php +++ b/tests/Unit/Request/BaseInputParametersTest.php @@ -5,13 +5,12 @@ namespace Answear\AcsBundle\Tests\Unit\Request; use Answear\AcsBundle\Request\BaseInputParameters; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class BaseInputParametersTest extends TestCase { - /** - * @test - */ + #[Test] public function returnCorrectArray(): void { $baseInputParameters = new BaseInputParameters('companyId', 'companyPassword', 'userId', 'userPassword', 'EN'); diff --git a/tests/Unit/Request/StationsRequestTest.php b/tests/Unit/Request/StationsRequestTest.php index 6d2b0c7..77f96a8 100644 --- a/tests/Unit/Request/StationsRequestTest.php +++ b/tests/Unit/Request/StationsRequestTest.php @@ -7,17 +7,16 @@ use Answear\AcsBundle\Enum\CountryIdEnum; use Answear\AcsBundle\Request\BaseInputParameters; use Answear\AcsBundle\Request\StationsRequest; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class StationsRequestTest extends TestCase { - /** - * @test - */ + #[Test] public function returnCorrectJson(): void { $baseInputParameters = new BaseInputParameters('companyId', 'companyPassword', 'userId', 'userPassword', 'EN'); - $stationsRequest = new StationsRequest($baseInputParameters, CountryIdEnum::greece(), 1); + $stationsRequest = new StationsRequest($baseInputParameters, CountryIdEnum::Greece, 1); self::assertSame( '{"ACSAlias":"ACS_Stations","ACSInputParameters":{"ACS_SHOP_COUNTRY_ID":"GR","ACS_SHOP_KIND":1,"Company_ID":"companyId","Company_Password":"companyPassword","User_ID":"userId","User_Password":"userPassword","language":"EN"}}', @@ -25,13 +24,11 @@ public function returnCorrectJson(): void ); } - /** - * @test - */ + #[Test] public function returnCorrectJsonWithoutKind(): void { $baseInputParameters = new BaseInputParameters('companyId', 'companyPassword', 'userId', 'userPassword', 'EN'); - $stationsRequest = new StationsRequest($baseInputParameters, CountryIdEnum::greece()); + $stationsRequest = new StationsRequest($baseInputParameters, CountryIdEnum::Greece); self::assertSame( '{"ACSAlias":"ACS_Stations","ACSInputParameters":{"ACS_SHOP_COUNTRY_ID":"GR","Company_ID":"companyId","Company_Password":"companyPassword","User_ID":"userId","User_Password":"userPassword","language":"EN"}}', diff --git a/tests/Unit/Response/DTO/AddressTest.php b/tests/Unit/Response/DTO/AddressTest.php index c0cf2da..623b746 100644 --- a/tests/Unit/Response/DTO/AddressTest.php +++ b/tests/Unit/Response/DTO/AddressTest.php @@ -6,6 +6,7 @@ use Answear\AcsBundle\Response\DTO\Address; use Answear\AcsBundle\Tests\Unit\Response\StationsResponseTrait; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Webmozart\Assert\InvalidArgumentException; @@ -13,9 +14,7 @@ class AddressTest extends TestCase { use StationsResponseTrait; - /** - * @test - */ + #[Test] public function correctlyReturnsAddress(): void { $address = Address::fromArray($this->getCorrectResponseItemArray()); @@ -26,9 +25,7 @@ public function correctlyReturnsAddress(): void ); } - /** - * @test - */ + #[Test] public function throwsErrorWhenDataNotComplete(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/Response/DTO/CoordinatesTest.php b/tests/Unit/Response/DTO/CoordinatesTest.php index 16189bc..d3c0cae 100644 --- a/tests/Unit/Response/DTO/CoordinatesTest.php +++ b/tests/Unit/Response/DTO/CoordinatesTest.php @@ -6,6 +6,7 @@ use Answear\AcsBundle\Response\DTO\Coordinates; use Answear\AcsBundle\Tests\Unit\Response\StationsResponseTrait; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Webmozart\Assert\InvalidArgumentException; @@ -13,9 +14,7 @@ class CoordinatesTest extends TestCase { use StationsResponseTrait; - /** - * @test - */ + #[Test] public function correctlyReturnsCoordinates(): void { $coordinates = Coordinates::fromArray($this->getCorrectResponseItemArray()); @@ -26,9 +25,7 @@ public function correctlyReturnsCoordinates(): void ); } - /** - * @test - */ + #[Test] public function throwsErrorWhenDataNotComplete(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/Response/DTO/ParcelShopTest.php b/tests/Unit/Response/DTO/ParcelShopTest.php index 772ccae..a3f35d9 100644 --- a/tests/Unit/Response/DTO/ParcelShopTest.php +++ b/tests/Unit/Response/DTO/ParcelShopTest.php @@ -7,6 +7,7 @@ use Answear\AcsBundle\Response\DTO\Address; use Answear\AcsBundle\Response\DTO\ParcelShop; use Answear\AcsBundle\Tests\Unit\Response\StationsResponseTrait; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Webmozart\Assert\InvalidArgumentException; @@ -14,9 +15,7 @@ class ParcelShopTest extends TestCase { use StationsResponseTrait; - /** - * @test - */ + #[Test] public function correctlyReturnsParcelShop(): void { $parcelShop = ParcelShop::fromArray($this->getCorrectResponseItemArray()); @@ -27,9 +26,7 @@ public function correctlyReturnsParcelShop(): void ); } - /** - * @test - */ + #[Test] public function throwsErrorWhenDataNotComplete(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/Response/StationsResponseTest.php b/tests/Unit/Response/StationsResponseTest.php index cc4be9e..a7bc4bc 100644 --- a/tests/Unit/Response/StationsResponseTest.php +++ b/tests/Unit/Response/StationsResponseTest.php @@ -6,15 +6,14 @@ use Answear\AcsBundle\Exception\MalformedResponse; use Answear\AcsBundle\Response\StationsResponse; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class StationsResponseTest extends TestCase { use StationsResponseTrait; - /** - * @test - */ + #[Test] public function correctlyReturnsStationsResponse(): void { $stationsResponse = StationsResponse::fromArray($this->getArrayForStationsResponse()); @@ -25,33 +24,27 @@ public function correctlyReturnsStationsResponse(): void ); } - /** - * @test - */ + #[Test] public function throwsErrorWhenResponseWithoutACSTableOutput(): void { $this->expectException(MalformedResponse::class); - $this->expectErrorMessage('Expected the key "ACSTableOutput" to exist.'); + $this->expectExceptionMessage('Expected the key "ACSTableOutput" to exist.'); StationsResponse::fromArray([]); } - /** - * @test - */ + #[Test] public function throwsErrorWhenResponseWithoutTableData(): void { $this->expectException(MalformedResponse::class); - $this->expectErrorMessage('Expected the key "Table_Data" to exist.'); + $this->expectExceptionMessage('Expected the key "Table_Data" to exist.'); StationsResponse::fromArray(['ACSTableOutput' => []]); } - /** - * @test - */ + #[Test] public function throwsErrorWhenResponseWithIncorrectItems(): void { $this->expectException(MalformedResponse::class); - $this->expectErrorMessage('Expected the key "ACS_SHOP_COUNTRY_ID'); + $this->expectExceptionMessage('Expected the key "ACS_SHOP_COUNTRY_ID'); StationsResponse::fromArray( [ 'ACSTableOutput' => [ diff --git a/tests/Unit/Service/ClientTest.php b/tests/Unit/Service/ClientTest.php index a6b1e0b..67a1e69 100644 --- a/tests/Unit/Service/ClientTest.php +++ b/tests/Unit/Service/ClientTest.php @@ -12,6 +12,7 @@ use Answear\AcsBundle\Service\Client; use Answear\AcsBundle\Tests\MockGuzzleTrait; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; class ClientTest extends TestCase @@ -37,15 +38,15 @@ public function setUp(): void ); $this->client = new Client($configProvider, $this->setupGuzzleClient()); - $this->stationsRequest = new StationsRequest($configProvider->getBaseInputParameters(), CountryIdEnum::cyprus()); + $this->stationsRequest = new StationsRequest($configProvider->getBaseInputParameters(), CountryIdEnum::Cyprus); } - /** - * @test - */ + #[Test] public function properResponse(): void { - $this->guzzleHandler->append(new Response(200, [], '{"ACSExecution_HasError":false,"ACSExecutionErrorMessage":"","ACSOutputResponce":{"ACSTableOutput":{}}}')); + $this->guzzleHandler->append( + new Response(200, [], '{"ACSExecution_HasError":false,"ACSExecutionErrorMessage":"","ACSOutputResponce":{"ACSTableOutput":{}}}') + ); $result = $this->client->request($this->stationsRequest); @@ -58,12 +59,12 @@ public function properResponse(): void self::assertCount(1, $this->clientHistory); } - /** - * @test - */ + #[Test] public function responseWithExecutionErrors(): void { - $this->guzzleHandler->append(new Response(200, [], '{"ACSExecution_HasError":true,"ACSExecutionErrorMessage":"error message","ACSOutputResponce":""}')); + $this->guzzleHandler->append( + new Response(200, [], '{"ACSExecution_HasError":true,"ACSExecutionErrorMessage":"error message","ACSOutputResponce":""}') + ); $this->expectException(MalformedResponse::class); $this->expectExceptionMessage('error message'); @@ -71,9 +72,7 @@ public function responseWithExecutionErrors(): void $this->client->request($this->stationsRequest); } - /** - * @test - */ + #[Test] public function responseWithoutOutputResponce(): void { $this->guzzleHandler->append(new Response(200, [], '{"ACSExecution_HasError":false,"ACSExecutionErrorMessage":""}')); @@ -84,9 +83,7 @@ public function responseWithoutOutputResponce(): void $this->client->request($this->stationsRequest); } - /** - * @test - */ + #[Test] public function responseWithoutExecutionErrorMessage(): void { $this->guzzleHandler->append(new Response(200, [], '{"ACSExecution_HasError":false}')); @@ -97,9 +94,7 @@ public function responseWithoutExecutionErrorMessage(): void $this->client->request($this->stationsRequest); } - /** - * @test - */ + #[Test] public function responseWithoutHasError(): void { $this->guzzleHandler->append(new Response(200, [], '{}')); @@ -110,9 +105,7 @@ public function responseWithoutHasError(): void $this->client->request($this->stationsRequest); } - /** - * @test - */ + #[Test] public function responseWithoutArray(): void { $this->guzzleHandler->append(new Response(200, [], '"result":[]')); @@ -123,9 +116,7 @@ public function responseWithoutArray(): void $this->client->request($this->stationsRequest); } - /** - * @test - */ + #[Test] public function serviceUnavailable(): void { $this->guzzleHandler->append(new Response(500, [], '{}'));