示例#1
0
 public function testDescendingSort()
 {
     $object1 = new stdClass();
     $object1->name = 'Name1';
     $object2 = new stdClass();
     $object2->name = 'Name2';
     $object3 = new stdClass();
     $object3->name = 'Name3';
     $object4 = new stdClass();
     $object4->name = 'Name4';
     $object5 = new stdClass();
     $object5->name = 'Name5';
     $results = [$object5, $object3, $object1, $object4, $object2];
     $sort = new Sort(['name'], new Order('DESC'));
     $results = Sorter::sort($results, $sort);
     $expected = [$object5, $object4, $object3, $object2, $object1];
     $this->assertEquals($expected, $results);
 }
 /**
  * Returns all instances of the type.
  *
  * @param FilterInterface|null $filter
  * @param Sort|null            $sort
  * @param Fields|null          $fields
  *
  * @return array
  */
 public function findBy(FilterInterface $filter = null, Sort $sort = null, Fields $fields = null) : array
 {
     $results = $this->data;
     if (null !== $filter && !$filter->isNull()) {
         $results = InMemoryFilter::filter($results, $filter);
     }
     if (null !== $sort && !$filter->isNull()) {
         $results = Sorter::sort($results, $sort);
     }
     return array_values($results);
 }