Skip to content

Commit b5ce796

Browse files
committed
Catch more specific exceptions
1 parent ca3612c commit b5ce796

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313

1414
sudo: false
1515

16+
env: SYLIUS_CACHE_DIR=$HOME/.sylius-cache SYLIUS_BUILD_DIR=etc/build
17+
1618
cache:
1719
yarn: true
1820
directories:

src/Action/Admin/RefundUnitsAction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Sylius\RefundPlugin\Action\Admin;
66

77
use Sylius\RefundPlugin\Creator\RefundUnitsCommandCreatorInterface;
8+
use Sylius\RefundPlugin\Exception\OrderNotFound;
89
use Symfony\Component\HttpFoundation\RedirectResponse;
910
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
@@ -44,7 +45,7 @@ public function __invoke(Request $request): Response
4445
$this->commandBus->dispatch($this->commandCreator->fromRequest($request));
4546

4647
$this->session->getFlashBag()->add('success', 'sylius_refund.units_successfully_refunded');
47-
} catch (\Exception $exception) {
48+
} catch (\InvalidArgumentException | OrderNotFound $exception) {
4849
$this->session->getFlashBag()->add('error', $exception->getMessage());
4950
}
5051

tests/Behat/Context/Application/RefundingContext.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function decideToRefundPartFromProductWithPayment(
104104
$paymentMethod->getId(),
105105
''
106106
));
107-
} catch (\Exception $exception) {
107+
} catch(\InvalidArgumentException | OrderNotFound $exception) {
108108
return;
109109
}
110110
}
@@ -145,7 +145,7 @@ public function tryToRefundPartOfOrderShipment(int $amount, PaymentMethodInterfa
145145
$this->commandBus->dispatch(new RefundUnits(
146146
$this->order->getNumber(), [], [new ShipmentRefund($shippingAdjustment->getId(), $amount)], $paymentMethod->getId(), ''
147147
));
148-
} catch (\Exception $exception) {
148+
} catch(\InvalidArgumentException | OrderNotFound $exception) {
149149
return;
150150
}
151151
}
@@ -222,7 +222,7 @@ public function shouldNotBeAbleToRefundUnitWithProduct(int $unitNumber, string $
222222
1,
223223
''
224224
));
225-
} catch (\Exception $exception) {
225+
} catch(\InvalidArgumentException | OrderNotFound $exception) {
226226
return;
227227
}
228228

@@ -245,7 +245,7 @@ public function shouldNotBeAbleToRefundOrderShipment(): void
245245
1,
246246
''
247247
));
248-
} catch (\Exception $exception) {
248+
} catch(\InvalidArgumentException | OrderNotFound $exception) {
249249
return;
250250
}
251251

@@ -265,7 +265,7 @@ public function shouldStillBeAbleToRefundOrderShipment(PaymentMethodInterface $p
265265
$this->commandBus->dispatch(new RefundUnits(
266266
$this->order->getNumber(), [], [new ShipmentRefund($shippingAdjustment->getId(), $remainingTotal)], $paymentMethod->getId(), ''
267267
));
268-
} catch (\Exception $exception) {
268+
} catch(\InvalidArgumentException | OrderNotFound $exception) {
269269
throw new \Exception('RefundUnits command should not fail');
270270
}
271271
}

0 commit comments

Comments
 (0)