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
7950b793
Commit
7950b793
authored
Feb 09, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2374 from mintao/master
Some missing base unit tests
parents
89fe3549
7b618734
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
3 deletions
+73
-3
Component.php
framework/base/Component.php
+1
-3
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+55
-0
ObjectTest.php
tests/unit/framework/base/ObjectTest.php
+17
-0
No files found.
framework/base/Component.php
View file @
7950b793
...
@@ -174,9 +174,7 @@ class Component extends Object
...
@@ -174,9 +174,7 @@ class Component extends Object
}
}
}
}
}
}
if
(
method_exists
(
$this
,
'get'
.
$name
))
{
throw
new
InvalidCallException
(
'Unsetting an unknown or read-only property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
throw
new
InvalidCallException
(
'Unsetting read-only property: '
.
get_class
(
$this
)
.
'.'
.
$name
);
}
}
}
/**
/**
...
...
tests/unit/framework/base/ComponentTest.php
View file @
7950b793
...
@@ -303,6 +303,57 @@ class ComponentTest extends TestCase
...
@@ -303,6 +303,57 @@ class ComponentTest extends TestCase
$this
->
assertNull
(
$component
->
getBehavior
(
'a'
));
$this
->
assertNull
(
$component
->
getBehavior
(
'a'
));
$this
->
assertNull
(
$component
->
getBehavior
(
'b'
));
$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
class
NewComponent
extends
Component
...
@@ -357,6 +408,10 @@ class NewComponent extends Component
...
@@ -357,6 +408,10 @@ class NewComponent extends Component
{
{
$this
->
trigger
(
'click'
,
new
Event
);
$this
->
trigger
(
'click'
,
new
Event
);
}
}
public
function
setWriteOnly
()
{
}
}
}
class
NewBehavior
extends
Behavior
class
NewBehavior
extends
Behavior
...
...
tests/unit/framework/base/ObjectTest.php
View file @
7950b793
...
@@ -139,6 +139,21 @@ class ObjectTest extends TestCase
...
@@ -139,6 +139,21 @@ class ObjectTest extends TestCase
$object
=
new
NewObject
([
'text'
=>
'test text'
]);
$object
=
new
NewObject
([
'text'
=>
'test text'
]);
$this
->
assertEquals
(
'test text'
,
$object
->
getText
());
$this
->
assertEquals
(
'test text'
,
$object
->
getText
());
}
}
public
function
testGetClassName
()
{
$object
=
$this
->
object
;
$this
->
assertSame
(
get_class
(
$object
),
$object
::
className
());
}
public
function
testReadingWriteOnlyProperty
()
{
$this
->
setExpectedException
(
'yii\base\InvalidCallException'
,
'Getting write-only property: yiiunit\framework\base\NewObject::writeOnly'
);
$this
->
object
->
writeOnly
;
}
}
}
...
@@ -179,4 +194,6 @@ class NewObject extends Object
...
@@ -179,4 +194,6 @@ class NewObject extends Object
{
{
return
$this
->
_items
;
return
$this
->
_items
;
}
}
public
function
setWriteOnly
(){}
}
}
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