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
88672ed1
Commit
88672ed1
authored
Jan 07, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
furnishing base classes.
parent
8e05e6e6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
195 additions
and
89 deletions
+195
-89
Component.php
framework/base/Component.php
+104
-35
Object.php
framework/base/Object.php
+18
-6
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+60
-41
DictionaryTest.php
tests/unit/framework/base/DictionaryTest.php
+5
-2
VectorTest.php
tests/unit/framework/base/VectorTest.php
+8
-5
No files found.
framework/base/Component.php
View file @
88672ed1
This diff is collapsed.
Click to expand it.
framework/base/Object.php
View file @
88672ed1
...
...
@@ -160,8 +160,12 @@ class Object
/**
* Returns a value indicating whether a property is defined.
* A property is defined if there is a getter or setter method
* defined in the class. Note that property names are case-insensitive.
* A property is defined if:
*
* - the class has a getter or setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @return boolean whether the property is defined
...
...
@@ -175,8 +179,12 @@ class Object
/**
* Returns a value indicating whether a property can be read.
* A property can be read if the class has a getter method
* for the property name. Note that property name is case-insensitive.
* A property is readable if:
*
* - the class has a getter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @return boolean whether the property can be read
...
...
@@ -189,8 +197,12 @@ class Object
/**
* Returns a value indicating whether a property can be set.
* A property can be written if the class has a setter method
* for the property name. Note that property name is case-insensitive.
* A property is writable if:
*
* - the class has a setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @return boolean whether the property can be written
...
...
tests/unit/framework/base/ComponentTest.php
View file @
88672ed1
...
...
@@ -32,9 +32,12 @@ class ComponentTest extends \yiiunit\TestCase
public
function
testHasProperty
()
{
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'Text'
),
"Component hasn't property Text"
);
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'text'
),
"Component hasn't property text"
);
$this
->
assertFalse
(
$this
->
component
->
hasProperty
(
'Caption'
),
"Component as property Caption"
);
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
component
->
hasProperty
(
'Caption'
));
$this
->
assertTrue
(
$this
->
component
->
hasProperty
(
'content'
));
$this
->
assertFalse
(
$this
->
component
->
hasProperty
(
'content'
,
false
));
$this
->
assertFalse
(
$this
->
component
->
hasProperty
(
'Content'
));
}
public
function
testCanGetProperty
()
...
...
@@ -42,19 +45,26 @@ class ComponentTest extends \yiiunit\TestCase
$this
->
assertTrue
(
$this
->
component
->
canGetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
component
->
canGetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
component
->
canGetProperty
(
'Caption'
));
$this
->
assertTrue
(
$this
->
component
->
canGetProperty
(
'content'
));
$this
->
assertFalse
(
$this
->
component
->
canGetProperty
(
'content'
,
false
));
$this
->
assertFalse
(
$this
->
component
->
canGetProperty
(
'Content'
));
}
public
function
testCanSetProperty
()
{
$this
->
assertTrue
(
$this
->
component
->
canSetProperty
(
'Text'
));
$this
->
assertTrue
(
$this
->
component
->
canSetProperty
(
'text'
));
$this
->
assertFalse
(
$this
->
component
->
canSetProperty
(
'Object'
));
$this
->
assertFalse
(
$this
->
component
->
canSetProperty
(
'Caption'
));
$this
->
assertTrue
(
$this
->
component
->
canSetProperty
(
'content'
));
$this
->
assertFalse
(
$this
->
component
->
canSetProperty
(
'content'
,
false
));
$this
->
assertFalse
(
$this
->
component
->
canSetProperty
(
'Content'
));
}
public
function
testGetProperty
()
{
$this
->
assertTrue
(
'default'
===
$this
->
component
->
Text
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadProperty
Exception'
);
$value2
=
$this
->
component
->
Caption
;
}
...
...
@@ -62,24 +72,30 @@ class ComponentTest extends \yiiunit\TestCase
{
$value
=
'new value'
;
$this
->
component
->
Text
=
$value
;
$text
=
$this
->
component
->
Text
;
$this
->
assertTrue
(
$value
===
$this
->
component
->
Text
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
assertEquals
(
$value
,
$this
->
component
->
Text
);
$this
->
setExpectedException
(
'yii\base\BadPropertyException'
);
$this
->
component
->
NewMember
=
$value
;
}
public
function
testIsset
()
{
$this
->
assertTrue
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
!
empty
(
$this
->
component
->
Text
));
unset
(
$this
->
component
->
Text
);
$this
->
assertFalse
(
isset
(
$this
->
component
->
Text
));
$this
->
assertFalse
(
!
empty
(
$this
->
component
->
Text
));
$this
->
assertFalse
(
empty
(
$this
->
component
->
Text
));
$this
->
component
->
Text
=
''
;
$this
->
assertTrue
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
component
->
Text
));
$this
->
component
->
Text
=
null
;
$this
->
assertFalse
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
component
->
Text
));
}
public
function
testUnset
()
{
unset
(
$this
->
component
->
Text
);
$this
->
assertFalse
(
isset
(
$this
->
component
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
component
->
Text
));
}
public
function
testOn
()
...
...
@@ -147,38 +163,24 @@ class ComponentTest extends \yiiunit\TestCase
$this
->
assertFalse
(
$this
->
component
->
eventHandled
);
}
public
function
test
De
tachBehavior
()
public
function
test
At
tachBehavior
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$this
->
assertSame
(
$behavior
,
$component
->
detachBehavior
(
'a'
));
}
public
function
testDetachingBehaviors
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$component
->
detachBehaviors
();
$this
->
setExpectedException
(
'yii\base\Exception'
);
$component
->
test
();
}
$this
->
assertFalse
(
$component
->
hasProperty
(
'p'
));
$this
->
assertFalse
(
$component
->
behaviorCalled
);
$this
->
assertNull
(
$component
->
getBehavior
(
'a'
));
public
function
testGetBehavior
()
{
$component
=
new
NewComponent
;
$behavior
=
new
NewBehavior
;
$component
->
attachBehavior
(
'a'
,
$behavior
);
$this
->
assertSame
(
$behavior
,
$component
->
getBehavior
(
'a'
));
}
$this
->
assertTrue
(
$component
->
hasProperty
(
'p'
));
$component
->
test
();
$this
->
assertTrue
(
$component
->
behaviorCalled
);
public
function
testCreate
()
{
$component
=
NewComponent2
::
newInstance
(
array
(
'a'
=>
3
),
1
,
2
);
$this
->
assertEquals
(
1
,
$component
->
b
);
$this
->
assertEquals
(
2
,
$component
->
c
);
$this
->
assertEquals
(
3
,
$component
->
a
);
$this
->
assertSame
(
$behavior
,
$component
->
detachBehavior
(
'a'
));
$this
->
assertFalse
(
$component
->
hasProperty
(
'p'
));
$this
->
setExpectedException
(
'yii\base\BadMethodException'
);
$component
->
test
();
}
}
...
...
@@ -186,9 +188,8 @@ class NewComponent extends \yii\base\Component
{
private
$_object
=
null
;
private
$_text
=
'default'
;
public
$eventHandled
=
false
;
public
$event
;
public
$behaviorCalled
=
false
;
private
$_items
=
array
();
public
$content
;
public
function
getText
()
{
...
...
@@ -203,12 +204,28 @@ class NewComponent extends \yii\base\Component
public
function
getObject
()
{
if
(
!
$this
->
_object
)
{
$this
->
_object
=
new
NewComponent
;
$this
->
_object
=
new
self
;
$this
->
_object
->
_text
=
'object text'
;
}
return
$this
->
_object
;
}
public
function
getExecute
()
{
return
function
(
$param
)
{
return
$param
*
2
;
};
}
public
function
getItems
()
{
return
$this
->
_items
;
}
public
$eventHandled
=
false
;
public
$event
;
public
$behaviorCalled
=
false
;
public
function
myEventHandler
(
$event
)
{
$this
->
eventHandled
=
true
;
...
...
@@ -223,6 +240,8 @@ class NewComponent extends \yii\base\Component
class
NewBehavior
extends
\yii\base\Behavior
{
public
$p
;
public
function
test
()
{
$this
->
owner
->
behaviorCalled
=
true
;
...
...
tests/unit/framework/base/DictionaryTest.php
View file @
88672ed1
...
...
@@ -11,6 +11,9 @@ class MapItem
class
DictionaryTest
extends
\yiiunit\TestCase
{
/**
* @var \yii\base\Dictionary
*/
protected
$dictionary
;
protected
$item1
,
$item2
,
$item3
;
...
...
@@ -92,7 +95,7 @@ class DictionaryTest extends \yiiunit\TestCase
$this
->
assertEquals
(
$this
->
item3
,
$this
->
dictionary
[
'key3'
]);
$this
->
assertEquals
(
$this
->
item1
,
$this
->
dictionary
[
'key4'
]);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
dictionary
->
copyFrom
(
$this
);
}
...
...
@@ -111,7 +114,7 @@ class DictionaryTest extends \yiiunit\TestCase
$this
->
assertEquals
(
3
,
$this
->
dictionary
->
getCount
());
$this
->
assertEquals
(
$this
->
item1
,
$this
->
dictionary
[
'key2'
]);
$this
->
assertEquals
(
$this
->
item3
,
$this
->
dictionary
[
'key3'
]);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
dictionary
->
mergeWith
(
$this
,
false
);
}
...
...
tests/unit/framework/base/VectorTest.php
View file @
88672ed1
...
...
@@ -11,6 +11,9 @@ class ListItem
class
VectorTest
extends
\yiiunit\TestCase
{
/**
* @var Vector
*/
protected
$vector
;
protected
$item1
,
$item2
,
$item3
;
...
...
@@ -62,7 +65,7 @@ class VectorTest extends \yiiunit\TestCase
$this
->
assertEquals
(
2
,
$this
->
vector
->
indexOf
(
$this
->
item2
));
$this
->
assertEquals
(
0
,
$this
->
vector
->
indexOf
(
$this
->
item3
));
$this
->
assertEquals
(
1
,
$this
->
vector
->
indexOf
(
$this
->
item1
));
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
vector
->
insertAt
(
4
,
$this
->
item3
);
}
...
...
@@ -84,7 +87,7 @@ class VectorTest extends \yiiunit\TestCase
$this
->
assertEquals
(
-
1
,
$this
->
vector
->
indexOf
(
$this
->
item2
));
$this
->
assertEquals
(
1
,
$this
->
vector
->
indexOf
(
$this
->
item3
));
$this
->
assertEquals
(
0
,
$this
->
vector
->
indexOf
(
$this
->
item1
));
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
vector
->
removeAt
(
2
);
}
...
...
@@ -115,7 +118,7 @@ class VectorTest extends \yiiunit\TestCase
$array
=
array
(
$this
->
item3
,
$this
->
item1
);
$this
->
vector
->
copyFrom
(
$array
);
$this
->
assertTrue
(
count
(
$array
)
==
2
&&
$this
->
vector
[
0
]
===
$this
->
item3
&&
$this
->
vector
[
1
]
===
$this
->
item1
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
vector
->
copyFrom
(
$this
);
}
...
...
@@ -124,7 +127,7 @@ class VectorTest extends \yiiunit\TestCase
$array
=
array
(
$this
->
item3
,
$this
->
item1
);
$this
->
vector
->
mergeWith
(
$array
);
$this
->
assertTrue
(
$this
->
vector
->
getCount
()
==
4
&&
$this
->
vector
[
0
]
===
$this
->
item1
&&
$this
->
vector
[
3
]
===
$this
->
item1
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$this
->
vector
->
mergeWith
(
$this
);
}
...
...
@@ -138,7 +141,7 @@ class VectorTest extends \yiiunit\TestCase
{
$this
->
assertTrue
(
$this
->
vector
[
0
]
===
$this
->
item1
);
$this
->
assertTrue
(
$this
->
vector
[
1
]
===
$this
->
item2
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
setExpectedException
(
'yii\base\
BadParam
Exception'
);
$a
=
$this
->
vector
[
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