order = factory(Order::class)->create(); Auth::login(factory(User::class)->create()); } public function testCreation() { $this->assertInstanceOf('SM\StateMachine\StateMachine', $this->order->stateMachine()); } public function testGetState() { $this->assertEquals('new', $this->order->stateIs()); } public function testTransitionState() { $this->order->transition('process'); // let's refresh the model to see if the state was really persisted $this->order = $this->order->fresh(); $this->assertEquals('processed', $this->order->stateIs()); $this->assertEquals(1,$this->order->history()->count()); $this->order->transition('ship'); $this->order = $this->order->fresh(); $this->assertEquals('shipped', $this->order->stateIs()); $this->assertEquals(2,$this->order->history()->count()); } public function testTransitionAllowed() { $this->assertTrue($this->order->transitionAllowed('process')); $this->assertFalse($this->order->transitionAllowed('ship')); } public function testInvalidTransition() { $this->expectException(SMException::class); $this->order->transition('ship'); } }