order = factory(Order::class)->create([ "user_id" => factory(User::class)->create()->id ]); Auth::login(User::find($this->order->user->id)); } public function testCreation() { $this->assertInstanceOf('SM\StateMachine\StateMachine', $this->order->getStateMachine()); } public function testGetState() { $this->assertEquals('new', $this->order->state()); } public function testApplyState() { $this->order->state('process'); $this->assertEquals('processed', $this->order->state()); $this->assertEquals(1,$this->order->history()->count()); $this->order->state('ship'); $this->assertEquals('shipped', $this->order->state()); $this->assertEquals(2,$this->order->history()->count()); } public function testCanTransitState() { $this->assertTrue($this->order->transitionAllowed('process')); $this->assertFalse($this->order->transitionAllowed('ship')); } public function testInvalidTransition() { $this->expectException(SMException::class); $this->order->state('ship'); } }