diff --git a/src/modules/Cart/Service.php b/src/modules/Cart/Service.php index c79021c49..676be66c0 100644 --- a/src/modules/Cart/Service.php +++ b/src/modules/Cart/Service.php @@ -188,7 +188,7 @@ class Service implements InjectionAwareInterface /** @var Product $cartProduct */ $cartProduct = $cartItem['product']; $requestedQty = $this->getRequestedQuantity($cartItem['config']); - $cartProductId = (int) $this->getProductId($cartProduct); + $cartProductId = $this->getProductId($cartProduct); $pendingQuantities[$cartProductId] = ($pendingQuantities[$cartProductId] ?? 0) + $requestedQty; $reservedQty = $this->getReservedQuantityInCart($cart, $cartProductId); @@ -584,15 +584,15 @@ class Service implements InjectionAwareInterface * https://github.com/boxbilling/boxbilling/discussions/1022#discussioncomment-1311819 */ if ($item['type'] === 'domain' || $item['type'] === 'hosting') { - $item['register_sld'] = (isset($item['register_sld'])) ? strtolower($item['register_sld']) : null; - $item['transfer_sld'] = (isset($item['transfer_sld'])) ? strtolower($item['transfer_sld']) : null; - $item['sld'] = (isset($item['sld'])) ? strtolower($item['sld']) : null; - $item['domain']['owndomain_sld'] = (isset($item['domain']['owndomain_sld'])) ? strtolower($item['domain']['owndomain_sld']) : null; - $item['domain']['register_sld'] = (isset($item['domain']['register_sld'])) ? strtolower($item['domain']['register_sld']) : null; - $item['domain']['transfer_sld'] = (isset($item['domain']['transfer_sld'])) ? strtolower($item['domain']['transfer_sld']) : null; + $item['register_sld'] = (isset($item['register_sld'])) ? strtolower((string) $item['register_sld']) : null; + $item['transfer_sld'] = (isset($item['transfer_sld'])) ? strtolower((string) $item['transfer_sld']) : null; + $item['sld'] = (isset($item['sld'])) ? strtolower((string) $item['sld']) : null; + $item['domain']['owndomain_sld'] = (isset($item['domain']['owndomain_sld'])) ? strtolower((string) $item['domain']['owndomain_sld']) : null; + $item['domain']['register_sld'] = (isset($item['domain']['register_sld'])) ? strtolower((string) $item['domain']['register_sld']) : null; + $item['domain']['transfer_sld'] = (isset($item['domain']['transfer_sld'])) ? strtolower((string) $item['domain']['transfer_sld']) : null; // Domain TLD must begin with a period - add if not present for owndomain. - $item['domain']['owndomain_tld'] = (isset($item['domain']['owndomain_tld'])) ? (str_contains($item['domain']['owndomain_tld'], '.') ? $item['domain']['owndomain_tld'] : '.' . $item['domain']['owndomain_tld']) : null; + $item['domain']['owndomain_tld'] = (isset($item['domain']['owndomain_tld'])) ? (str_contains((string) $item['domain']['owndomain_tld'], '.') ? $item['domain']['owndomain_tld'] : '.' . $item['domain']['owndomain_tld']) : null; } $order = $this->di['db']->dispense('ClientOrder'); @@ -754,7 +754,7 @@ class Service implements InjectionAwareInterface $this->getProductService()->usePromo($promo); } - public function findActivePromoByCode($code) + public function findActivePromoByCode($code): ?Promo { return $this->getProductService()->findActivePromoByCode($code); } @@ -763,9 +763,9 @@ class Service implements InjectionAwareInterface * Function checks if product is related to other products in cart * If relation exists then count discount for this. * - * @return number + * @return float */ - protected function getRelatedItemsDiscount(\Model_Cart $cart, \Model_CartProduct $model) + protected function getRelatedItemsDiscount(\Model_Cart $cart, \Model_CartProduct $model): float { $config = $this->getItemConfig($model); diff --git a/src/modules/Cart/tests/Unit/ServiceTest.php b/src/modules/Cart/tests/Unit/ServiceTest.php index ce7478d48..bad0301df 100644 --- a/src/modules/Cart/tests/Unit/ServiceTest.php +++ b/src/modules/Cart/tests/Unit/ServiceTest.php @@ -27,7 +27,6 @@ function createProductEntity(?int $id = null, ?string $type = null, ?string $con $product = new Product(); if ($id !== null) { $reflection = new ReflectionProperty($product, 'id'); - $reflection->setAccessible(true); $reflection->setValue($product, $id); } if ($type !== null) { @@ -44,7 +43,6 @@ function createPromoEntity(int $id): Promo { $promo = new Promo(); $reflection = new ReflectionProperty($promo, 'id'); - $reflection->setAccessible(true); $reflection->setValue($promo, $id); return $promo; @@ -67,7 +65,7 @@ test('gets search query', function (): void { $result = $service->getSearchQuery([]); expect($result[0])->toBeString(); expect($result[1])->toBeArray(); - expect(strpos($result[0], 'SELECT cart.id FROM cart'))->not->toBeFalse(); + expect(strpos((string) $result[0], 'SELECT cart.id FROM cart'))->not->toBeFalse(); }); test('getSessionCart returns existing cart', function (): void { @@ -258,7 +256,7 @@ test('removeProduct throws exception when cart product not found', function (): $cart = new Model_Cart(); $cart->loadBean(new Tests\Helpers\DummyBean()); - expect(fn () => $service->removeProduct($cart, 1))->toThrow(FOSSBilling\Exception::class); + expect(fn (): bool => $service->removeProduct($cart, 1))->toThrow(FOSSBilling\Exception::class); }); test('changeCartCurrency returns true', function (): void { @@ -691,7 +689,6 @@ test('createFromCart with promo entity uses product promo service', function (): $promo = new Promo(); $promo->setCode('PROMO'); $promoIdReflection = new ReflectionProperty($promo, 'id'); - $promoIdReflection->setAccessible(true); $promoIdReflection->setValue($promo, 7); $productService = Mockery::mock(ProductService::class); @@ -700,16 +697,13 @@ test('createFromCart with promo entity uses product promo service', function (): $productService->shouldReceive('createCheckoutPromoRedemptions')->once()->with( $promo, $client, - Mockery::on(function (array $orders): bool { - return count($orders) === 1 && $orders[0] instanceof Model_ClientOrder; - }), + Mockery::on(fn (array $orders): bool => count($orders) === 1 && $orders[0] instanceof Model_ClientOrder), null, PromoRedemption::STATUS_COMMITTED ); $product = new Product(); $productIdReflection = new ReflectionProperty($product, 'id'); - $productIdReflection->setAccessible(true); $productIdReflection->setValue($product, 5); $product->setStatus('enabled'); $product->setType('service'); @@ -763,14 +757,12 @@ test('createFromCart with promo entity uses product promo service', function (): $di = container(); $di['db'] = $dbMock; - $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use ($currencyService, $clientService, $productService, $orderService) { - return match ($serviceName) { - 'currency' => $currencyService, - 'client' => $clientService, - 'Product' => $productService, - 'order', 'Order' => $orderService, - default => null, - }; + $di['mod_service'] = $di->protect(fn ($serviceName, $sub = '') => match ($serviceName) { + 'currency' => $currencyService, + 'client' => $clientService, + 'Product' => $productService, + 'order', 'Order' => $orderService, + default => null, }); $serviceMock->setDi($di); @@ -807,7 +799,6 @@ test('createFromCart compensates promo usage on transaction failure', function ( $promo = new Promo(); $promo->setCode('PROMO'); $promoIdReflection = new ReflectionProperty($promo, 'id'); - $promoIdReflection->setAccessible(true); $promoIdReflection->setValue($promo, 7); $productService = Mockery::mock(ProductService::class); @@ -825,7 +816,6 @@ test('createFromCart compensates promo usage on transaction failure', function ( $product = new Product(); $productIdReflection = new ReflectionProperty($product, 'id'); - $productIdReflection->setAccessible(true); $productIdReflection->setValue($product, 5); $product->setStatus('enabled'); $product->setType('service'); @@ -875,14 +865,12 @@ test('createFromCart compensates promo usage on transaction failure', function ( $di = container(); $di['db'] = $dbMock; $di['logger'] = new Box_Log(); - $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use ($currencyService, $clientService, $productService, $orderService) { - return match ($serviceName) { - 'currency' => $currencyService, - 'client' => $clientService, - 'Product' => $productService, - 'order', 'Order' => $orderService, - default => null, - }; + $di['mod_service'] = $di->protect(fn ($serviceName, $sub = '') => match ($serviceName) { + 'currency' => $currencyService, + 'client' => $clientService, + 'Product' => $productService, + 'order', 'Order' => $orderService, + default => null, }); $serviceMock->setDi($di); diff --git a/src/modules/Invoice/tests/Unit/ServiceTest.php b/src/modules/Invoice/tests/Unit/ServiceTest.php index cc26fc92f..b0ea823f6 100644 --- a/src/modules/Invoice/tests/Unit/ServiceTest.php +++ b/src/modules/Invoice/tests/Unit/ServiceTest.php @@ -436,8 +436,8 @@ test('to api array self-heals invoice with missing hash', function (): void { expect($result)->toBeArray(); expect($result['hash'])->toBeString(); - expect(strlen($result['hash']))->toBeGreaterThanOrEqual(30); - expect(strlen($result['hash']))->toBeLessThanOrEqual(60); + expect(strlen((string) $result['hash']))->toBeGreaterThanOrEqual(30); + expect(strlen((string) $result['hash']))->toBeLessThanOrEqual(60); }); test('handles after admin invoice payment received event', function (): void { @@ -2404,14 +2404,12 @@ test('markAsPaid transitions a deposit invoice to paid status', function (): voi $di['db'] = $dbMock; $di['logger'] = new Tests\Helpers\TestLogger(); $productService = Mockery::mock(Box\Mod\Product\Service::class)->shouldIgnoreMissing(); - $di['mod_service'] = $di->protect(function ($name, $sub = '') use ($systemService, $currencyService, $invoiceItemService, $productService) { - return match ([$name, $sub]) { - ['system', ''] => $systemService, - ['currency', ''] => $currencyService, - ['Invoice', 'InvoiceItem'] => $invoiceItemService, - ['Product', ''], ['product', ''] => $productService, - default => throw new RuntimeException("Unexpected service: {$name}/{$sub}"), - }; + $di['mod_service'] = $di->protect(fn ($name, $sub = '') => match ([$name, $sub]) { + ['system', ''] => $systemService, + ['currency', ''] => $currencyService, + ['Invoice', 'InvoiceItem'] => $invoiceItemService, + ['Product', ''], ['product', ''] => $productService, + default => throw new RuntimeException("Unexpected service: {$name}/{$sub}"), }); $di['events_manager'] = $eventsManager; $service->setDi($di); diff --git a/src/modules/Order/Service.php b/src/modules/Order/Service.php index 8daf80d4b..4a47f5bdf 100644 --- a/src/modules/Order/Service.php +++ b/src/modules/Order/Service.php @@ -1643,7 +1643,7 @@ class Service implements InjectionAwareInterface private function getProductUnit(Product $product): string { - return (string) $product->getUnit(); + return $product->getUnit(); } private function isAddonProduct(Product $product): bool diff --git a/src/modules/Order/tests/Unit/ServiceTest.php b/src/modules/Order/tests/Unit/ServiceTest.php index 8b27c0cc1..da344f696 100644 --- a/src/modules/Order/tests/Unit/ServiceTest.php +++ b/src/modules/Order/tests/Unit/ServiceTest.php @@ -20,7 +20,6 @@ function orderServiceCreateProductEntity(?int $id = null, ?string $type = null): $product = new Product(); if ($id !== null) { $reflection = new ReflectionProperty($product, 'id'); - $reflection->setAccessible(true); $reflection->setValue($product, $id); } if ($type !== null) { @@ -988,103 +987,101 @@ test('toApiArray returns expected keys', function (): void { expect($result)->toHaveKey('client'); }); -dataset('searchQueryData', function (): array { - return [ - 'no data' => [[], 'SELECT co.* from client_order co', []], - 'client_id' => [ - ['client_id' => 1], - 'co.client_id = :client_id', - [':client_id' => '1'], +dataset('searchQueryData', fn (): array => [ + 'no data' => [[], 'SELECT co.* from client_order co', []], + 'client_id' => [ + ['client_id' => 1], + 'co.client_id = :client_id', + [':client_id' => '1'], + ], + 'invoice_option' => [ + ['invoice_option' => 'issue-invoice'], + 'co.invoice_option = :invoice_option', + [':invoice_option' => 'issue-invoice'], + ], + 'id' => [ + ['id' => 1], + 'co.id = :id', + [':id' => '1'], + ], + 'status' => [ + ['status' => 'pending_setup'], + 'co.status = :status', + [':status' => 'pending_setup'], + ], + 'product_id' => [ + ['product_id' => 1], + 'co.product_id = :product_id', + [':product_id' => '1'], + ], + 'type' => [ + ['type' => 'custom'], + 'co.service_type = :service_type', + [':service_type' => 'custom'], + ], + 'title' => [ + ['title' => 'titleField'], + 'co.title LIKE :title', + [':title' => '%titleField%'], + ], + 'period' => [ + ['period' => '1Y'], + 'co.period = :period', + [':period' => '1Y'], + ], + 'hide_addons' => [ + ['hide_addons' => true], + 'co.group_master = 1', + [], + ], + 'created_at' => [ + ['created_at' => '2012-12-11'], + "DATE_FORMAT(co.created_at, '%Y-%m-%d') = :created_at", + [':created_at' => '2012-12-11'], + ], + 'date_from' => [ + ['date_from' => '2012-12-11'], + 'UNIX_TIMESTAMP(co.created_at) >= :date_from', + [':date_from' => strtotime('2012-12-11')], + ], + 'date_to' => [ + ['date_to' => '2012-12-11'], + 'UNIX_TIMESTAMP(co.created_at) <= :date_to', + [':date_to' => strtotime('2012-12-11')], + ], + 'search numeric' => [ + ['search' => 120], + 'co.id = :search', + [':search' => 120], + ], + 'search string' => [ + ['search' => 'John'], + '(c.first_name LIKE :first_name OR c.last_name LIKE :last_name OR co.title LIKE :title)', + [ + ':first_name' => '%John%', + ':last_name' => '%John%', + ':title' => '%John%', ], - 'invoice_option' => [ - ['invoice_option' => 'issue-invoice'], - 'co.invoice_option = :invoice_option', - [':invoice_option' => 'issue-invoice'], + ], + 'ids' => [ + ['ids' => [1, 2, 3]], + 'co.id IN (:ids)', + [':ids' => '1, 2, 3'], + ], + 'promo_id' => [ + ['promo_id' => 9], + 'co.promo_id = :promo_id', + [':promo_id' => 9], + ], + 'meta' => [ + ['meta' => ['param' => 'value']], + '(meta.name = :meta_name1 AND meta.value LIKE :meta_value1)', + [ + ':meta_name1' => 'param', + ':meta_value1' => 'value%', ], - 'id' => [ - ['id' => 1], - 'co.id = :id', - [':id' => '1'], - ], - 'status' => [ - ['status' => 'pending_setup'], - 'co.status = :status', - [':status' => 'pending_setup'], - ], - 'product_id' => [ - ['product_id' => 1], - 'co.product_id = :product_id', - [':product_id' => '1'], - ], - 'type' => [ - ['type' => 'custom'], - 'co.service_type = :service_type', - [':service_type' => 'custom'], - ], - 'title' => [ - ['title' => 'titleField'], - 'co.title LIKE :title', - [':title' => '%titleField%'], - ], - 'period' => [ - ['period' => '1Y'], - 'co.period = :period', - [':period' => '1Y'], - ], - 'hide_addons' => [ - ['hide_addons' => true], - 'co.group_master = 1', - [], - ], - 'created_at' => [ - ['created_at' => '2012-12-11'], - "DATE_FORMAT(co.created_at, '%Y-%m-%d') = :created_at", - [':created_at' => '2012-12-11'], - ], - 'date_from' => [ - ['date_from' => '2012-12-11'], - 'UNIX_TIMESTAMP(co.created_at) >= :date_from', - [':date_from' => strtotime('2012-12-11')], - ], - 'date_to' => [ - ['date_to' => '2012-12-11'], - 'UNIX_TIMESTAMP(co.created_at) <= :date_to', - [':date_to' => strtotime('2012-12-11')], - ], - 'search numeric' => [ - ['search' => 120], - 'co.id = :search', - [':search' => 120], - ], - 'search string' => [ - ['search' => 'John'], - '(c.first_name LIKE :first_name OR c.last_name LIKE :last_name OR co.title LIKE :title)', - [ - ':first_name' => '%John%', - ':last_name' => '%John%', - ':title' => '%John%', - ], - ], - 'ids' => [ - ['ids' => [1, 2, 3]], - 'co.id IN (:ids)', - [':ids' => '1, 2, 3'], - ], - 'promo_id' => [ - ['promo_id' => 9], - 'co.promo_id = :promo_id', - [':promo_id' => 9], - ], - 'meta' => [ - ['meta' => ['param' => 'value']], - '(meta.name = :meta_name1 AND meta.value LIKE :meta_value1)', - [ - ':meta_name1' => 'param', - ':meta_value1' => 'value%', - ], - ], - ]; -}); + ], +]); test('getSearchQuery returns expected query and bindings', function (array $data, string $expectedStr, array $expectedParams): void { $di = container(); @@ -1657,7 +1654,7 @@ test('activateOrder throws for non-pending order', function (): void { $svc = new Service(); - expect(fn () => $svc->activateOrder($clientOrderModel)) + expect(fn (): bool => $svc->activateOrder($clientOrderModel)) ->toThrow(FOSSBilling\Exception::class, 'Only pending setup or failed orders can be activated'); }); @@ -1775,7 +1772,7 @@ test('stockSale throws when quantity would go negative', function (): void { $svc = new Service(); $svc->setDi($di); - expect(fn () => $svc->stockSale($productModel, 2)) + expect(fn (): bool => $svc->stockSale($productModel, 2)) ->toThrow(FOSSBilling\InformationException::class, 'Product 1 is out of stock.'); }); @@ -1935,7 +1932,7 @@ test('suspendFromOrder throws for non-active order', function (): void { $svc = new Service(); $svc->setDi($di); - expect(fn () => $svc->suspendFromOrder($clientOrderModel)) + expect(fn (): bool => $svc->suspendFromOrder($clientOrderModel)) ->toThrow(FOSSBilling\Exception::class, 'Only active orders can be suspended'); }); @@ -2247,7 +2244,7 @@ test('updateOrderConfig throws when required field is missing', function (): voi $order->loadBean(new Tests\Helpers\DummyBean()); $order->form_id = 7; - expect(fn () => $svc->updateOrderConfig($order, [])) + expect(fn (): bool => $svc->updateOrderConfig($order, [])) ->toThrow(FOSSBilling\Exception::class, '', 4892); }); @@ -2275,7 +2272,7 @@ test('updateOrderConfig throws for invalid select option', function (): void { $order->loadBean(new Tests\Helpers\DummyBean()); $order->form_id = 8; - expect(fn () => $svc->updateOrderConfig($order, ['plan' => 'enterprise'])) + expect(fn (): bool => $svc->updateOrderConfig($order, ['plan' => 'enterprise'])) ->toThrow(FOSSBilling\Exception::class, '', 4893); }); @@ -2303,7 +2300,7 @@ test('updateOrderConfig select rejects array value', function (): void { $order->loadBean(new Tests\Helpers\DummyBean()); $order->form_id = 11; - expect(fn () => $svc->updateOrderConfig($order, ['plan' => ['pro']])) + expect(fn (): bool => $svc->updateOrderConfig($order, ['plan' => ['pro']])) ->toThrow(FOSSBilling\Exception::class, '', 4893); }); @@ -2331,7 +2328,7 @@ test('updateOrderConfig throws for invalid radio option', function (): void { $order->loadBean(new Tests\Helpers\DummyBean()); $order->form_id = 9; - expect(fn () => $svc->updateOrderConfig($order, ['os' => 'macos'])) + expect(fn (): bool => $svc->updateOrderConfig($order, ['os' => 'macos'])) ->toThrow(FOSSBilling\Exception::class, '', 4893); }); @@ -2359,7 +2356,7 @@ test('updateOrderConfig throws for invalid checkbox option', function (): void { $order->loadBean(new Tests\Helpers\DummyBean()); $order->form_id = 10; - expect(fn () => $svc->updateOrderConfig($order, ['addons' => ['backup', 'ddos-protection']])) + expect(fn (): bool => $svc->updateOrderConfig($order, ['addons' => ['backup', 'ddos-protection']])) ->toThrow(FOSSBilling\Exception::class, '', 4894); }); diff --git a/src/modules/Product/Entity/Promo.php b/src/modules/Product/Entity/Promo.php index 909031fb0..aa5c76861 100644 --- a/src/modules/Product/Entity/Promo.php +++ b/src/modules/Product/Entity/Promo.php @@ -179,7 +179,7 @@ class Promo implements ApiArrayInterface, TimestampInterface public function setMaxUses(?int $maxUses): self { - $this->maxUses = max(0, (int) ($maxUses ?? 0)); + $this->maxUses = max(0, $maxUses ?? 0); return $this; } @@ -191,7 +191,7 @@ class Promo implements ApiArrayInterface, TimestampInterface public function setUsed(?int $used): self { - $this->used = max(0, (int) ($used ?? 0)); + $this->used = max(0, $used ?? 0); return $this; } diff --git a/src/modules/Product/Service.php b/src/modules/Product/Service.php index 4d41d5b86..326cb21d6 100644 --- a/src/modules/Product/Service.php +++ b/src/modules/Product/Service.php @@ -368,7 +368,7 @@ class Service implements InjectionAwareInterface return 'year'; } - return (string) $product->getUnit(); + return $product->getUnit(); } public function isRecurrentProductPricing(Product $product): bool @@ -569,7 +569,7 @@ class Service implements InjectionAwareInterface return $result; } - public function createAddon($title, $description = null, $setup = null, $status = null, $iconUrl = null) + public function createAddon($title, $description = null, $setup = null, $status = null, $iconUrl = null): ?int { $productPayment = $this->createDefaultProductPayment(); $paymentId = (int) $productPayment->getId(); @@ -645,7 +645,7 @@ class Service implements InjectionAwareInterface return true; } - public function createCategory($title, $description = null, $icon_url = null) + public function createCategory($title, $description = null, $icon_url = null): ?int { $model = (new ProductCategory()) ->setTitle($title) @@ -681,7 +681,7 @@ class Service implements InjectionAwareInterface return $this->getProductRepository()->getSearchQueryBuilder($data); } - public function toProductCategoryApiArray(ProductCategory $model, $deep = true, $identity = null) + public function toProductCategoryApiArray(ProductCategory $model, $deep = true, $identity = null): array { $min_price = 0; $products = []; @@ -1017,7 +1017,10 @@ class Service implements InjectionAwareInterface return $addons; } - public function getProductAddons(Product $model, bool $includeUnavailable = false) + /** + * @return mixed[] + */ + public function getProductAddons(Product $model, bool $includeUnavailable = false): array { $ids = $this->normalizeProductIds(json_decode($this->getProductAddonsJson($model) ?? '', true) ?? []); @@ -1158,7 +1161,7 @@ class Service implements InjectionAwareInterface return $this->getPromoRepository()->getSearchQueryBuilder($data); } - public function createPromo($code, $type, $value, $products, $periods, $clientGroups, $data) + public function createPromo($code, $type, $value, $products, $periods, $clientGroups, $data): int { if ($this->getPromoRepository()->findOneBy(['code' => $code]) instanceof Promo) { throw new \FOSSBilling\InformationException('This promotion code already exists.'); @@ -1634,7 +1637,7 @@ class Service implements InjectionAwareInterface return [ 'price' => (float) $this->getProductPrice($product, $config), 'quantity' => $quantity, - 'setup_price' => (float) $this->getProductSetupPrice($product, $config), + 'setup_price' => $this->getProductSetupPrice($product, $config), ]; } @@ -1788,7 +1791,7 @@ class Service implements InjectionAwareInterface private function normalizeProductIds(array $ids): array { return array_values(array_unique(array_filter( - array_map('intval', $ids), + array_map(intval(...), $ids), static fn (int $id): bool => $id > 0 ))); } diff --git a/src/modules/Product/tests/Unit/Api/AdminTest.php b/src/modules/Product/tests/Unit/Api/AdminTest.php index 47c41579b..343c8a6ef 100644 --- a/src/modules/Product/tests/Unit/Api/AdminTest.php +++ b/src/modules/Product/tests/Unit/Api/AdminTest.php @@ -77,7 +77,7 @@ test('throws exception when preparing domain product already created', function $api->setDi(container()); $api->setService($serviceMock); - expect(fn () => $api->prepare($data)) + expect(fn (): int => $api->prepare($data)) ->toThrow(FOSSBilling\Exception::class, 'You have already created domain product'); }); @@ -91,7 +91,7 @@ test('throws exception when preparing unrecognized product type', function (): v $api->setDi(container()); $api->setService($serviceMock); - expect(fn () => $api->prepare($data)) + expect(fn (): int => $api->prepare($data)) ->toThrow(FOSSBilling\Exception::class, "Product type {$data['type']} is not registered."); }); @@ -186,7 +186,6 @@ test('gets an addon', function (): void { $model = new Product(); $reflection = new ReflectionProperty($model, 'isAddon'); - $reflection->setAccessible(true); $reflection->setValue($model, true); $serviceMock = Mockery::mock(Service::class); @@ -207,7 +206,6 @@ test('updates an addon', function (): void { $model = new Product(); $reflection = new ReflectionProperty($model, 'isAddon'); - $reflection->setAccessible(true); $reflection->setValue($model, true); $serviceMock = Mockery::mock(Service::class); diff --git a/src/modules/Product/tests/Unit/ServiceTest.php b/src/modules/Product/tests/Unit/ServiceTest.php index 2815abb66..6be77f9d7 100644 --- a/src/modules/Product/tests/Unit/ServiceTest.php +++ b/src/modules/Product/tests/Unit/ServiceTest.php @@ -30,7 +30,6 @@ function productTestCreateProductEntity(int $id): Product { $product = new Product(); $reflection = new ReflectionProperty($product, 'id'); - $reflection->setAccessible(true); $reflection->setValue($product, $id); return $product; @@ -40,7 +39,6 @@ function productTestCreatePromoEntity(int $id): Promo { $promo = new Promo(); $reflection = new ReflectionProperty($promo, 'id'); - $reflection->setAccessible(true); $reflection->setValue($promo, $id); return $promo; @@ -50,7 +48,6 @@ function productTestCreateProductCategoryEntity(int $id): ProductCategory { $category = new ProductCategory(); $reflection = new ReflectionProperty($category, 'id'); - $reflection->setAccessible(true); $reflection->setValue($category, $id); return $category; @@ -60,7 +57,6 @@ function productTestCreateProductPaymentEntity(int $id): ProductPayment { $productPayment = new ProductPayment(); $reflection = new ReflectionProperty($productPayment, 'id'); - $reflection->setAccessible(true); $reflection->setValue($productPayment, $id); return $productPayment; @@ -78,12 +74,12 @@ function productTestCreateEntityManagerWithRepositories( public int $flushCalls = 0; public function __construct( - private ?ProductRepository $productRepo, - private ?ProductPaymentRepository $paymentRepo, - private ?Product $persistedProduct, - private ?ProductPayment $persistedPayment, - private ?ProductCategoryRepository $categoryRepo, - private ?ProductCategory $persistedCategory, + private readonly ?ProductRepository $productRepo, + private readonly ?ProductPaymentRepository $paymentRepo, + private readonly ?Product $persistedProduct, + private readonly ?ProductPayment $persistedPayment, + private readonly ?ProductCategoryRepository $categoryRepo, + private readonly ?ProductCategory $persistedCategory, ) { } @@ -101,19 +97,16 @@ function productTestCreateEntityManagerWithRepositories( { if ($entity instanceof Product && $this->persistedProduct instanceof Product) { $reflection = new ReflectionProperty($entity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($entity, $this->persistedProduct->getId()); } if ($entity instanceof ProductPayment && $this->persistedPayment instanceof ProductPayment) { $reflection = new ReflectionProperty($entity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($entity, $this->persistedPayment->getId()); } if ($entity instanceof ProductCategory && $this->persistedCategory instanceof ProductCategory) { $reflection = new ReflectionProperty($entity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($entity, $this->persistedCategory->getId()); } } @@ -134,7 +127,7 @@ function productTestCreateProductPaymentEntityManager(ProductPaymentRepository $ return new class($paymentRepo) { public int $flushCalls = 0; - public function __construct(private ProductPaymentRepository $paymentRepo) + public function __construct(private readonly ProductPaymentRepository $paymentRepo) { } @@ -797,11 +790,9 @@ test('update priority', function (): void { $productB = productTestCreateProductEntity(5); $productRepo = Mockery::mock(ProductRepository::class); - $productRepo->shouldReceive('find')->twice()->andReturnUsing(function ($id) use ($productA, $productB) { - return match ($id) { - 1 => $productA, - 5 => $productB, - }; + $productRepo->shouldReceive('find')->twice()->andReturnUsing(fn ($id) => match ($id) { + 1 => $productA, + 5 => $productB, }); $di = container(); @@ -901,7 +892,7 @@ test('delete product active order exception', function (): void { $service->setDi($di); - expect(fn () => $service->deleteProduct($model)) + expect(fn (): bool => $service->deleteProduct($model)) ->toThrow(FOSSBilling\Exception::class, 'Cannot remove product which has active orders.'); }); @@ -965,7 +956,7 @@ test('remove product category category has products exception', function (): voi $service->setDi($di); - expect(fn () => $service->removeProductCategory($modelProductCategory)) + expect(fn (): bool => $service->removeProductCategory($modelProductCategory)) ->toThrow(FOSSBilling\Exception::class, 'Cannot remove product category with products'); }); @@ -992,7 +983,7 @@ test('create promo', function (): void { $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('findOneBy')->once()->with(['code' => 'code'])->andReturn(null); - $emMock = new class($promoRepo) { + $emMock = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1005,7 +996,6 @@ test('create promo', function (): void { public function persist(object $entity): void { $reflection = new ReflectionProperty($entity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($entity, 1); } @@ -1036,7 +1026,7 @@ test('to promo api array', function (): void { $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('countLinkedOrdersByPromoId')->once()->with(1)->andReturn(0); - $emMock = new class($promoRepo, $repoMock) { + $emMock = new readonly class($promoRepo, $repoMock) { public function __construct(private object $promoRepo, private object $redemptionRepo) { } @@ -1081,7 +1071,7 @@ test('to promo api array includes usage stats for deep requests', function (): v $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldNotReceive('countLinkedOrdersByPromoId'); - $emMock = new class($promoRepo, $repoMock) { + $emMock = new readonly class($promoRepo, $repoMock) { public function __construct(private object $promoRepo, private object $redemptionRepo) { } @@ -1147,11 +1137,11 @@ test('promo can be applied', function (Promo $promo, bool $expectedResult): void $service = new Service(); expect($service->promoCanBeApplied($promo))->toBe($expectedResult); })->with([ - 'inactive' => [fn () => productTestCreatePromoEntity(1)->setActive(false), false], - 'max uses reached' => [fn () => productTestCreatePromoEntity(2)->setActive(true)->setMaxUses(5)->setUsed(5), false], - 'not yet started' => [fn () => productTestCreatePromoEntity(3)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('tomorrow')), false], - 'already ended' => [fn () => productTestCreatePromoEntity(4)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('yesterday'))->setEndAt(new DateTime('yesterday')), false], - 'within window' => [fn () => productTestCreatePromoEntity(5)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('yesterday'))->setEndAt(new DateTime('tomorrow')), true], + 'inactive' => [fn (): Promo => productTestCreatePromoEntity(1)->setActive(false), false], + 'max uses reached' => [fn (): Promo => productTestCreatePromoEntity(2)->setActive(true)->setMaxUses(5)->setUsed(5), false], + 'not yet started' => [fn (): Promo => productTestCreatePromoEntity(3)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('tomorrow')), false], + 'already ended' => [fn (): Promo => productTestCreatePromoEntity(4)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('yesterday'))->setEndAt(new DateTime('yesterday')), false], + 'within window' => [fn (): Promo => productTestCreatePromoEntity(5)->setActive(true)->setMaxUses(10)->setUsed(5)->setStartAt(new DateTime('yesterday'))->setEndAt(new DateTime('tomorrow')), true], ]); test('can client use promo returns false when promo cannot be applied', function (): void { @@ -1202,7 +1192,7 @@ test('use promo', function (): void { $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('incrementUsageIfAvailable')->once()->with(12, Mockery::type(DateTimeInterface::class))->andReturn(1); - $emMock = new class($promoRepo) { + $emMock = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1228,7 +1218,7 @@ test('use promo limit reached', function (): void { $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('incrementUsageIfAvailable')->once()->andReturn(0); - $emMock = new class($promoRepo) { + $emMock = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1335,13 +1325,12 @@ test('find active promo by code', function (): void { $promoEntity = new Promo(); $promoEntity->setCode('CODE'); $reflection = new ReflectionProperty($promoEntity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($promoEntity, 14); $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('findActiveByCode')->once()->with('CODE')->andReturn($promoEntity); - $emMock = new class($promoRepo) { + $emMock = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1424,7 +1413,7 @@ test('get renewal promo adjustment for domain order', function (): void { $di = container(); $di['db'] = $dbMock; $di['api_guest'] = $apiGuest; - $di['em'] = new class($promoRepo) { + $di['em'] = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1490,30 +1479,30 @@ test('is promo available for client group', function (Promo $promo, ?Model_Clien expect($service->isPromoAvailableForClientGroup($promo))->toBe($expectedResult); })->with([ - 'no restrictions' => [fn () => productTestCreatePromoEntity(1)->setClientGroups(json_encode([])), fn () => $client = new Model_Client(), true], - 'restricted and no client group' => [fn () => productTestCreatePromoEntity(2)->setClientGroups(json_encode([1, 2])), function () { + 'no restrictions' => [fn (): Promo => productTestCreatePromoEntity(1)->setClientGroups(json_encode([])), fn (): Model_Client => $client = new Model_Client(), true], + 'restricted and no client group' => [fn (): Promo => productTestCreatePromoEntity(2)->setClientGroups(json_encode([1, 2])), function () { $client = new Model_Client(); $client->loadBean(new Tests\Helpers\DummyBean()); $client->client_group_id = null; return $client; }, false], - 'restricted and wrong client group' => [fn () => productTestCreatePromoEntity(3)->setClientGroups(json_encode([1, 2])), function () { + 'restricted and wrong client group' => [fn (): Promo => productTestCreatePromoEntity(3)->setClientGroups(json_encode([1, 2])), function () { $client = new Model_Client(); $client->loadBean(new Tests\Helpers\DummyBean()); $client->client_group_id = 3; return $client; }, false], - 'restricted and matching client group' => [fn () => productTestCreatePromoEntity(4)->setClientGroups(json_encode([1, 2])), function () { + 'restricted and matching client group' => [fn (): Promo => productTestCreatePromoEntity(4)->setClientGroups(json_encode([1, 2])), function () { $client = new Model_Client(); $client->loadBean(new Tests\Helpers\DummyBean()); $client->client_group_id = 2; return $client; }, true], - 'no restrictions and no client' => [fn () => productTestCreatePromoEntity(5)->setClientGroups(json_encode([])), null, true], - 'restricted and no client' => [fn () => productTestCreatePromoEntity(6)->setClientGroups(json_encode([1, 2])), null, false], + 'no restrictions and no client' => [fn (): Promo => productTestCreatePromoEntity(5)->setClientGroups(json_encode([])), null, true], + 'restricted and no client' => [fn (): Promo => productTestCreatePromoEntity(6)->setClientGroups(json_encode([1, 2])), null, false], ]); test('release reserved promo redemptions for invoice releases reservations and decrements operational counter', function (): void { @@ -1548,7 +1537,7 @@ test('release reserved promo redemptions for invoice releases reservations and d $di['em'] = new class($promoRepo, $repoMock) { public int $flushCalls = 0; - public function __construct(private object $promoRepo, private object $redemptionRepo) + public function __construct(private readonly object $promoRepo, private readonly object $redemptionRepo) { } @@ -1597,8 +1586,8 @@ test('compensateCheckoutPromoFailure deletes orphaned redemptions and decrements public int $removeCalls = 0; public function __construct( - private object $promoRepo, - private object $redemptionRepo, + private readonly object $promoRepo, + private readonly object $redemptionRepo, ) { } @@ -1647,13 +1636,12 @@ test('update promo', function (): void { $promoEntity = new Promo(); $promoEntity->setCode('OLD'); $reflection = new ReflectionProperty($promoEntity, 'id'); - $reflection->setAccessible(true); $reflection->setValue($promoEntity, 1); $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('findOneBy')->once()->with(['code' => 'GO'])->andReturn(null); - $emMock = new class($promoRepo) { + $emMock = new readonly class($promoRepo) { public function __construct(private object $promoRepo) { } @@ -1689,7 +1677,7 @@ test('delete promo', function (): void { $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('countLinkedOrdersByPromoId')->once()->with(1)->andReturn(0); - $emMock = new class($promoRepo, $redemptionRepo) { + $emMock = new readonly class($promoRepo, $redemptionRepo) { public function __construct(private object $promoRepo, private object $redemptionRepo) { } @@ -1730,7 +1718,7 @@ test('delete promo blocks deletion when redemption history exists', function (): $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldNotReceive('countLinkedOrdersByPromoId'); - $emMock = new class($promoRepo, $redemptionRepo) { + $emMock = new readonly class($promoRepo, $redemptionRepo) { public function __construct(private object $promoRepo, private object $redemptionRepo) { } @@ -1747,7 +1735,7 @@ test('delete promo blocks deletion when redemption history exists', function (): $service->setDi($di); - expect(fn () => $service->deletePromo($promoEntity)) + expect(fn (): bool => $service->deletePromo($promoEntity)) ->toThrow(FOSSBilling\InformationException::class, 'Promotions with redemption history cannot be deleted. Disable the promotion instead.'); }); @@ -1761,7 +1749,7 @@ test('delete promo blocks deletion when linked orders exist without ledger histo $promoRepo = Mockery::mock(PromoRepository::class); $promoRepo->shouldReceive('countLinkedOrdersByPromoId')->once()->with(1)->andReturn(1); - $emMock = new class($promoRepo, $redemptionRepo) { + $emMock = new readonly class($promoRepo, $redemptionRepo) { public function __construct(private object $promoRepo, private object $redemptionRepo) { } @@ -1777,7 +1765,7 @@ test('delete promo blocks deletion when linked orders exist without ledger histo $service->setDi($di); - expect(fn () => $service->deletePromo($promoEntity)) + expect(fn (): bool => $service->deletePromo($promoEntity)) ->toThrow(FOSSBilling\InformationException::class, 'Promotions with redemption history cannot be deleted. Disable the promotion instead.'); }); @@ -1846,7 +1834,7 @@ test('get product search query', function (): void { $repo->shouldReceive('getSearchQueryBuilder')->once()->with($data)->andReturn($qb); $di = container(); - $di['em'] = new class($repo) { + $di['em'] = new readonly class($repo) { public function __construct(private ProductRepository $repo) { } @@ -1929,7 +1917,7 @@ test('find one active by id', function (): void { $repo->shouldReceive('findActiveById')->once()->with(1)->andReturn($model); $di = container(); - $di['em'] = new class($repo) { + $di['em'] = new readonly class($repo) { public function __construct(private ProductRepository $repo) { } @@ -1953,7 +1941,7 @@ test('find one active by slug', function (): void { $repo->shouldReceive('findActiveBySlug')->once()->with('product/1')->andReturn($model); $di = container(); - $di['em'] = new class($repo) { + $di['em'] = new readonly class($repo) { public function __construct(private ProductRepository $repo) { } @@ -2146,11 +2134,9 @@ test('assert upgrade allowed by ids throws helpful exception', function (): void $serviceMock = Mockery::mock(Service::class)->makePartial(); $serviceMock->shouldReceive('getUpgradablePairsByProductId')->once()->with(1)->andReturn([]); - $serviceMock->shouldReceive('findProductById')->twice()->andReturnUsing(function ($id) use ($currentProduct, $upgradeProduct) { - return match ($id) { - 1 => $currentProduct, - 2 => $upgradeProduct, - }; + $serviceMock->shouldReceive('findProductById')->twice()->andReturnUsing(fn ($id) => match ($id) { + 1 => $currentProduct, + 2 => $upgradeProduct, }); expect(fn () => $serviceMock->assertUpgradeAllowedByIds(1, 2)) diff --git a/src/modules/Servicecustom/tests/Unit/ServiceTest.php b/src/modules/Servicecustom/tests/Unit/ServiceTest.php index 4cc0fbe79..d166d4d9f 100644 --- a/src/modules/Servicecustom/tests/Unit/ServiceTest.php +++ b/src/modules/Servicecustom/tests/Unit/ServiceTest.php @@ -300,7 +300,7 @@ test('action activate order service not created exception', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $serviceMock); $service->setDi($di); - expect(fn () => $service->action_activate($order)) + expect(fn (): bool => $service->action_activate($order)) ->toThrow(Exception::class); }); @@ -345,7 +345,7 @@ test('active service not found exception', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $serviceMock); $service->setDi($di); - expect(fn () => $service->action_renew($order)) + expect(fn (): bool => $service->action_renew($order)) ->toThrow(Exception::class); }); diff --git a/src/modules/Servicedomain/Service.php b/src/modules/Servicedomain/Service.php index 0e828517d..13651d1a3 100644 --- a/src/modules/Servicedomain/Service.php +++ b/src/modules/Servicedomain/Service.php @@ -58,7 +58,7 @@ class Service implements \FOSSBilling\InjectionAwareInterface ]; } - public function getCartProductTitle(Product $product, array $data) + public function getCartProductTitle(Product $product, array $data): ?string { if ( isset($data['action']) && $data['action'] == 'register' diff --git a/src/modules/Servicedownloadable/tests/Unit/ServiceTest.php b/src/modules/Servicedownloadable/tests/Unit/ServiceTest.php index 9182dc72d..69e1f89d5 100644 --- a/src/modules/Servicedownloadable/tests/Unit/ServiceTest.php +++ b/src/modules/Servicedownloadable/tests/Unit/ServiceTest.php @@ -23,7 +23,6 @@ function serviceDownloadableCreateProductEntity(?int $id = null, ?string $config $product = new Product(); if ($id !== null) { $reflection = new ReflectionProperty($product, 'id'); - $reflection->setAccessible(true); $reflection->setValue($product, $id); } if ($config !== null) { @@ -155,6 +154,6 @@ test('validate file upload rejects unknown extension', function (): void { $reflection = new ReflectionMethod(Service::class, 'validateFileUpload'); - expect(fn () => $reflection->invoke($service, $file)) + expect(fn (): mixed => $reflection->invoke($service, $file)) ->toThrow(FOSSBilling\Exception::class); }); diff --git a/src/modules/Servicehosting/Service.php b/src/modules/Servicehosting/Service.php index e2f03ea3f..2393df670 100644 --- a/src/modules/Servicehosting/Service.php +++ b/src/modules/Servicehosting/Service.php @@ -76,7 +76,7 @@ class Service implements InjectionAwareInterface } } - public function getCartProductTitle(Product $product, array $data) + public function getCartProductTitle(Product $product, array $data): ?string { try { $data = array_merge(json_decode($product->getConfig() ?? '', true) ?? [], $data); diff --git a/src/modules/Servicehosting/tests/Unit/ServiceTest.php b/src/modules/Servicehosting/tests/Unit/ServiceTest.php index 4dcd85e98..9295ac30e 100644 --- a/src/modules/Servicehosting/tests/Unit/ServiceTest.php +++ b/src/modules/Servicehosting/tests/Unit/ServiceTest.php @@ -105,7 +105,7 @@ test('action renew order without active service', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $orderServiceMock); $service->setDi($di); - expect(fn () => $service->action_renew($orderModel)) + expect(fn (): bool => $service->action_renew($orderModel)) ->toThrow(FOSSBilling\Exception::class, sprintf('Order %d has no active service', $orderModel->id)); }); @@ -151,7 +151,7 @@ test('action suspend order without active service', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $orderServiceMock); $service->setDi($di); - expect(fn () => $service->action_suspend($orderModel)) + expect(fn (): bool => $service->action_suspend($orderModel)) ->toThrow(FOSSBilling\Exception::class, sprintf('Order %d has no active service', $orderModel->id)); }); @@ -197,7 +197,7 @@ test('action unsuspend order without active service', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $orderServiceMock); $service->setDi($di); - expect(fn () => $service->action_unsuspend($orderModel)) + expect(fn (): bool => $service->action_unsuspend($orderModel)) ->toThrow(FOSSBilling\Exception::class, sprintf('Order %d has no active service', $orderModel->id)); }); @@ -243,7 +243,7 @@ test('action cancel order without active service', function (): void { $di['mod_service'] = $di->protect(fn (): Mockery\MockInterface => $orderServiceMock); $service->setDi($di); - expect(fn () => $service->action_cancel($orderModel)) + expect(fn (): bool => $service->action_cancel($orderModel)) ->toThrow(FOSSBilling\Exception::class, sprintf('Order %d has no active service', $orderModel->id)); }); @@ -345,7 +345,7 @@ test('change account username missing username', function (): void { $model->loadBean(new Tests\Helpers\DummyBean()); $data = []; - expect(fn () => $service->changeAccountUsername($orderModel, $model, $data)) + expect(fn (): bool => $service->changeAccountUsername($orderModel, $model, $data)) ->toThrow(FOSSBilling\Exception::class, 'Account username is missing or is invalid'); }); @@ -391,7 +391,7 @@ test('change account ip missing ip', function (): void { $model = new Model_ServiceHosting(); $model->loadBean(new Tests\Helpers\DummyBean()); - expect(fn () => $service->changeAccountIp($orderModel, $model, $data)) + expect(fn (): bool => $service->changeAccountIp($orderModel, $model, $data)) ->toThrow(FOSSBilling\Exception::class, 'Account IP address is missing or is invalid'); }); @@ -438,7 +438,7 @@ test('change account domain missing params', function (): void { $model = new Model_ServiceHosting(); $model->loadBean(new Tests\Helpers\DummyBean()); - expect(fn () => $service->changeAccountDomain($orderModel, $model, $data)) + expect(fn (): bool => $service->changeAccountDomain($orderModel, $model, $data)) ->toThrow(FOSSBilling\Exception::class, 'Domain SLD or TLD is missing'); }); @@ -485,7 +485,7 @@ test('change account password missing params', function (): void { $model = new Model_ServiceHosting(); $model->loadBean(new Tests\Helpers\DummyBean()); - expect(fn () => $service->changeAccountPassword($orderModel, $model, $data)) + expect(fn (): bool => $service->changeAccountPassword($orderModel, $model, $data)) ->toThrow(FOSSBilling\Exception::class, 'Account password is missing or is invalid'); }); diff --git a/src/modules/Servicelicense/tests/Unit/ServiceTest.php b/src/modules/Servicelicense/tests/Unit/ServiceTest.php index 858471983..c4e30e1f1 100644 --- a/src/modules/Servicelicense/tests/Unit/ServiceTest.php +++ b/src/modules/Servicelicense/tests/Unit/ServiceTest.php @@ -154,7 +154,7 @@ test('action activate license collision max iterations exception', function (): $service->setDi($di); - expect(fn () => $service->action_activate($clientOrderModel)) + expect(fn (): bool => $service->action_activate($clientOrderModel)) ->toThrow(FOSSBilling\Exception::class); }); @@ -177,7 +177,7 @@ test('action activate plugin not found', function (): void { $service->setDi($di); - expect(fn () => $service->action_activate($clientOrderModel)) + expect(fn (): bool => $service->action_activate($clientOrderModel)) ->toThrow(FOSSBilling\Exception::class, "License plugin {$serviceLicenseModel->plugin} was not found."); }); @@ -195,7 +195,7 @@ test('action activate order activation exception', function (): void { $service->setDi($di); - expect(fn () => $service->action_activate($clientOrderModel)) + expect(fn (): bool => $service->action_activate($clientOrderModel)) ->toThrow(FOSSBilling\Exception::class, 'Could not activate order. Service was not created'); }); diff --git a/src/modules/Staff/tests/Unit/ServiceTest.php b/src/modules/Staff/tests/Unit/ServiceTest.php index e3d5d7a26..54bf4eda7 100644 --- a/src/modules/Staff/tests/Unit/ServiceTest.php +++ b/src/modules/Staff/tests/Unit/ServiceTest.php @@ -312,7 +312,7 @@ test('onAfterClientReplyTicket sends email notification', function (): void { $emailServiceMock = Mockery::mock(Box\Mod\Email\Service::class); $emailServiceMock->shouldReceive('sendTemplate')->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_staff_ticket_reply')); + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_staff_ticket_reply')); $eventMock->shouldReceive('getparameters')->atLeast()->once() ->andReturn(['id' => random_int(1, 100)]); @@ -380,7 +380,7 @@ test('onAfterClientCloseTicket sends email notification', function (): void { $emailServiceMock = Mockery::mock(Box\Mod\Email\Service::class); $emailServiceMock->shouldReceive('sendTemplate')->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_staff_ticket_close')); + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_staff_ticket_close')); $eventMock->shouldReceive('getparameters')->atLeast()->once() ->andReturn(['id' => random_int(1, 100)]); @@ -448,7 +448,7 @@ test('onAfterClientOpenTicket sends guest email notification', function (): void $emailServiceMock = Mockery::mock(Box\Mod\Email\Service::class); $emailServiceMock->shouldReceive('sendTemplate')->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_staff_ticket_open')); + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_staff_ticket_open')); $eventMock->shouldReceive('getparameters')->atLeast()->once() ->andReturn(['id' => random_int(1, 100)]); @@ -516,7 +516,7 @@ test('onAfterClientReplyTicket sends guest email notification', function (): voi $emailServiceMock = Mockery::mock(Box\Mod\Email\Service::class); $emailServiceMock->shouldReceive('sendTemplate')->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_staff_ticket_reply')); + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_staff_ticket_reply')); $eventMock->shouldReceive('getparameters')->atLeast()->once() ->andReturn(['id' => random_int(1, 100)]); diff --git a/src/modules/Support/Controller/Client.php b/src/modules/Support/Controller/Client.php index c6895f43a..07a139acf 100644 --- a/src/modules/Support/Controller/Client.php +++ b/src/modules/Support/Controller/Client.php @@ -67,7 +67,7 @@ class Client implements \FOSSBilling\InjectionAwareInterface /** * A redirect to keep old guest ticket links working. - * + * * /support/contact-us/conversation/:hash -> /support/ticket/:hash */ public function get_ticket_redirect(\Box_App $app, $hash): never diff --git a/src/modules/Support/Service.php b/src/modules/Support/Service.php index 3d415151c..29e465ae4 100644 --- a/src/modules/Support/Service.php +++ b/src/modules/Support/Service.php @@ -175,8 +175,8 @@ class Service implements \FOSSBilling\InjectionAwareInterface } /** - * Determine if the provided ticket is a guest ticket - * + * Determine if the provided ticket is a guest ticket. + * * @todo Doctrine: Move this to the Entity when migrating to Doctrine */ public function isGuestTicket(\Model_SupportTicket $ticket): bool @@ -1083,7 +1083,7 @@ class Service implements \FOSSBilling\InjectionAwareInterface } $data['email'] = $this->di['tools']->validateAndSanitizeEmail($data['email']); - $data['content'] = $data['content'] ?? $data['message'] ?? null; + $data['content'] ??= $data['message'] ?? null; SupportTicketValidator::validateTicketCreation($data); diff --git a/src/modules/Support/tests/Unit/ServiceTest.php b/src/modules/Support/tests/Unit/ServiceTest.php index 43a7d9612..5bee7d41b 100644 --- a/src/modules/Support/tests/Unit/ServiceTest.php +++ b/src/modules/Support/tests/Unit/ServiceTest.php @@ -65,7 +65,7 @@ test('handles after client open ticket event', function (): void { $emailServiceMock = Mockery::mock(EmailService::class); $emailServiceMock->shouldReceive('sendTemplate') ->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_support_ticket_open')) + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_support_ticket_open')) ->andReturn(true); $di = container(); @@ -112,7 +112,7 @@ test('handles after admin open ticket event', function (): void { $emailServiceMock = Mockery::mock(EmailService::class); $emailServiceMock->shouldReceive('sendTemplate') ->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_support_ticket_staff_open')) + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_support_ticket_staff_open')) ->andReturn(true); $di = container(); @@ -159,7 +159,7 @@ test('handles after admin close ticket event', function (): void { $emailServiceMock = Mockery::mock(EmailService::class); $emailServiceMock->shouldReceive('sendTemplate') ->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_support_ticket_staff_close')) + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_support_ticket_staff_close')) ->andReturn(true); $di = container(); @@ -206,7 +206,7 @@ test('handles after admin reply ticket event', function (): void { $emailServiceMock = Mockery::mock(EmailService::class); $emailServiceMock->shouldReceive('sendTemplate') ->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_support_ticket_staff_reply')) + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_support_ticket_staff_reply')) ->andReturn(true); $di = container(); @@ -256,7 +256,7 @@ test('handles guest ticket with regular client open event', function (): void { $emailServiceMock = Mockery::mock(EmailService::class); $emailServiceMock->shouldReceive('sendTemplate') ->atLeast()->once() - ->with(Mockery::on(fn ($email) => $email['code'] === 'mod_support_ticket_open' && $email['to'] === 'email@example.com')) + ->with(Mockery::on(fn ($email): bool => $email['code'] === 'mod_support_ticket_open' && $email['to'] === 'email@example.com')) ->andReturn(true); $di = container(); @@ -1847,7 +1847,7 @@ test('guest ticket reply', function (): void { $ticket->loadBean(new Tests\Helpers\DummyBean()); $ticket->access_hash = 'test-hash-123'; - $result = $service->ticketReply($ticket, new \Model_Guest(), 'Content'); + $result = $service->ticketReply($ticket, new Model_Guest(), 'Content'); expect($result)->toBeInt(); });