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
c600572f
Commit
c600572f
authored
Feb 08, 2014
by
Florian Fackler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The missing Component.php tests
parent
009d47db
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
+55
-2
Component.php
framework/base/Component.php
+0
-2
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+55
-0
No files found.
framework/base/Component.php
View file @
c600572f
...
...
@@ -174,10 +174,8 @@ class Component extends Object
}
}
}
if
(
method_exists
(
$this
,
'get'
.
$name
))
{
throw
new
InvalidCallException
(
'Unsetting read-only property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
}
/**
* Calls the named method which is not a class method.
...
...
tests/unit/framework/base/ComponentTest.php
View file @
c600572f
...
...
@@ -303,6 +303,57 @@ class ComponentTest extends TestCase
$this
->
assertNull
(
$component
->
getBehavior
(
'a'
));
$this
->
assertNull
(
$component
->
getBehavior
(
'b'
));
}
public
function
testSetReadOnlyProperty
()
{
$this
->
setExpectedException
(
'\yii\base\InvalidCallException'
,
'Setting read-only property: yiiunit\framework\base\NewComponent::object'
);
$this
->
component
->
object
=
'z'
;
}
public
function
testSetPropertyOfBehavior
()
{
$this
->
assertNull
(
$this
->
component
->
getBehavior
(
'a'
));
$behavior
=
new
NewBehavior
;
$this
->
component
->
attachBehaviors
([
'a'
=>
$behavior
,
]);
$this
->
component
->
p
=
'Yii is cool.'
;
$this
->
assertSame
(
'Yii is cool.'
,
$this
->
component
->
getBehavior
(
'a'
)
->
p
);
}
public
function
testSettingBehaviorWithSetter
()
{
$behaviorName
=
'foo'
;
$this
->
assertNull
(
$this
->
component
->
getBehavior
(
$behaviorName
));
$p
=
'as '
.
$behaviorName
;
$this
->
component
->
$p
=
__NAMESPACE__
.
'\NewBehavior'
;
$this
->
assertSame
(
__NAMESPACE__
.
'\NewBehavior'
,
get_class
(
$this
->
component
->
getBehavior
(
$behaviorName
)));
}
public
function
testWriteOnlyProperty
()
{
$this
->
setExpectedException
(
'\yii\base\InvalidCallException'
,
'Getting write-only property: yiiunit\framework\base\NewComponent::writeOnly'
);
$this
->
component
->
writeOnly
;
}
public
function
testSuccessfulMethodCheck
()
{
$this
->
assertTrue
(
$this
->
component
->
hasMethod
(
'hasProperty'
));
}
public
function
testTurningOffNonExistingBehavior
()
{
$this
->
assertFalse
(
$this
->
component
->
hasEventHandlers
(
'foo'
));
$this
->
assertFalse
(
$this
->
component
->
off
(
'foo'
));
}
}
class
NewComponent
extends
Component
...
...
@@ -357,6 +408,10 @@ class NewComponent extends Component
{
$this
->
trigger
(
'click'
,
new
Event
);
}
public
function
setWriteOnly
()
{
}
}
class
NewBehavior
extends
Behavior
...
...
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