From e19c9cebc6dff43a9b69357f66965d92b077b7d8 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Wed, 20 Nov 2013 13:14:21 +0200 Subject: [PATCH] Sphinx has many relation test prepared. --- tests/unit/data/sphinx/ar/ArticleIndex.php | 5 +++++ tests/unit/data/sphinx/ar/TagDb.php | 12 ++++++++++++ tests/unit/data/sphinx/source.sql | 15 ++++++++++++++- .../extensions/sphinx/ExternalActiveRelationTest.php | 17 +++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/unit/data/sphinx/ar/TagDb.php diff --git a/tests/unit/data/sphinx/ar/ArticleIndex.php b/tests/unit/data/sphinx/ar/ArticleIndex.php index 3865216..767fdea 100644 --- a/tests/unit/data/sphinx/ar/ArticleIndex.php +++ b/tests/unit/data/sphinx/ar/ArticleIndex.php @@ -23,6 +23,11 @@ class ArticleIndex extends ActiveRecord return $this->hasOne('db', ArticleDb::className(), ['id' => 'id']); } + public function getTags() + { + return $this->hasMany('db', TagDb::className(), ['id' => 'tag']); + } + public function getSnippetSource() { return $this->source->content; diff --git a/tests/unit/data/sphinx/ar/TagDb.php b/tests/unit/data/sphinx/ar/TagDb.php new file mode 100644 index 0000000..2d87eaf --- /dev/null +++ b/tests/unit/data/sphinx/ar/TagDb.php @@ -0,0 +1,12 @@ + 2]); + + // has one : $this->assertFalse($article->isRelationPopulated('source')); $source = $article->source; $this->assertTrue($article->isRelationPopulated('source')); $this->assertTrue($source instanceof ArticleDb); $this->assertEquals(1, count($article->populatedRelations)); + + // has many : + /*$this->assertFalse($article->isRelationPopulated('tags')); + $tags = $article->tags; + $this->assertTrue($article->isRelationPopulated('tags')); + $this->assertEquals(3, count($tags)); + $this->assertTrue($tags[0] instanceof TagDb);*/ } public function testFindEager() { + // has one : $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); + + // has many : + /*$articles = ArticleIndex::find()->with('tags')->all(); + $this->assertEquals(2, count($articles)); + $this->assertTrue($articles[0]->isRelationPopulated('tags')); + $this->assertTrue($articles[1]->isRelationPopulated('tags'));*/ } /**