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
71063374
Commit
71063374
authored
Jul 20, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
cd346119
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
12 deletions
+60
-12
Component.php
framework/base/Component.php
+7
-7
TestCase.php
framework/test/TestCase.php
+1
-1
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+52
-4
No files found.
framework/base/Component.php
View file @
71063374
...
...
@@ -135,7 +135,7 @@ class Component
elseif
(
method_exists
(
$this
,
$name
)
&&
strncasecmp
(
$name
,
'on'
,
2
)
===
0
)
{
// event, e.g. onClick()
$name
=
strtolower
(
$name
);
if
(
!
isset
(
$this
->
_e
[
$name
]))
{
$this
->
_e
[
$name
]
=
new
\yii\collections\
Vector
;
$this
->
_e
[
$name
]
=
new
Vector
;
}
return
$this
->
_e
[
$name
];
}
...
...
@@ -149,7 +149,7 @@ class Component
}
}
}
throw
new
Exception
(
'Getting unknown property: '
.
get_class
(
$this
)
.
'.'
$name
);
throw
new
Exception
(
'Getting unknown property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
/**
...
...
@@ -176,7 +176,7 @@ class Component
elseif
(
method_exists
(
$this
,
$name
)
&&
strncasecmp
(
$name
,
'on'
,
2
)
===
0
)
{
$name
=
strtolower
(
$name
);
if
(
!
isset
(
$this
->
_e
[
$name
]))
{
$this
->
_e
[
$name
]
=
new
\yii\collections\
Vector
;
$this
->
_e
[
$name
]
=
new
Vector
;
}
return
$this
->
_e
[
$name
]
->
add
(
$value
);
}
...
...
@@ -188,10 +188,10 @@ class Component
}
}
if
(
method_exists
(
$this
,
'get'
.
$name
))
{
throw
new
Exception
(
'Setting read-only property: '
.
get_class
(
$this
)
.
'.'
$name
);
throw
new
Exception
(
'Setting read-only property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
else
{
throw
new
Exception
(
'Setting unknown property: '
.
get_class
(
$this
)
.
'.'
$name
);
throw
new
Exception
(
'Setting unknown property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
}
...
...
@@ -269,7 +269,7 @@ class Component
}
}
elseif
(
method_exists
(
$this
,
'get'
.
$name
))
{
throw
new
Exception
(
'Unsetting read-only property: '
.
get_class
(
$this
)
.
'.'
$name
);
throw
new
Exception
(
'Unsetting read-only property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
}
...
...
@@ -304,7 +304,7 @@ class Component
}
}
}
throw
new
Exception
(
'Unknown method: '
.
get_class
(
$this
)
.
'::'
$name
.
'()'
);
throw
new
Exception
(
'Unknown method: '
.
get_class
(
$this
)
.
"::
$name
()"
);
}
/**
...
...
framework/test/TestCase.php
View file @
71063374
...
...
@@ -7,7 +7,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\test
\TestCase
;
namespace
yii\test
;
require_once
(
'PHPUnit/Runner/Version.php'
);
require_once
(
'PHPUnit/Autoload.php'
);
...
...
tests/unit/framework/base/ComponentTest.php
View file @
71063374
<?php
require_once
dirname
(
__FILE__
)
.
'/NewComponent.php'
;
require_once
dirname
(
__FILE__
)
.
'/NewBehavior.php'
;
function
globalEventHandler
(
$event
)
{
...
...
@@ -13,7 +11,7 @@ function globalEventHandler2($event)
$event
->
handled
=
true
;
}
class
ComponentTest
extends
C
TestCase
class
ComponentTest
extends
\yii\test\
TestCase
{
protected
$component
;
...
...
@@ -133,7 +131,7 @@ class ComponentTest extends CTestCase
{
$this
->
component
->
attachEventHandler
(
'OnMyEvent'
,
array
(
$this
->
component
,
'myEventHandler'
));
$this
->
assertFalse
(
$this
->
component
->
eventHandled
);
$this
->
component
->
raiseEvent
(
'OnMyEvent'
,
new
C
Event
(
$this
));
$this
->
component
->
raiseEvent
(
'OnMyEvent'
,
new
\yii\base\
Event
(
$this
));
$this
->
assertTrue
(
$this
->
component
->
eventHandled
);
//$this->setExpectedException('CException');
...
...
@@ -221,3 +219,53 @@ class ComponentTest extends CTestCase
$this
->
assertEquals
(
'Hello world'
,
$component
->
evaluateExpression
(
array
(
$component
,
'exprEvaluator'
),
array
(
'who'
=>
'world'
)));
}
}
class
NewComponent
extends
\yii\base\Component
{
private
$_object
=
null
;
private
$_text
=
'default'
;
public
$eventHandled
=
false
;
public
$behaviorCalled
=
false
;
public
function
getText
()
{
return
$this
->
_text
;
}
public
function
setText
(
$value
)
{
$this
->
_text
=
$value
;
}
public
function
getObject
()
{
if
(
!
$this
->
_object
)
{
$this
->
_object
=
new
NewComponent
;
$this
->
_object
->
_text
=
'object text'
;
}
return
$this
->
_object
;
}
public
function
onMyEvent
()
{
$this
->
raiseEvent
(
'OnMyEvent'
,
new
\yii\base\Event
(
$this
));
}
public
function
myEventHandler
(
$event
)
{
$this
->
eventHandled
=
true
;
}
public
function
exprEvaluator
(
$p1
,
$comp
)
{
return
"Hello
$p1
"
;
}
}
class
NewBehavior
extends
\yii\base\Behavior
{
public
function
test
()
{
$this
->
owner
->
behaviorCalled
=
true
;
return
2
;
}
}
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