public function testMoved() { $dispatcher = Category::getEventDispatcher(); Category::setEventDispatcher($events = m::mock('Illuminate\\Contracts\\Events\\Dispatcher')); $closure = function () { }; $events->shouldReceive('listen')->once()->with('eloquent.moved: ' . get_class(new Category()), $closure, 0); Category::moved($closure); Category::unsetEventDispatcher(); Category::setEventDispatcher($dispatcher); }
public function testMovementHaltsWhenReturningFalseFromMoving() { $unchanged = $this->categories('Child 2'); $dispatcher = Category::getEventDispatcher(); Category::setEventDispatcher($events = m::mock('Illuminate\\Events\\Dispatcher[until]')); $events->shouldReceive('until')->once()->with('eloquent.moving: ' . get_class($unchanged), $unchanged)->andReturn(false); // Force "moving" to return false Category::moving(function ($node) { return false; }); $unchanged->makeRoot(); $unchanged->reload(); $this->assertEquals(1, $unchanged->getParentId()); $this->assertEquals(1, $unchanged->getLevel()); $this->assertEquals(4, $unchanged->getLeft()); $this->assertEquals(7, $unchanged->getRight()); // Restore Category::getEventDispatcher()->forget('eloquent.moving: ' . get_class($unchanged)); Category::unsetEventDispatcher(); Category::setEventDispatcher($dispatcher); }