public function commit() { $this->order->getConnection()->getPdo()->beginTransaction(); try { $this->order->save(); $this->storeOrderInSession(); $this->sendEmailToClient(); $this->sendEmailToAdmin(); $this->clearSession(); } catch (LoginRequiredException $e) { $this->logMailErrors(); } catch (Swift_TransportException $e) { $this->logMailErrors(); } catch (ValidationException $e) { $this->order->getConnection()->getPdo()->rollback(); $this->errors = $this->order->getErrors(); throw new InvalidException(); } $this->order->getConnection()->getPdo()->commit(); return $this; }
/** * @test **/ public function it_set_errors_on_save_if_validation_fails() { $order = new Order(); try { $order->save(); } catch (ValidationException $e) { } $this->assertFalse($order->getErrors()->isEmpty()); }