/** * @test */ public function it_should_reindex_on_model_save() { /** * * Expectation * */ Facade::clearResolvedInstances(); $proxy = m::mock('Iverberk\\Larasearch\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('iverberk.larasearch.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); Config::shouldReceive('get')->with('/^larasearch::reversedPaths\\.Husband$/', array())->once()->andReturn(['', 'wife', 'children', 'children.toys']); Queue::shouldReceive('push')->with('Iverberk\\Larasearch\\Jobs\\ReindexJob', ['Husband:2', 'Wife:2', 'Child:2', 'Toy:2'])->once(); /** * * * Assertion * */ $husband = \Husband::find(2); with(new Observer())->saved($husband); /** * * Expectation * */ Facade::clearResolvedInstances(); $proxy = m::mock('Iverberk\\Larasearch\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('iverberk.larasearch.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); Config::shouldReceive('get')->with('/^larasearch::reversedPaths\\.Toy$/', array())->once()->andReturn(['', 'children', 'children.mother.husband', 'children.mother']); Queue::shouldReceive('push')->with('Iverberk\\Larasearch\\Jobs\\ReindexJob', ['Toy:2', 'Child:8', 'Child:2', 'Husband:8', 'Husband:2', 'Wife:8', 'Wife:2'])->once(); /** * * * Assertion * */ $toy = \Toy::find(2); with(new Observer())->saved($toy); }
public function testI18nWithRelations2() { \MovieQuery::create()->deleteAll(); $count = \MovieQuery::create()->count(); $this->assertEquals(0, $count, 'No movie before the test'); \ToyQuery::create()->deleteAll(); $count = \ToyQuery::create()->count(); $this->assertEquals(0, $count, 'No toy before the test'); \ToyI18nQuery::create()->deleteAll(); $count = \ToyI18nQuery::create()->count(); $this->assertEquals(0, $count, 'No i18n toys before the test'); \MovieI18nQuery::create()->deleteAll(); $count = \MovieI18nQuery::create()->count(); $this->assertEquals(0, $count, 'No i18n movies before the test'); $t = new \Toy(); $t->setLocale('en'); $t->setName('My Name'); $t->setLocale('fr'); $t->setName('Mon Nom'); $t->setLocale('en'); $this->assertEquals('My Name', $t->getName()); $t->setLocale('fr'); $this->assertEquals('Mon Nom', $t->getName()); $m = new \Movie(); $m->addToy($t); $m->save(); $count = \MovieQuery::create()->count(); $this->assertEquals(1, $count, '1 movie'); $count = \ToyQuery::create()->count(); $this->assertEquals(1, $count, '1 toy'); $count = \ToyI18nQuery::create()->count(); $this->assertEquals(2, $count, '2 i18n toys'); $count = \MovieI18nQuery::create()->count(); $this->assertEquals(0, $count, '0 i18n movies'); }
public function roll() { parent::ping(); return 'rolling'; }
/** * @test */ public function it_should_reindex_on_model_save() { /** * * Expectation * */ Facade::clearResolvedInstances(); $config = m::mock('Menthol\\Flexible\\Config'); $proxy = m::mock('Menthol\\Flexible\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('menthol.flexible.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->andReturn($config); $config->shouldReceive('get')->with('reversedPaths.Husband', [])->once()->andReturn(['', 'wife', 'children', 'children.toys']); Queue::shouldReceive('push')->with('Menthol\\Flexible\\Jobs\\ReindexJob', ['Husband:2', 'Wife:2', 'Child:2', 'Toy:2'])->once(); /** * * Assertion * */ $husband = \Husband::find(2); $husband->clearProxy(); with(new Observer())->saved($husband); /** * * Expectation * */ Facade::clearResolvedInstances(); $config = m::mock('Menthol\\Flexible\\Config'); $proxy = m::mock('Menthol\\Flexible\\Proxy'); $proxy->shouldReceive('shouldIndex')->andReturn(true); App::shouldReceive('make')->with('menthol.flexible.proxy', m::type('Illuminate\\Database\\Eloquent\\Model'))->andReturn($proxy); App::shouldReceive('make')->with('Menthol\\Flexible\\Config')->andReturn($config); $config->shouldReceive('get')->with('reversedPaths.Toy', [])->once()->andReturn(['', 'children', 'children.mother.husband', 'children.mother']); Queue::shouldReceive('push')->with('Menthol\\Flexible\\Jobs\\ReindexJob', ['Toy:2', 'Child:8', 'Child:2', 'Husband:8', 'Husband:2', 'Wife:8', 'Wife:2'])->once(); /** * * Assertion * */ $toy = \Toy::find(2); with(new Observer())->saved($toy); }