public function testShouldReturnLazyLoadingCursor()
{
$parentCategory = new Category();
$parentCategory->setName('Parent category');
$parentCategory->setDesc('Parent category');
$parentCategory->save();
for ($i = 0; $i < 10; $i++) {
$category = new Category();
$category->setName('Category ' . $i);
$category->setDesc('Category ' . $i . ' desc');
$category->setCategory($parentCategory);
$category->save();
}
Category::enableLazyLoading();
$categories = Category::find([['category' => ['$ne' => null]]]);
$this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
foreach ($categories as $category) {
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category->getCategory());
}
$categories = Category::find([['category' => ['$ne' => null]]]);
$this->assertInstanceOf('\\Vegas\\Odm\\Collection\\LazyLoadingCursor', $categories);
foreach ($categories as $category) {
$this->assertInstanceOf('\\Fixtures\\Collection\\Category', $category);
$reflectionClass = new \ReflectionClass(get_class($category));
$categoryProperty = $reflectionClass->getProperty('category');
$categoryProperty->setAccessible(true);
$this->assertTrue(\MongoDBRef::isRef($categoryProperty->getValue($category)));
}
}