Paul Klimov
11 years ago
4 changed files with 104 additions and 24 deletions
@ -0,0 +1,22 @@ |
|||||||
|
<?php |
||||||
|
/** |
||||||
|
* @link http://www.yiiframework.com/ |
||||||
|
* @copyright Copyright (c) 2008 Yii Software LLC |
||||||
|
* @license http://www.yiiframework.com/license/ |
||||||
|
*/ |
||||||
|
|
||||||
|
namespace yii\sphinx; |
||||||
|
|
||||||
|
use yii\db\ActiveRelationInterface; |
||||||
|
use yii\db\ActiveRelationTrait; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class ActiveRelation |
||||||
|
* |
||||||
|
* @author Paul Klimov <klimov.paul@gmail.com> |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
class ActiveRelation extends ActiveQuery implements ActiveRelationInterface |
||||||
|
{ |
||||||
|
use ActiveRelationTrait; |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yiiunit\extensions\sphinx; |
||||||
|
|
||||||
|
use yiiunit\data\sphinx\ar\ActiveRecord; |
||||||
|
use yiiunit\data\ar\ActiveRecord as ActiveRecordDb; |
||||||
|
use yiiunit\data\sphinx\ar\ArticleIndex; |
||||||
|
use yiiunit\data\sphinx\ar\ArticleDb; |
||||||
|
|
||||||
|
/** |
||||||
|
* @group sphinx |
||||||
|
*/ |
||||||
|
class ExternalActiveRelationTest extends SphinxTestCase |
||||||
|
{ |
||||||
|
protected function setUp() |
||||||
|
{ |
||||||
|
parent::setUp(); |
||||||
|
ActiveRecord::$db = $this->getConnection(); |
||||||
|
ActiveRecordDb::$db = $this->getDbConnection(); |
||||||
|
} |
||||||
|
|
||||||
|
// Tests : |
||||||
|
|
||||||
|
public function testFindLazy() |
||||||
|
{ |
||||||
|
/** @var ArticleIndex $article */ |
||||||
|
$article = ArticleIndex::find(['id' => 2]); |
||||||
|
$this->assertFalse($article->isRelationPopulated('source')); |
||||||
|
$source = $article->source; |
||||||
|
$this->assertTrue($article->isRelationPopulated('source')); |
||||||
|
$this->assertTrue($source instanceof ArticleDb); |
||||||
|
$this->assertEquals(1, count($article->populatedRelations)); |
||||||
|
} |
||||||
|
|
||||||
|
public function testFindEager() |
||||||
|
{ |
||||||
|
$articles = ArticleIndex::find()->with('source')->all(); |
||||||
|
$this->assertEquals(2, count($articles)); |
||||||
|
$this->assertTrue($articles[0]->isRelationPopulated('source')); |
||||||
|
$this->assertTrue($articles[1]->isRelationPopulated('source')); |
||||||
|
$this->assertTrue($articles[0]->source instanceof ArticleDb); |
||||||
|
$this->assertTrue($articles[1]->source instanceof ArticleDb); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @depends testFindEager |
||||||
|
*/ |
||||||
|
public function testFindWithSnippets() |
||||||
|
{ |
||||||
|
$articles = ArticleIndex::find() |
||||||
|
->match('about') |
||||||
|
->with('source') |
||||||
|
->snippetByModel() |
||||||
|
->all(); |
||||||
|
$this->assertEquals(2, count($articles)); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue