예제 #1
0
 public function testMultiSort()
 {
     $this->assertEmpty(ArrayUtils::multiSort($this->_getArrayPreset('empty_array'), 'id'));
     $collection = $this->_getArrayPreset('2D_collection_5');
     $collectionNamed = $this->_getArrayPreset('2D_collection_5_named');
     $this->assertCount(count($collection), ArrayUtils::multiSort($collection, 'id'));
     $this->assertTrue(ArrayUtils::isCollection(ArrayUtils::multiSort($collectionNamed, 'id')));
     // make sure the same order
     $sortedCollection = ArrayUtils::multiSort($collection, 'id');
     $this->assertEquals($collection, $sortedCollection);
     // make sure proper order
     $sortedCollection = ArrayUtils::multiSort($collection, 'categoryId');
     $this->assertEquals('1-3-3-5-5', ArrayUtils::implodeByKey($sortedCollection, 'categoryId', '-'));
     $sortedCollection = ArrayUtils::multiSort($collection, 'categoryId', true);
     $this->assertEquals('5-5-3-3-1', ArrayUtils::implodeByKey($sortedCollection, 'categoryId', '-'));
     $sortedCollection = ArrayUtils::multiSort($collection, 'date');
     $this->assertEquals('5-2-1-9-6', ArrayUtils::implodeByKey($sortedCollection, 'id', '-'));
     $sortedCollection = ArrayUtils::multiSort($collection, 'date', true);
     $this->assertEquals('6-9-1-2-5', ArrayUtils::implodeByKey($sortedCollection, 'id', '-'));
     // make sure all keys are intact
     $sortedCollection = ArrayUtils::multiSort($collectionNamed, 'date', true);
     foreach ($sortedCollection as $item) {
         $this->assertArrayHasKey('id', $item);
         $this->assertArrayHasKey('name', $item);
         $this->assertArrayHasKey('categoryId', $item);
         $this->assertArrayHasKey('date', $item);
     }
 }
예제 #2
0
 /**
  * @dataProvider collectionProvider
  */
 public function testResetKeys($collection)
 {
     $this->assertTrue(ArrayUtils::isCollection(ObjectUtils::resetKeys($collection)));
     $collectionNamed = ObjectUtils::keyExplode($collection, 'name');
     $this->assertTrue(ArrayUtils::isCollection(ObjectUtils::resetKeys($collectionNamed)), 'Failed to assert that MD\\Foundation\\Utils\\Object::resetKeys() returns a collection.');
 }