/** * @test */ public function it_can_reindex_when_alias_exists() { /** * * Set * */ $indexDouble = am::double('Menthol\\Flexible\\Index', ['refresh' => null, 'clean' => null, 'updateAliases' => null, 'getAlias' => ['mockIndex' => 'aliases']]); $indexMock = m::mock('Menthol\\Flexible\\Index'); $operations[] = ['add' => ['alias' => 'Husband', 'index' => 'Husband_9999'], 'remove' => ['alias' => 'Husband', 'index' => 'mockIndex']]; $actions[] = ['actions' => $operations]; $test = $this; /** * * Expectation * */ $this->index->shouldReceive('getName')->andReturn('Husband'); $indexMock->shouldReceive('create')->once()->andReturn(); $indexMock->shouldReceive('aliasExists')->once()->andReturn(true); $indexMock->shouldReceive('import')->andReturn(); App::shouldReceive('make')->with('menthol.flexible.index', ['name' => 'Husband_9999', 'proxy' => $this->proxy])->andReturn($indexMock); /** * * Assertion * */ $this->proxy->reindex(); $indexDouble->verifyInvoked('refresh', 'Husband'); $indexDouble->verifyInvoked('clean', 'Husband'); $indexDouble->verifyInvoked('updateAliases', function ($calls) use($test, $actions) { $test->assertEquals($actions, $calls[0]); }); }