From f3c2b74ba6cde982e2320a2dba33cfbd81054602 Mon Sep 17 00:00:00 2001 From: Mateusz Qunabu Date: Thu, 15 Feb 2024 13:44:24 +0100 Subject: [PATCH 1/2] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 0106cb6..7780898 100644 --- a/composer.json +++ b/composer.json @@ -17,9 +17,9 @@ }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.10", - "nunomaduro/collision": "^5.5", - "nunomaduro/larastan": "^0.7.6", - "orchestra/testbench": "^6.0|^7.0", + "nunomaduro/collision": ">=5.5", + "nunomaduro/larastan": ">=0.7.6", + "orchestra/testbench": ">=7.0", "phpunit/phpunit": "^9.0", "escolalms/courses": "^0" }, From 0cfdc6b5f33d050fea9e1a720d68c74ad0e02211 Mon Sep 17 00:00:00 2001 From: Tomasz Smolarek Date: Thu, 15 Feb 2024 14:48:26 +0100 Subject: [PATCH 2/2] Test fix --- src/Http/Controllers/Admin/ProductAdminApiController.php | 4 ++-- src/Http/Controllers/Admin/ProductableAdminApiController.php | 4 ++-- src/Http/Requests/Admin/ProductAttachRequest.php | 2 +- src/Http/Requests/Admin/ProductDetachRequest.php | 2 +- src/Http/Requests/Admin/ProductableAttachRequest.php | 2 +- src/Http/Requests/Admin/ProductableDetachRequest.php | 2 +- tests/API/AdminProductApiTest.php | 4 ++-- tests/API/CartApiTest.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Http/Controllers/Admin/ProductAdminApiController.php b/src/Http/Controllers/Admin/ProductAdminApiController.php index e998f78..b034701 100644 --- a/src/Http/Controllers/Admin/ProductAdminApiController.php +++ b/src/Http/Controllers/Admin/ProductAdminApiController.php @@ -76,13 +76,13 @@ public function delete(ProductDeleteRequest $request): JsonResponse public function attach(ProductAttachRequest $request): JsonResponse { - $this->productService->attachProductToUser($request->getProduct(), $request->getUser()); + $this->productService->attachProductToUser($request->getProduct(), $request->getCartUser()); return $this->sendSuccess(__('Product attached to user')); } public function detach(ProductDetachRequest $request): JsonResponse { - $this->productService->detachProductFromUser($request->getProduct(), $request->getUser()); + $this->productService->detachProductFromUser($request->getProduct(), $request->getCartUser()); return $this->sendSuccess(__('Product detached from user')); } diff --git a/src/Http/Controllers/Admin/ProductableAdminApiController.php b/src/Http/Controllers/Admin/ProductableAdminApiController.php index abd6bd1..9a44aba 100644 --- a/src/Http/Controllers/Admin/ProductableAdminApiController.php +++ b/src/Http/Controllers/Admin/ProductableAdminApiController.php @@ -33,7 +33,7 @@ public function index(ProductableListRequest $request): JsonResponse public function attach(ProductableAttachRequest $request): JsonResponse { $productable = $this->productService->findProductable($request->getProductableType(), $request->getProductableId()); - $user = $request->getUser(); + $user = $request->getCartUser(); $this->productService->attachProductableToUser($productable, $user); return $this->sendSuccess(__('Productable attached to user')); } @@ -41,7 +41,7 @@ public function attach(ProductableAttachRequest $request): JsonResponse public function detach(ProductableDetachRequest $request): JsonResponse { $productable = $this->productService->findProductable($request->getProductableType(), $request->getProductableId()); - $user = $request->getUser(); + $user = $request->getCartUser(); if (!$this->productService->canDetachProductableFromUser($productable, $user)) { return $this->sendError(__('Unable to detach productable that was bought by User'), 403); } diff --git a/src/Http/Requests/Admin/ProductAttachRequest.php b/src/Http/Requests/Admin/ProductAttachRequest.php index aadf811..56600e9 100644 --- a/src/Http/Requests/Admin/ProductAttachRequest.php +++ b/src/Http/Requests/Admin/ProductAttachRequest.php @@ -41,7 +41,7 @@ public function getProduct(): Product return Product::findOrFail($this->getProductId()); } - public function getUser(): User + public function getCartUser(): User { return User::findOrFail($this->input('user_id')); } diff --git a/src/Http/Requests/Admin/ProductDetachRequest.php b/src/Http/Requests/Admin/ProductDetachRequest.php index f5c54f9..c2ae17f 100644 --- a/src/Http/Requests/Admin/ProductDetachRequest.php +++ b/src/Http/Requests/Admin/ProductDetachRequest.php @@ -41,7 +41,7 @@ public function getProduct(): Product return Product::findOrFail($this->getProductId()); } - public function getUser(): User + public function getCartUser(): User { return User::findOrFail($this->input('user_id')); } diff --git a/src/Http/Requests/Admin/ProductableAttachRequest.php b/src/Http/Requests/Admin/ProductableAttachRequest.php index 57d5292..c337d1e 100644 --- a/src/Http/Requests/Admin/ProductableAttachRequest.php +++ b/src/Http/Requests/Admin/ProductableAttachRequest.php @@ -35,7 +35,7 @@ public function getProductableType(): string return $this->validated()['productable_type']; } - public function getUser(): User + public function getCartUser(): User { return User::findOrFail($this->input('user_id')); } diff --git a/src/Http/Requests/Admin/ProductableDetachRequest.php b/src/Http/Requests/Admin/ProductableDetachRequest.php index 94d21a4..5723453 100644 --- a/src/Http/Requests/Admin/ProductableDetachRequest.php +++ b/src/Http/Requests/Admin/ProductableDetachRequest.php @@ -35,7 +35,7 @@ public function getProductableType(): string return $this->validated()['productable_type']; } - public function getUser(): User + public function getCartUser(): User { return User::findOrFail($this->input('user_id')); } diff --git a/tests/API/AdminProductApiTest.php b/tests/API/AdminProductApiTest.php index cfabdf7..a196be3 100644 --- a/tests/API/AdminProductApiTest.php +++ b/tests/API/AdminProductApiTest.php @@ -266,7 +266,7 @@ public function test_create_product_min_price() $this->response->assertJson( fn (AssertableJson $json) => $json - ->where('message', 'The given data was invalid.') + ->where('message', 'Field price must be greater than or equal to 10. (and 1 more error)') ->where('errors', [ 'price' => ['Field price must be greater than or equal to 10.'], 'price_old' => ['Field price old must be greater than or equal to 10.'], @@ -302,7 +302,7 @@ public function test_update_product_min_price() $this->response->assertJson( fn (AssertableJson $json) => $json - ->where('message', 'The given data was invalid.') + ->where('message', 'Field price must be greater than or equal to 10. (and 1 more error)') ->where('errors', [ 'price' => ['Field price must be greater than or equal to 10.'], 'price_old' => ['Field price old must be greater than or equal to 10.'], diff --git a/tests/API/CartApiTest.php b/tests/API/CartApiTest.php index 5fbe849..3427c91 100644 --- a/tests/API/CartApiTest.php +++ b/tests/API/CartApiTest.php @@ -391,7 +391,7 @@ public function test_added_more_than_limit_per_user() $this->response->assertUnprocessable(); $this->response->assertJson( fn (AssertableJson $json) => - $json->where('message', 'The given data was invalid.') + $json->where('message', 'The quantity must not be greater than 1.') ->where('errors.quantity', ['The quantity must not be greater than 1.']) ->etc() );