/**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $this->setExpectedException('InvalidArgumentException', 'Depth parameter must be an integer');
     // invoke logic & test
     SimpleArrayLibrary::countMaxDepth('a', 'z');
 }
 /**
  * TearDown remove dummy data from one or more collections
  *
  * @param array $records
  *
  * @throws \UnexpectedValueException
  * @return void
  */
 public function tearDown(array $records = [])
 {
     if (empty($records)) {
         if (is_array($this->data)) {
             foreach ($this->data as $collection => $rows) {
                 $records[$collection] = array_keys($rows);
             }
         }
     } elseif (SimpleArrayLibrary::countMaxDepth($records) == 1) {
         $this->validateCollections($records);
         $temp = [];
         foreach ($records as $collection) {
             $temp[$collection] = array_keys($this->data[$collection]);
         }
         $records = $temp;
     } else {
         foreach ($records as $collection => $ids) {
             $this->validateIds($collection, $ids);
         }
     }
     foreach ($records as $collection => $ids) {
         foreach ($ids as $id) {
             $this->delete($collection, $id);
         }
     }
 }
 /**
  * Edits $data array
  *
  * @param array|string $value
  * @param string       $collection
  * @param string       $id
  * @param string       $field
  *
  * @return void
  */
 public function saveData($value, $collection = '', $id = '', $field = '')
 {
     if (!empty($collection)) {
         if (!empty($id)) {
             if (!empty($field)) {
                 if (!isset($this->data[$collection])) {
                     throw new UnexpectedValueException('Non existing collection');
                 }
                 if (!isset($this->data[$collection][$id])) {
                     throw new UnexpectedValueException('Non existing row');
                 }
                 $this->data[$collection][$id][$field] = $value;
             } else {
                 if (!is_array($value)) {
                     throw new UnexpectedValueException('Row should be an array of fields');
                 }
                 $data[$collection] = isset($data[$collection]) ? $data[$collection] : [];
                 $this->data[$collection][$id] = $value;
             }
         } else {
             if (SimpleArrayLibrary::countMaxDepth($value) <= 1) {
                 throw new UnexpectedValueException('Collection has to be array of rows which are all arrays of fields');
             }
             $this->data[$collection] = $value;
         }
     } else {
         if (SimpleArrayLibrary::countMaxDepth($value) <= 2) {
             throw new UnexpectedValueException('Data has to be an array of collections which are all arrays of rows which are all arrays of fields');
         }
         $this->data = $value;
     }
 }
 /**
  * @param array $data
  *
  * @return void
  * @dataProvider getData
  */
 public function test_function(array $data)
 {
     // invoke logic & test
     $this->assertEquals($data['expResult'], SimpleArrayLibrary::countMaxDepth($data['array'], $data['depth']));
 }
 /**
  * @param array $repacked
  *
  * @return array
  */
 protected function compactDependencies(array $repacked)
 {
     if (SimpleArrayLibrary::countMaxDepth($repacked) != 2 || SimpleArrayLibrary::countMinDepth($repacked) != 2) {
         throw new UnexpectedValueException('Invalid input');
     }
     $return = [];
     foreach ($repacked as $collection => $data) {
         $i = $data['i'];
         unset($data['i']);
         $return[$i] = [$collection => array_unique($data)];
     }
     ksort($return);
     $return = array_values($return);
     $return = array_reverse($return);
     return $return;
 }