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
07ad008d
Commit
07ad008d
authored
Nov 13, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sphinx unit tests advanced.
parent
f4a8be1f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
1 deletion
+136
-1
Connection.php
extensions/sphinx/Connection.php
+11
-0
CommandTest.php
tests/unit/extensions/sphinx/CommandTest.php
+52
-0
SchemaTest.php
tests/unit/extensions/sphinx/SchemaTest.php
+72
-0
SphinxTestCase.php
tests/unit/extensions/sphinx/SphinxTestCase.php
+1
-1
No files found.
extensions/sphinx/Connection.php
View file @
07ad008d
...
@@ -10,6 +10,7 @@ namespace yii\sphinx;
...
@@ -10,6 +10,7 @@ namespace yii\sphinx;
/**
/**
* Class Connection
* Class Connection
*
*
* @property Schema $schema The schema information for this Sphinx connection. This property is read-only.
* @method Schema getSchema() The schema information for this Sphinx connection
* @method Schema getSchema() The schema information for this Sphinx connection
*
*
* @author Paul Klimov <klimov.paul@gmail.com>
* @author Paul Klimov <klimov.paul@gmail.com>
...
@@ -50,6 +51,16 @@ class Connection extends \yii\db\Connection
...
@@ -50,6 +51,16 @@ class Connection extends \yii\db\Connection
}
}
/**
/**
* Alias of [[quoteIndexName()]].
* @param string $name table name
* @return string the properly quoted table name
*/
public
function
quoteTableName
(
$name
)
{
return
$this
->
quoteIndexName
(
$name
);
}
/**
* Creates a command for execution.
* Creates a command for execution.
* @param string $sql the SQL statement to be executed
* @param string $sql the SQL statement to be executed
* @param array $params the parameters to be bound to the SQL statement
* @param array $params the parameters to be bound to the SQL statement
...
...
tests/unit/extensions/sphinx/CommandTest.php
View file @
07ad008d
...
@@ -18,6 +18,58 @@ class CommandTest extends SphinxTestCase
...
@@ -18,6 +18,58 @@ class CommandTest extends SphinxTestCase
// Tests :
// Tests :
public
function
testConstruct
()
{
$db
=
$this
->
getConnection
(
false
);
// null
$command
=
$db
->
createCommand
();
$this
->
assertEquals
(
null
,
$command
->
sql
);
// string
$sql
=
'SELECT * FROM yii2_test_item_index'
;
$params
=
[
'name'
=>
'value'
];
$command
=
$db
->
createCommand
(
$sql
,
$params
);
$this
->
assertEquals
(
$sql
,
$command
->
sql
);
$this
->
assertEquals
(
$params
,
$command
->
params
);
}
public
function
testGetSetSql
()
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT * FROM yii2_test_item_index'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
$sql
,
$command
->
sql
);
$sql2
=
'SELECT * FROM yii2_test_item_index'
;
$command
->
sql
=
$sql2
;
$this
->
assertEquals
(
$sql2
,
$command
->
sql
);
}
public
function
testAutoQuoting
()
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{yii2_test_item_index}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
"SELECT `id`, `t`.`name` FROM `yii2_test_item_index` t"
,
$command
->
sql
);
}
public
function
testPrepareCancel
()
{
$db
=
$this
->
getConnection
(
false
);
$command
=
$db
->
createCommand
(
'SELECT * FROM yii2_test_item_index'
);
$this
->
assertEquals
(
null
,
$command
->
pdoStatement
);
$command
->
prepare
();
$this
->
assertNotEquals
(
null
,
$command
->
pdoStatement
);
$command
->
cancel
();
$this
->
assertEquals
(
null
,
$command
->
pdoStatement
);
}
public
function
testExecute
()
public
function
testExecute
()
{
{
$db
=
$this
->
getConnection
();
$db
=
$this
->
getConnection
();
...
...
tests/unit/extensions/sphinx/SchemaTest.php
0 → 100644
View file @
07ad008d
<?php
namespace
yiiunit\extensions\sphinx
;
use
yii\caching\FileCache
;
use
yii\sphinx\Schema
;
/**
* @group sphinx
*/
class
SchemaTest
extends
SphinxTestCase
{
public
function
testFindIndexNames
()
{
$schema
=
$this
->
getConnection
()
->
schema
;
$indexes
=
$schema
->
getIndexNames
();
$this
->
assertContains
(
'yii2_test_article_index'
,
$indexes
);
$this
->
assertContains
(
'yii2_test_item_index'
,
$indexes
);
$this
->
assertContains
(
'yii2_test_rt_index'
,
$indexes
);
}
public
function
testGetIndexSchemas
()
{
$schema
=
$this
->
getConnection
()
->
schema
;
$indexes
=
$schema
->
getTableSchemas
();
$this
->
assertEquals
(
count
(
$schema
->
getIndexNames
()),
count
(
$indexes
));
foreach
(
$indexes
as
$index
)
{
$this
->
assertInstanceOf
(
'yii\sphinx\IndexSchema'
,
$index
);
}
}
public
function
testGetNonExistingIndexSchema
()
{
$this
->
assertNull
(
$this
->
getConnection
()
->
schema
->
getIndexSchema
(
'non_existing_index'
));
}
public
function
testSchemaRefresh
()
{
$schema
=
$this
->
getConnection
()
->
schema
;
$schema
->
db
->
enableSchemaCache
=
true
;
$schema
->
db
->
schemaCache
=
new
FileCache
();
$noCacheIndex
=
$schema
->
getIndexSchema
(
'yii2_test_rt_index'
,
true
);
$cachedIndex
=
$schema
->
getIndexSchema
(
'yii2_test_rt_index'
,
true
);
$this
->
assertEquals
(
$noCacheIndex
,
$cachedIndex
);
}
public
function
testGetPDOType
()
{
$values
=
[
[
null
,
\PDO
::
PARAM_NULL
],
[
''
,
\PDO
::
PARAM_STR
],
[
'hello'
,
\PDO
::
PARAM_STR
],
[
0
,
\PDO
::
PARAM_INT
],
[
1
,
\PDO
::
PARAM_INT
],
[
1337
,
\PDO
::
PARAM_INT
],
[
true
,
\PDO
::
PARAM_BOOL
],
[
false
,
\PDO
::
PARAM_BOOL
],
[
$fp
=
fopen
(
__FILE__
,
'rb'
),
\PDO
::
PARAM_LOB
],
];
$schema
=
$this
->
getConnection
()
->
schema
;
foreach
(
$values
as
$value
)
{
$this
->
assertEquals
(
$value
[
1
],
$schema
->
getPdoType
(
$value
[
0
]));
}
fclose
(
$fp
);
}
}
\ No newline at end of file
tests/unit/extensions/sphinx/SphinxTestCase.php
View file @
07ad008d
...
@@ -68,7 +68,7 @@ class SphinxTestCase extends TestCase
...
@@ -68,7 +68,7 @@ class SphinxTestCase extends TestCase
/**
/**
* @param bool $reset whether to clean up the test database
* @param bool $reset whether to clean up the test database
* @param bool $open whether to open and populate test database
* @param bool $open whether to open and populate test database
* @return \yii\
db
\Connection
* @return \yii\
sphinx
\Connection
*/
*/
public
function
getConnection
(
$reset
=
true
,
$open
=
true
)
public
function
getConnection
(
$reset
=
true
,
$open
=
true
)
{
{
...
...
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