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
d991f42c
Commit
d991f42c
authored
Dec 03, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use namespace in unit tests.
Fixed BehaviorTest.php
parent
0d817e67
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
149 additions
and
30 deletions
+149
-30
Component.php
framework/base/Component.php
+2
-1
TestCase.php
tests/unit/TestCase.php
+7
-4
bootstrap.php
tests/unit/bootstrap.php
+4
-0
BehaviorTest.php
tests/unit/framework/base/BehaviorTest.php
+7
-7
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+5
-10
DictionaryTest.php
tests/unit/framework/base/DictionaryTest.php
+5
-3
ObjectTest.php
tests/unit/framework/base/ObjectTest.php
+109
-1
VectorTest.php
tests/unit/framework/base/VectorTest.php
+3
-1
CommandTest.php
tests/unit/framework/db/dao/CommandTest.php
+3
-1
ConnectionTest.php
tests/unit/framework/db/dao/ConnectionTest.php
+4
-2
No files found.
framework/base/Component.php
View file @
d991f42c
...
...
@@ -209,7 +209,8 @@ class Component extends Object
if
(
method_exists
(
$this
,
$setter
))
{
// write property
return
$this
->
$setter
(
null
);
}
elseif
(
method_exists
(
$this
,
$name
)
&&
strncasecmp
(
$name
,
'on'
,
2
)
===
0
)
{
// event
return
unset
(
$this
->
_e
[
strtolower
(
$name
)]);
unset
(
$this
->
_e
[
strtolower
(
$name
)]);
return
;
}
elseif
(
isset
(
$this
->
_b
[
$name
]))
{
// behavior
return
$this
->
detachBehavior
(
$name
);
}
elseif
(
is_array
(
$this
->
_b
))
{
// behavior property
...
...
tests/unit/TestCase.php
View file @
d991f42c
<?php
namespace
yiiunit
;
class
TestCase
extends
\yii\test\TestCase
{
public
$params
;
public
static
$params
;
function
getParam
(
$name
)
{
if
(
$this
->
params
===
null
)
{
$this
->
params
=
require
(
__DIR__
.
'/data/config.php'
);
if
(
self
::
$
params
===
null
)
{
self
::
$
params
=
require
(
__DIR__
.
'/data/config.php'
);
}
return
isset
(
$this
->
params
[
$name
])
?
$this
->
params
[
$name
]
:
null
;
return
isset
(
self
::
$params
[
$name
])
?
self
::
$
params
[
$name
]
:
null
;
}
}
\ No newline at end of file
tests/unit/bootstrap.php
View file @
d991f42c
...
...
@@ -7,4 +7,7 @@ $_SERVER['SCRIPT_NAME'] = '/' . __DIR__;
$_SERVER
[
'SCRIPT_FILENAME'
]
=
__FILE__
;
require_once
(
__DIR__
.
'/../../framework/yii.php'
);
Yii
::
setAlias
(
'@yiiunit'
,
__DIR__
);
require_once
(
__DIR__
.
'/TestCase.php'
);
\ No newline at end of file
tests/unit/framework/base/BehaviorTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\base
;
class
BarClass
extends
\yii\base\Component
{
...
...
@@ -14,19 +17,16 @@ class BarBehavior extends \yii\base\Behavior
}
}
/**
* BehaviorTest
*/
class
BehaviorTest
extends
\yii\test\TestCase
class
BehaviorTest
extends
\yiiunit\TestCase
{
public
function
testAttachAndAccessing
()
{
$bar
=
BarClass
::
create
();
$behavior
=
new
BarBehavior
();
$bar
->
attachBehavior
(
'bar'
,
$b
a
r
);
$bar
->
attachBehavior
(
'bar'
,
$b
ehavio
r
);
$this
->
assertEquals
(
'behavior property'
,
$bar
->
behaviorProperty
);
$this
->
assertEquals
(
'behavior method'
,
$bar
->
behaviorMethod
);
$this
->
assertEquals
(
'behavior method'
,
$bar
->
behaviorMethod
()
);
$this
->
assertEquals
(
'behavior property'
,
$bar
->
bar
->
behaviorProperty
);
$this
->
assertEquals
(
'behavior method'
,
$bar
->
bar
->
behaviorMethod
);
$this
->
assertEquals
(
'behavior method'
,
$bar
->
bar
->
behaviorMethod
()
);
}
}
tests/unit/framework/base/ComponentTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\base
;
function
globalEventHandler
(
$event
)
{
$event
->
sender
->
eventHandled
=
true
;
...
...
@@ -11,7 +13,7 @@ function globalEventHandler2($event)
$event
->
handled
=
true
;
}
class
ComponentTest
extends
TestCase
class
ComponentTest
extends
\yiiunit\
TestCase
{
protected
$component
;
...
...
@@ -142,7 +144,7 @@ class ComponentTest extends TestCase
{
$component
=
new
NewComponent
;
$this
->
assertEquals
(
$component
->
onMyEvent
->
getCount
(),
0
);
$component
->
onMyEvent
=
'globalEventHandler'
;
$component
->
onMyEvent
=
'
yiiunit\framework\base\
globalEventHandler'
;
$component
->
onMyEvent
=
array
(
$this
->
component
,
'myEventHandler'
);
$this
->
assertEquals
(
$component
->
onMyEvent
->
getCount
(),
2
);
$this
->
assertFalse
(
$component
->
eventHandled
);
...
...
@@ -155,7 +157,7 @@ class ComponentTest extends TestCase
public
function
testStopEvent
()
{
$component
=
new
NewComponent
;
$component
->
onMyEvent
=
'globalEventHandler2'
;
$component
->
onMyEvent
=
'
yiiunit\framework\base\
globalEventHandler2'
;
$component
->
onMyEvent
=
array
(
$this
->
component
,
'myEventHandler'
);
$component
->
onMyEvent
();
$this
->
assertTrue
(
$component
->
eventHandled
);
...
...
@@ -202,13 +204,6 @@ class ComponentTest extends TestCase
$this
->
assertSame
(
$behavior
,
$component
->
asa
(
'a'
));
}
public
function
testEvaluateExpression
()
{
$component
=
new
NewComponent
;
$this
->
assertEquals
(
'Hello world'
,
$component
->
evaluateExpression
(
'"Hello $who"'
,
array
(
'who'
=>
'world'
)));
$this
->
assertEquals
(
'Hello world'
,
$component
->
evaluateExpression
(
array
(
$component
,
'exprEvaluator'
),
array
(
'who'
=>
'world'
)));
}
public
function
testCreate
()
{
$component
=
NewComponent2
::
create
(
1
,
2
,
array
(
'a'
=>
3
));
...
...
tests/unit/framework/base/DictionaryTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\base
;
use
yii\base\Dictionary
;
class
MapItem
...
...
@@ -7,7 +9,7 @@ class MapItem
public
$data
=
'data'
;
}
class
DictionaryTest
extends
TestCase
class
DictionaryTest
extends
\yiiunit\
TestCase
{
protected
$dictionary
;
protected
$item1
,
$item2
,
$item3
;
...
...
@@ -115,10 +117,10 @@ class DictionaryTest extends TestCase
public
function
testRecursiveMergeWithTraversable
(){
$dictionary
=
new
Dictionary
();
$obj
=
new
ArrayObject
(
array
(
$obj
=
new
\
ArrayObject
(
array
(
'k1'
=>
$this
->
item1
,
'k2'
=>
$this
->
item2
,
'k3'
=>
new
ArrayObject
(
array
(
'k3'
=>
new
\
ArrayObject
(
array
(
'k4'
=>
$this
->
item3
,
))
));
...
...
tests/unit/framework/base/ObjectTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\base
;
class
Foo
extends
\yii\base\Object
{
public
$prop
;
...
...
@@ -7,8 +10,20 @@ class Foo extends \yii\base\Object
/**
* ObjectTest
*/
class
ObjectTest
extends
\yii
\tes
t\TestCase
class
ObjectTest
extends
\yii
uni
t\TestCase
{
protected
$object
;
public
function
setUp
()
{
$this
->
object
=
new
NewObject
;
}
public
function
tearDown
()
{
$this
->
object
=
null
;
}
public
function
testCreate
()
{
$foo
=
Foo
::
create
(
array
(
...
...
@@ -19,4 +34,96 @@ class ObjectTest extends \yii\test\TestCase
$this
->
assertEquals
(
'test'
,
$foo
->
prop
[
'test'
]);
}
public
function
testHasProperty
()
{
$this
->
assertTrue
(
$this
->
object
->
hasProperty
(
'Text'
),
"Component hasn't property Text"
);
$this
->
assertTrue
(
$this
->
object
->
hasProperty
(
'text'
),
"Component hasn't property text"
);
$this
->
assertFalse
(
$this
->
object
->
hasProperty
(
'Caption'
),
"Component as property Caption"
);
}
public
function
testCanGetProperty
()
{
$this
->
assertTrue
(
$this
->
object
->
canGetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
object
->
canGetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
object
->
canGetProperty
(
'Caption'
));
}
public
function
testCanSetProperty
()
{
$this
->
assertTrue
(
$this
->
object
->
canSetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
object
->
canSetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
object
->
canSetProperty
(
'Caption'
));
}
public
function
testGetProperty
()
{
$this
->
assertTrue
(
'default'
===
$this
->
object
->
Text
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$value2
=
$this
->
object
->
Caption
;
}
public
function
testSetProperty
()
{
$value
=
'new value'
;
$this
->
object
->
Text
=
$value
;
$text
=
$this
->
object
->
Text
;
$this
->
assertTrue
(
$value
===
$this
->
object
->
Text
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
object
->
NewMember
=
$value
;
}
public
function
testIsset
()
{
$this
->
assertTrue
(
isset
(
$this
->
object
->
Text
));
$this
->
assertTrue
(
!
empty
(
$this
->
object
->
Text
));
unset
(
$this
->
object
->
Text
);
$this
->
assertFalse
(
isset
(
$this
->
object
->
Text
));
$this
->
assertFalse
(
!
empty
(
$this
->
object
->
Text
));
$this
->
object
->
Text
=
''
;
$this
->
assertTrue
(
isset
(
$this
->
object
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
object
->
Text
));
}
public
function
testEvaluateExpression
()
{
$object
=
new
NewObject
;
$this
->
assertEquals
(
'Hello world'
,
$object
->
evaluateExpression
(
'"Hello $who"'
,
array
(
'who'
=>
'world'
)));
$this
->
assertEquals
(
'Hello world'
,
$object
->
evaluateExpression
(
array
(
$object
,
'exprEvaluator'
),
array
(
'who'
=>
'world'
)));
}
}
class
NewObject
extends
\yii\base\Component
{
private
$_object
=
null
;
private
$_text
=
'default'
;
public
function
getText
()
{
return
$this
->
_text
;
}
public
function
setText
(
$value
)
{
$this
->
_text
=
$value
;
}
public
function
getObject
()
{
if
(
!
$this
->
_object
)
{
$this
->
_object
=
new
self
;
$this
->
_object
->
_text
=
'object text'
;
}
return
$this
->
_object
;
}
public
function
exprEvaluator
(
$p1
,
$comp
)
{
return
"Hello
$p1
"
;
}
}
\ No newline at end of file
tests/unit/framework/base/VectorTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\base
;
use
yii\base\Vector
;
class
ListItem
...
...
@@ -7,7 +9,7 @@ class ListItem
public
$data
=
'data'
;
}
class
VectorTest
extends
TestCase
class
VectorTest
extends
\yiiunit\
TestCase
{
protected
$vector
;
protected
$item1
,
$item2
,
$item3
;
...
...
tests/unit/framework/db/dao/CommandTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\db\dao
;
use
yii\db\dao\Connection
;
use
yii\db\dao\Command
;
use
yii\db\dao\Query
;
class
CommandTest
extends
TestCase
class
CommandTest
extends
\yiiunit\
TestCase
{
private
$connection
;
...
...
tests/unit/framework/db/dao/ConnectionTest.php
View file @
d991f42c
<?php
namespace
yiiunit\framework\db\dao
;
use
yii\db\dao\Connection
;
class
ConnectionTest
extends
TestCase
class
ConnectionTest
extends
\yiiunit\
TestCase
{
function
setUp
()
{
...
...
@@ -29,7 +31,7 @@ class ConnectionTest extends TestCase
$connection
->
open
();
$this
->
assertTrue
(
$connection
->
active
);
$this
->
assertTrue
(
$connection
->
pdo
instanceof
PDO
);
$this
->
assertTrue
(
$connection
->
pdo
instanceof
\
PDO
);
$connection
->
close
();
$this
->
assertFalse
(
$connection
->
active
);
...
...
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