From d2a5b89a2552d2a693e7efb7b062564d1931d222 Mon Sep 17 00:00:00 2001 From: Julian Finkler Date: Wed, 31 Jul 2024 13:11:40 +0200 Subject: [PATCH] feat: Add CI --- .github/workflows/php.yml | 45 +++++++++++++++++++ composer.json | 10 ++--- src/Channel/Contracts/Order.php | 1 + src/Common/Http/BaseResponse.php | 1 - src/Http/Abstraction/Uri.php | 14 +++--- .../Contracts/ProvisioningDetails.php | 2 +- .../RequestToBillbeeFailedException.php | 1 - .../Channel/Http/OrderRequestHandlerTest.php | 6 +-- .../Http/ProductRequestHandlerTest.php | 2 +- 9 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..5436627 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,45 @@ +name: PHP Composer + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP with Xdebug + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: xdebug + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Run test suite + run: composer run-script test + + - name: Run SCA + run: composer run-script phpstan + + - name: Run CS + run: composer run-script fix-cs:dry-run \ No newline at end of file diff --git a/composer.json b/composer.json index 5ddb436..2e4dab0 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "psr/http-message": "^2.0", "jms/serializer": "^3.30.0", "mintware-de/streams": "^3.0", - "ext-json": "*", "mark-gerarts/auto-mapper-plus": "^1.4", + "ext-json": "*", "ext-curl": "*" }, "require-dev": { @@ -39,12 +39,12 @@ "minimum-stability": "stable", "scripts": { "fix-cs": [ - "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2", - "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2" + "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR12", + "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR12" ], "fix-cs:dry-run": [ - "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2 --dry-run", - "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2 --dry-run" + "./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR12 --dry-run", + "./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR12 --dry-run" ], "phpstan": [ "./vendor/bin/phpstan" diff --git a/src/Channel/Contracts/Order.php b/src/Channel/Contracts/Order.php index bb7e493..4490c7f 100644 --- a/src/Channel/Contracts/Order.php +++ b/src/Channel/Contracts/Order.php @@ -68,6 +68,7 @@ class Order #[Serializer\SerializedName('orderDate')] protected DateTime $orderDate; + #[Serializer\Type("DateTimeInterface<'Y-m-d\TH:i:s'>")] #[Serializer\SerializedName('payDate')] protected ?DateTime $payDate = null; diff --git a/src/Common/Http/BaseResponse.php b/src/Common/Http/BaseResponse.php index b124a3e..508fdf6 100644 --- a/src/Common/Http/BaseResponse.php +++ b/src/Common/Http/BaseResponse.php @@ -9,7 +9,6 @@ */ class BaseResponse { - /** @param T $data */ public function __construct( #[Serializer\SerializedName('data')] diff --git a/src/Http/Abstraction/Uri.php b/src/Http/Abstraction/Uri.php index e71fd77..319496b 100644 --- a/src/Http/Abstraction/Uri.php +++ b/src/Http/Abstraction/Uri.php @@ -88,7 +88,7 @@ public function getFragment(): string } /** @inheritDoc */ - public function withScheme($scheme):self + public function withScheme($scheme): self { $uri = clone $this; $uri->scheme = $scheme; @@ -96,7 +96,7 @@ public function withScheme($scheme):self } /** @inheritDoc */ - public function withUserInfo($user, $password = null):self + public function withUserInfo($user, $password = null): self { $uri = clone $this; $uri->userInfo = implode(':', array_filter([$user, $password])); @@ -104,7 +104,7 @@ public function withUserInfo($user, $password = null):self } /** @inheritDoc */ - public function withHost($host):self + public function withHost($host): self { $uri = clone $this; $uri->host = $host; @@ -112,7 +112,7 @@ public function withHost($host):self } /** @inheritDoc */ - public function withPort($port):self + public function withPort($port): self { $uri = clone $this; $uri->port = (int)$port; @@ -120,7 +120,7 @@ public function withPort($port):self } /** @inheritDoc */ - public function withPath($path):self + public function withPath($path): self { $uri = clone $this; $uri->path = $path; @@ -128,7 +128,7 @@ public function withPath($path):self } /** @inheritDoc */ - public function withQuery($query):self + public function withQuery($query): self { $uri = clone $this; $uri->query = $query; @@ -136,7 +136,7 @@ public function withQuery($query):self } /** @inheritDoc */ - public function withFragment($fragment):self + public function withFragment($fragment): self { $uri = clone $this; $uri->fragment = $fragment; diff --git a/src/Provisioning/Contracts/ProvisioningDetails.php b/src/Provisioning/Contracts/ProvisioningDetails.php index e774583..7485112 100644 --- a/src/Provisioning/Contracts/ProvisioningDetails.php +++ b/src/Provisioning/Contracts/ProvisioningDetails.php @@ -85,6 +85,6 @@ public function setSubsystems(array $subsystems): ProvisioningDetails return $this; } - + } diff --git a/src/Provisioning/Exception/RequestToBillbeeFailedException.php b/src/Provisioning/Exception/RequestToBillbeeFailedException.php index c9b2bca..1385cb4 100644 --- a/src/Provisioning/Exception/RequestToBillbeeFailedException.php +++ b/src/Provisioning/Exception/RequestToBillbeeFailedException.php @@ -6,5 +6,4 @@ class RequestToBillbeeFailedException extends Exception { - } diff --git a/tests/Channel/Http/OrderRequestHandlerTest.php b/tests/Channel/Http/OrderRequestHandlerTest.php index b4ca7cc..8ecefbb 100644 --- a/tests/Channel/Http/OrderRequestHandlerTest.php +++ b/tests/Channel/Http/OrderRequestHandlerTest.php @@ -49,7 +49,7 @@ public function testCanHandle(string $action, bool $isSupported): void $mockRequest = self::createMock(Request::class); Assert::assertEquals($isSupported, $this->handler->canHandle($mockRequest, $action)); } - + #[TestWith(['{"action": "GetOrderList", "payload": {"page": 1, "perPage": 10, "startDate": "2024-06-14T15:36:00"}}', 1, 10, "2024-06-14"])] #[TestWith(['{"action": "GetOrderList", "payload": {"page": 2, "perPage": 20, "startDate": "2023-06-14T15:36:00"}}', 2, 20, "2023-06-14"])] public function testHandle_GetOrders(string $requestBody, int $page, int $perPage, string $start): void @@ -96,8 +96,8 @@ public function testAckOrder(string $requestBody, string $orderId): void $this->handler->handle($mockRequest, 'AckOrder'); } - #[TestWith(['{"action": "SetOrderState", "payload": {"id": "12345","status": 2,"changeDate": "2024-06-14T10:00:00Z","paidAmount": 99.99}}', "12345"])] - #[TestWith(['{"action": "SetOrderState", "payload": {"id": "5678","status": 2,"changeDate": "2024-06-14T10:00:00Z","paidAmount": 99.99}}', "5678"])] + #[TestWith(['{"action": "SetOrderState", "payload": {"id": "12345","status": 2,"changeDate": "2024-06-14T10:00:00","paidAmount": 99.99}}', "12345"])] + #[TestWith(['{"action": "SetOrderState", "payload": {"id": "5678","status": 2,"changeDate": "2024-06-14T10:00:00","paidAmount": 99.99}}', "5678"])] public function testSetOrderState(string $requestBody, string $orderId): void { $this->mockOrderRepository diff --git a/tests/Channel/Http/ProductRequestHandlerTest.php b/tests/Channel/Http/ProductRequestHandlerTest.php index 386c0d2..a79a037 100644 --- a/tests/Channel/Http/ProductRequestHandlerTest.php +++ b/tests/Channel/Http/ProductRequestHandlerTest.php @@ -46,7 +46,7 @@ public function testCanHandle(string $action, bool $isSupported): void $mockRequest = self::createMock(Request::class); Assert::assertEquals($isSupported, $this->handler->canHandle($mockRequest, $action)); } - + #[TestWith(['{"action": "GetProductList", "payload": {"page": 1, "perPage": 10}}', 1, 10])] #[TestWith(['{"action": "GetProductList", "payload": {"page": 2, "perPage": 20}}', 2, 20])] public function testHandle_GetProducts(string $requestBody, int $page, int $perPage): void