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
cc5618c0
Commit
cc5618c0
authored
Aug 26, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More tests for ArrayHelper and Inflector
parent
8f2ce5da
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
0 deletions
+149
-0
ArrayHelperTest.php
tests/unit/framework/helpers/ArrayHelperTest.php
+143
-0
InflectorTest.php
tests/unit/framework/helpers/InflectorTest.php
+6
-0
No files found.
tests/unit/framework/helpers/ArrayHelperTest.php
View file @
cc5618c0
...
...
@@ -24,6 +24,17 @@ class Post2 extends Object
}
}
class
Post3
extends
Object
{
public
$id
=
33
;
public
$subObject
;
public
function
init
()
{
$this
->
subObject
=
new
Post2
();
}
}
class
ArrayHelperTest
extends
TestCase
{
public
function
testToArray
()
...
...
@@ -57,6 +68,16 @@ class ArrayHelperTest extends TestCase
return
strlen
(
$post
->
content
);
}
))));
$object
=
new
Post3
();
$this
->
assertEquals
(
get_object_vars
(
$object
),
ArrayHelper
::
toArray
(
$object
,
array
(),
false
));
$this
->
assertEquals
(
array
(
'id'
=>
33
,
'subObject'
=>
array
(
'id'
=>
123
,
'content'
=>
'test'
,
),
),
ArrayHelper
::
toArray
(
$object
));
}
public
function
testRemove
()
...
...
@@ -66,6 +87,9 @@ class ArrayHelperTest extends TestCase
$this
->
assertEquals
(
$name
,
'b'
);
$this
->
assertEquals
(
$array
,
array
(
'age'
=>
3
));
$default
=
ArrayHelper
::
remove
(
$array
,
'nonExisting'
,
'defaultValue'
);
$this
->
assertEquals
(
'defaultValue'
,
$default
);
}
...
...
@@ -150,4 +174,123 @@ class ArrayHelperTest extends TestCase
$this
->
assertEquals
(
array
(
'name'
=>
'a'
,
'age'
=>
1
),
$array
[
1
]);
$this
->
assertEquals
(
array
(
'name'
=>
'b'
,
'age'
=>
3
),
$array
[
2
]);
}
public
function
testMerge
()
{
$a
=
array
(
'name'
=>
'Yii'
,
'version'
=>
'1.0'
,
'options'
=>
array
(
'namespace'
=>
false
,
'unittest'
=>
false
,
),
'features'
=>
array
(
'mvc'
,
),
);
$b
=
array
(
'version'
=>
'1.1'
,
'options'
=>
array
(
'unittest'
=>
true
,
),
'features'
=>
array
(
'gii'
,
),
);
$c
=
array
(
'version'
=>
'2.0'
,
'options'
=>
array
(
'namespace'
=>
true
,
),
'features'
=>
array
(
'debug'
,
),
);
$result
=
ArrayHelper
::
merge
(
$a
,
$b
,
$c
);
$expected
=
array
(
'name'
=>
'Yii'
,
'version'
=>
'2.0'
,
'options'
=>
array
(
'namespace'
=>
true
,
'unittest'
=>
true
,
),
'features'
=>
array
(
'mvc'
,
'gii'
,
'debug'
,
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
public
function
testIndex
()
{
$array
=
array
(
array
(
'id'
=>
'123'
,
'data'
=>
'abc'
),
array
(
'id'
=>
'345'
,
'data'
=>
'def'
),
);
$result
=
ArrayHelper
::
index
(
$array
,
'id'
);
$this
->
assertEquals
(
array
(
'123'
=>
array
(
'id'
=>
'123'
,
'data'
=>
'abc'
),
'345'
=>
array
(
'id'
=>
'345'
,
'data'
=>
'def'
),
),
$result
);
$result
=
ArrayHelper
::
index
(
$array
,
function
(
$element
)
{
return
$element
[
'data'
];
});
$this
->
assertEquals
(
array
(
'abc'
=>
array
(
'id'
=>
'123'
,
'data'
=>
'abc'
),
'def'
=>
array
(
'id'
=>
'345'
,
'data'
=>
'def'
),
),
$result
);
}
public
function
testGetColumn
()
{
$array
=
array
(
'a'
=>
array
(
'id'
=>
'123'
,
'data'
=>
'abc'
),
'b'
=>
array
(
'id'
=>
'345'
,
'data'
=>
'def'
),
);
$result
=
ArrayHelper
::
getColumn
(
$array
,
'id'
);
$this
->
assertEquals
(
array
(
'a'
=>
'123'
,
'b'
=>
'345'
),
$result
);
$result
=
ArrayHelper
::
getColumn
(
$array
,
'id'
,
false
);
$this
->
assertEquals
(
array
(
'123'
,
'345'
),
$result
);
$result
=
ArrayHelper
::
getColumn
(
$array
,
function
(
$element
)
{
return
$element
[
'data'
];
});
$this
->
assertEquals
(
array
(
'a'
=>
'abc'
,
'b'
=>
'def'
),
$result
);
$result
=
ArrayHelper
::
getColumn
(
$array
,
function
(
$element
)
{
return
$element
[
'data'
];
},
false
);
$this
->
assertEquals
(
array
(
'abc'
,
'def'
),
$result
);
}
public
function
testMap
()
{
$array
=
array
(
array
(
'id'
=>
'123'
,
'name'
=>
'aaa'
,
'class'
=>
'x'
),
array
(
'id'
=>
'124'
,
'name'
=>
'bbb'
,
'class'
=>
'x'
),
array
(
'id'
=>
'345'
,
'name'
=>
'ccc'
,
'class'
=>
'y'
),
);
$result
=
ArrayHelper
::
map
(
$array
,
'id'
,
'name'
);
$this
->
assertEquals
(
array
(
'123'
=>
'aaa'
,
'124'
=>
'bbb'
,
'345'
=>
'ccc'
,
),
$result
);
$result
=
ArrayHelper
::
map
(
$array
,
'id'
,
'name'
,
'class'
);
$this
->
assertEquals
(
array
(
'x'
=>
array
(
'123'
=>
'aaa'
,
'124'
=>
'bbb'
,
),
'y'
=>
array
(
'345'
=>
'ccc'
,
),
),
$result
);
}
}
tests/unit/framework/helpers/InflectorTest.php
View file @
cc5618c0
...
...
@@ -131,5 +131,11 @@ class InflectorTest extends TestCase
public
function
testOrdinalize
()
{
$this
->
assertEquals
(
'21st'
,
Inflector
::
ordinalize
(
'21'
));
$this
->
assertEquals
(
'22nd'
,
Inflector
::
ordinalize
(
'22'
));
$this
->
assertEquals
(
'23rd'
,
Inflector
::
ordinalize
(
'23'
));
$this
->
assertEquals
(
'24th'
,
Inflector
::
ordinalize
(
'24'
));
$this
->
assertEquals
(
'25th'
,
Inflector
::
ordinalize
(
'25'
));
$this
->
assertEquals
(
'111th'
,
Inflector
::
ordinalize
(
'111'
));
$this
->
assertEquals
(
'113th'
,
Inflector
::
ordinalize
(
'113'
));
}
}
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