From 452c4d0c6fd898245f7db68d00db64922d028be5 Mon Sep 17 00:00:00 2001 From: Tomas Prochazka Date: Thu, 12 Nov 2015 10:17:05 +0100 Subject: Sort by magic properies of object. --- test/SortByFieldExtensionTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/SortByFieldExtensionTest.php') 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'); -- cgit v1.2.3