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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
6bfc888c
Commit
6bfc888c
authored
Nov 18, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx Active Relation created
parent
c355fed2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
24 deletions
+108
-24
ActiveRelation.php
extensions/sphinx/ActiveRelation.php
+23
-0
ArticleDb.php
tests/unit/data/sphinx/ar/ArticleDb.php
+13
-0
ActiveRelationTest.php
tests/unit/extensions/sphinx/ActiveRelationTest.php
+14
-24
ExternalActiveRelationTest.php
tests/unit/extensions/sphinx/ExternalActiveRelationTest.php
+58
-0
No files found.
extensions/sphinx/ActiveRelation.php
0 → 100644
View file @
6bfc888c
<?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
;
}
\ No newline at end of file
tests/unit/data/sphinx/ar/ArticleDb.php
View file @
6bfc888c
...
...
@@ -2,6 +2,7 @@
namespace
yiiunit\data\sphinx\ar
;
use
yii\sphinx\ActiveRelation
;
use
yiiunit\data\ar\ActiveRecord
as
ActiveRecordDb
;
class
ArticleDb
extends
ActiveRecordDb
...
...
@@ -10,4 +11,15 @@ class ArticleDb extends ActiveRecordDb
{
return
'yii2_test_article'
;
}
public
function
getIndex
()
{
$config
=
[
'modelClass'
=>
ArticleIndex
::
className
(),
'primaryModel'
=>
$this
,
'link'
=>
[
'id'
=>
'id'
],
'multiple'
=>
false
,
];
return
new
ActiveRelation
(
$config
);
}
}
\ No newline at end of file
tests/unit/extensions/sphinx/ActiveRelationTest.php
View file @
6bfc888c
...
...
@@ -19,37 +19,26 @@ class ActiveRelationTest extends SphinxTestCase
ActiveRecordDb
::
$db
=
$this
->
getDbConnection
();
}
// Tests :
public
function
testFindLazy
()
{
/** @var Article
Index
$article */
$article
=
Article
Index
::
find
([
'id'
=>
2
]);
$this
->
assertFalse
(
$article
->
isRelationPopulated
(
'
source
'
));
$
source
=
$article
->
source
;
$this
->
assertTrue
(
$article
->
isRelationPopulated
(
'
source
'
));
$this
->
assertTrue
(
$
source
instanceof
ArticleDb
);
/** @var Article
Db
$article */
$article
=
Article
Db
::
find
([
'id'
=>
2
]);
$this
->
assertFalse
(
$article
->
isRelationPopulated
(
'
index
'
));
$
index
=
$article
->
index
;
$this
->
assertTrue
(
$article
->
isRelationPopulated
(
'
index
'
));
$this
->
assertTrue
(
$
index
instanceof
ArticleIndex
);
$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
();
$articles
=
ArticleDb
::
find
()
->
with
(
'index'
)
->
all
();
$this
->
assertEquals
(
2
,
count
(
$articles
));
$this
->
assertTrue
(
$articles
[
0
]
->
isRelationPopulated
(
'index'
));
$this
->
assertTrue
(
$articles
[
1
]
->
isRelationPopulated
(
'index'
));
$this
->
assertTrue
(
$articles
[
0
]
->
index
instanceof
ArticleIndex
);
$this
->
assertTrue
(
$articles
[
1
]
->
index
instanceof
ArticleIndex
);
}
}
\ No newline at end of file
tests/unit/extensions/sphinx/ExternalActiveRelationTest.php
0 → 100644
View file @
6bfc888c
<?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
));
}
}
\ No newline at end of file
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