/** * @param State\Booking $booking * @return bool */ public function pay(State\Booking $booking) { // ... // Do the necessary to pay // ... $booking->setState(new Reserved()); return true; }
/** * The reservation can always be canceled * @param State\Booking $booking * @return bool */ public function cancel(State\Booking $booking) { // ... // Cancel the reservation // ... $booking->setState(new Cancelled()); return true; }
public function testCancelledStateMechanism() { $this->booking->setState(new BookingState\Cancelled()); $this->setExpectedException('Exception', 'Already cancelled'); $this->booking->cancel(); $this->setExpectedException('Exception', 'Order cancelled'); $this->booking->pay(); $this->setExpectedException('Exception', 'Order cancelled'); $this->booking->reserve(); }