aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTomas Prochazka <[email protected]>2015-11-12 10:17:05 +0100
committerVictor Häggqvist <[email protected]>2015-11-17 17:09:02 +0100
commit452c4d0c6fd898245f7db68d00db64922d028be5 (patch)
treedfb4412c60d3eb386841196112c911009827d834 /test
parente9456021113f62e56ce33215ae00c4182acc4762 (diff)
Sort by magic properies of object.
Diffstat (limited to 'test')
-rw-r--r--test/Foo.php13
-rw-r--r--test/SortByFieldExtensionTest.php28
2 files changed, 41 insertions, 0 deletions
diff --git a/test/Foo.php b/test/Foo.php
index e6e688c..4b6148b 100644
--- a/test/Foo.php
+++ b/test/Foo.php
@@ -7,4 +7,17 @@
class Foo {
public $name;
+ private $attrs = array();
+
+ public function __isset($name) {
+ return isset($this->attrs[$name]);
+ }
+
+ public function __get($name) {
+ return $this->attrs[$name];
+ }
+
+ public function __set($name, $value) {
+ $this->attrs[$name] = $value;
+ }
}
diff --git a/test/SortByFieldExtensionTest.php b/test/SortByFieldExtensionTest.php
index 64bd11e..ff15a35 100644
--- a/test/SortByFieldExtensionTest.php
+++ b/test/SortByFieldExtensionTest.php
@@ -89,6 +89,34 @@ class SortByFieldExtensionTest extends PHPUnit_Framework_TestCase {
}
}
+ public function testSortObjectsMagicProperty() {
+ $base = array();
+ $ob1 = new Foo();
+ $ob1->magicName = "Redmine";
+ $base[]=$ob1;
+
+ $ob2 = new Foo();
+ $ob2->magicName = "GitLab";
+ $base[]=$ob2;
+
+ $ob3 = new Foo();
+ $ob3->magicName = "Jenkins";
+ $base[]=$ob3;
+
+ $ob4 = new Foo();
+ $ob4->magicName = "Jenkins";
+ $base[]=$ob4;
+
+ $fact = array('GitLab','Jenkins','Jenkins','Redmine');
+
+ $filter = new SortByFieldExtension();
+ $sorted = $filter->sortByFieldFilter($base,'magicName');
+
+ for ($i = 0; $i < count($fact); $i++){
+ $this->assertEquals($fact[$i], $sorted[$i]->magicName);
+ }
+ }
+
public function testNonArrayBase() {
$filter = new SortByFieldExtension();
$this->setExpectedException('InvalidArgumentException');