Skip to content

Commit

Permalink
Add more eager loading test
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiCollin committed Jun 19, 2018
1 parent 53a38dc commit a06ff22
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/cases/ProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function bars(Foo $foo)
}

/** @test */
public function relationships_within_the_with_property_are_always_eager_loaded()
public function many_relationships_within_the_with_property_are_always_eager_loaded()
{
$this->migrate('foos', function ($table) {
$table->increments('id');
Expand Down Expand Up @@ -134,4 +134,45 @@ public function bars(Foo $foo)
$this->assertInstanceOf(Illuminate\Support\Collection::class, $loadedFoo->bars);
$this->assertNotInstanceOf(Analogue\ORM\System\Proxies\CollectionProxy::class, $loadedFoo->bars);
}

/** @test */
public function single_relationships_within_the_with_property_are_always_eager_loaded()
{
$this->migrate('foos', function ($table) {
$table->increments('id');
$table->string('title');
});
$this->migrate('bars', function ($table) {
$table->increments('id');
$table->integer('foo_id')->nullable();
$table->string('title');
});
$this->analogue->register(Foo::class, new class() extends EntityMap {

});
$this->analogue->register(Bar::class, new class() extends EntityMap {
protected $with = ['foo'];
public function foo(Bar $bar)
{
return $this->belongsTo($bar, Foo::class);
}
});
$bar = new Bar();
$bar->title = 'Test';
$bar->foo = new Foo();
$bar->foo->title = "test";
mapper($bar)->store($bar);
$this->clearCache();
$loadedBar = mapper($bar)->find($bar->id);
$this->assertNotNull($loadedBar);
$this->assertInstanceOf(Foo::class, $loadedBar->foo);
$this->assertNotInstanceOf(\ProxyManager\Proxy\LazyLoadingInterface::class, $loadedBar->foo);
$bar = new Bar();
$bar->title = 'Test';
mapper($bar)->store($bar);
$this->clearCache();
$loadedBar = mapper($bar)->find($bar->id);
$this->assertNotNull($loadedBar);
$this->assertNull($loadedBar->foo);
}
}

0 comments on commit a06ff22

Please sign in to comment.