diff options
author | Victor Häggqvist <[email protected]> | 2016-01-27 00:58:22 +0100 |
---|---|---|
committer | Victor Häggqvist <[email protected]> | 2016-01-27 01:19:59 +0100 |
commit | 9590f61229a6e23c4f4ed91d34e3224804f69d40 (patch) | |
tree | 69947d6fe15362a066594169f7e7d7dba2904595 /test/SortByFieldExtensionTest.php | |
parent | 35b7217cab4ac9ebae1a757b06cfaaae40a8e670 (diff) |
add doctrine collection support
Diffstat (limited to '')
-rw-r--r-- | test/SortByFieldExtensionTest.php | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/test/SortByFieldExtensionTest.php b/test/SortByFieldExtensionTest.php index e97455d..7419f60 100644 --- a/test/SortByFieldExtensionTest.php +++ b/test/SortByFieldExtensionTest.php @@ -7,7 +7,7 @@ use Snilius\Twig\SortByFieldExtension; -require_once 'Foo.php'; +require_once __DIR__.'/../vendor/autoload.php'; class SortByFieldExtensionTest extends PHPUnit_Framework_TestCase { @@ -159,6 +159,33 @@ class SortByFieldExtensionTest extends PHPUnit_Framework_TestCase { } } + public function testSortDoctrineCollection() { + $collection = new \Doctrine\Common\Collections\ArrayCollection(); + $ob1 = new Foo(); + $ob1->name = "Redmine"; + $collection->add($ob1); + + $ob2 = new Foo(); + $ob2->name = "GitLab"; + $collection->add($ob2); + + $ob3 = new Foo(); + $ob3->name = "Jenkins"; + $collection->add($ob3); + + $ob4 = new Foo(); + $ob4->name = "Piwik"; + $collection->add($ob4); + $fact = array('GitLab', 'Jenkins', 'Piwik', 'Redmine'); + + $filter = new SortByFieldExtension(); + $sorted = $filter->sortByFieldFilter($collection, 'name'); + + for ($i = 0; $i < count($fact); $i++) { + $this->assertEquals($fact[$i], $sorted[$i]->name); + } + } + public function testNonArrayBase() { $filter = new SortByFieldExtension(); $this->setExpectedException('InvalidArgumentException'); @@ -168,7 +195,13 @@ class SortByFieldExtensionTest extends PHPUnit_Framework_TestCase { public function testInvalidField() { $filter = new SortByFieldExtension(); $this->setExpectedException('Exception'); - $filter->sortByFieldFilter(array(), null); + $filter->sortByFieldFilter(array(1,2,3), null); + } + + public function testEmptyArray() { + $filter = new SortByFieldExtension(); + $unTouchedArray = $filter->sortByFieldFilter(array()); + $this->assertEquals(array(), $unTouchedArray); } public function testUnknownField() { @@ -176,4 +209,5 @@ class SortByFieldExtensionTest extends PHPUnit_Framework_TestCase { $this->setExpectedException('Exception'); $filter->sortByFieldFilter(array(new Foo()), 'bar'); } + } |