function it_performs_action_as_given_admin_user_and_logout(SecurityServiceInterface $adminSecurityService, OrderInterface $order, AdminUserInterface $adminUser) { $adminSecurityService->getCurrentToken()->willThrow(TokenNotFoundException::class); $adminSecurityService->logIn($adminUser)->shouldBeCalled(); $order->completeCheckout()->shouldBeCalled(); $adminSecurityService->restoreToken(Argument::any())->shouldNotBeCalled(); $adminSecurityService->logOut()->shouldBeCalled(); $wrappedOrder = $order->getWrappedObject(); $this->performActionAsAdminUser($adminUser, function () use($wrappedOrder) { $wrappedOrder->completeCheckout(); }); }