Exemple #1
0
 public function testSort()
 {
     $items = range(1, 10);
     shuffle($items);
     $pagingSource = new CM_PagingSource_Array($items, null, function ($item) {
         return $item;
     });
     $this->assertSame(range(1, 10), $pagingSource->getItems());
     $pagingSource = new CM_PagingSource_Array($items, null, function ($item) {
         return $item;
     }, SORT_DESC);
     $this->assertSame(range(10, 1), $pagingSource->getItems());
     $pagingSource = new CM_PagingSource_Array($items, null, function ($item) {
         return $item;
     }, null, SORT_STRING);
     $this->assertSame(array(1, 10, 2, 3, 4, 5, 6, 7, 8, 9), $pagingSource->getItems());
     $pagingSource = new CM_PagingSource_Array($items, null, function ($item) {
         return $item;
     }, SORT_DESC, SORT_STRING);
     $this->assertSame(array(9, 8, 7, 6, 5, 4, 3, 2, 10, 1), $pagingSource->getItems());
 }
Exemple #2
0
 public function testGetStalenessChance()
 {
     /** @var CM_PagingSource_Abstract|\Mocka\AbstractClassTrait $internalSource */
     $internalSource = $this->mockObject('CM_PagingSource_Abstract');
     $getStalenessMock = $internalSource->mockMethod('getStalenessChance');
     $getStalenessMock->set(0.5);
     $arraySource = new CM_PagingSource_Array([1, 2, 3]);
     $this->assertSame(0, $arraySource->getStalenessChance());
     $arraySource = new CM_PagingSource_Array($internalSource);
     $this->assertSame(0.5, $arraySource->getStalenessChance());
     $this->assertSame(1, $getStalenessMock->getCallCount());
 }