Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
e19c9ceb
Commit
e19c9ceb
authored
Nov 20, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx has many relation test prepared.
parent
6a5b8d19
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
1 deletion
+49
-1
ArticleIndex.php
tests/unit/data/sphinx/ar/ArticleIndex.php
+5
-0
TagDb.php
tests/unit/data/sphinx/ar/TagDb.php
+13
-0
source.sql
tests/unit/data/sphinx/source.sql
+14
-1
ExternalActiveRelationTest.php
tests/unit/extensions/sphinx/ExternalActiveRelationTest.php
+17
-0
No files found.
tests/unit/data/sphinx/ar/ArticleIndex.php
View file @
e19c9ceb
...
...
@@ -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
;
...
...
tests/unit/data/sphinx/ar/TagDb.php
0 → 100644
View file @
e19c9ceb
<?php
namespace
yiiunit\data\sphinx\ar
;
use
yiiunit\data\ar\ActiveRecord
as
ActiveRecordDb
;
class
TagDb
extends
ActiveRecordDb
{
public
static
function
tableName
()
{
return
'yii2_test_tag'
;
}
}
\ No newline at end of file
tests/unit/data/sphinx/source.sql
View file @
e19c9ceb
...
...
@@ -4,6 +4,7 @@
DROP
TABLE
IF
EXISTS
yii2_test_article
;
DROP
TABLE
IF
EXISTS
yii2_test_item
;
DROP
TABLE
IF
EXISTS
yii2_test_tag
;
DROP
TABLE
IF
EXISTS
yii2_test_article_tag
;
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_article`
(
...
...
@@ -22,7 +23,13 @@ CREATE TABLE IF NOT EXISTS `yii2_test_item` (
`category_id`
int
(
11
)
NOT
NULL
,
`price`
float
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
3
;
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_tag`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
`name`
varchar
(
255
)
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
MyISAM
DEFAULT
CHARSET
=
utf8
AUTO_INCREMENT
=
5
;
CREATE
TABLE
IF
NOT
EXISTS
`yii2_test_article_tag`
(
`article_id`
int
(
11
)
NOT
NULL
,
...
...
@@ -38,6 +45,12 @@ INSERT INTO `yii2_test_item` (`id`, `name`, `description`, `category_id`, `price
(
1
,
'pencil'
,
'Simple pencil'
,
1
,
2
.
5
),
(
2
,
'table'
,
'Wooden table'
,
2
,
100
);
INSERT
INTO
`yii2_test_tag`
(
`id`
,
`name`
)
VALUES
(
1
,
'tag1'
),
(
2
,
'tag2'
),
(
3
,
'tag3'
),
(
4
,
'tag4'
);
INSERT
INTO
`yii2_test_article_tag`
(
`article_id`
,
`tag_id`
)
VALUES
(
1
,
1
),
(
1
,
2
),
...
...
tests/unit/extensions/sphinx/ExternalActiveRelationTest.php
View file @
e19c9ceb
...
...
@@ -6,6 +6,7 @@ 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
;
use
yiiunit\data\sphinx\ar\TagDb
;
/**
* @group sphinx
...
...
@@ -25,21 +26,37 @@ class ExternalActiveRelationTest extends SphinxTestCase
{
/** @var ArticleIndex $article */
$article
=
ArticleIndex
::
find
([
'id'
=>
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'));*/
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment