/**
  * @covers SilverStripe\Core\ClassInfo::ancestry()
  */
 public function testAncestry()
 {
     $ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass');
     $expect = ArrayLib::valuekey(array('SilverStripe\\Core\\Object', 'SilverStripe\\View\\ViewableData', 'SilverStripe\\ORM\\DataObject', 'ClassInfoTest_BaseClass', 'ClassInfoTest_ChildClass'));
     $this->assertEquals($expect, $ancestry);
     ClassInfo::reset_db_cache();
     $this->assertEquals($expect, ClassInfo::ancestry('classINFOTest_Childclass'));
     ClassInfo::reset_db_cache();
     $this->assertEquals($expect, ClassInfo::ancestry('classINFOTest_Childclass'));
     ClassInfo::reset_db_cache();
     $ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass', true);
     $this->assertEquals(array('ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass'), $ancestry, '$tablesOnly option excludes memory-only inheritance classes');
 }
    public function testEnumParsing()
    {
        $enum = new DBEnum('testField', "\n\t\t\t,\n\t\t\t0,\n\t\t\tItem1,\n\t\t\tItem2,\n\t\t\tItem 3,\n\t\t\tItem-4,\n\t\t\titem 5\n\t\t\tstill 5,\n\t\t\ttrailing comma,\n\t\t");
        $this->assertEquals(ArrayLib::valuekey(array('', '0', 'Item1', 'Item2', 'Item 3', 'Item-4', 'item 5
			still 5', 'trailing comma')), $enum->enumValues());
    }
 /**
  * Returns a list of classes that inherit from the given class.
  * The resulting array includes the base class passed
  * through the $class parameter as the first array value.
  *
  * Example usage:
  * <code>
  * ClassInfo::subclassesFor('BaseClass');
  * 	array(
  * 	'BaseClass' => 'BaseClass',
  * 	'ChildClass' => 'ChildClass',
  * 	'GrandChildClass' => 'GrandChildClass'
  * )
  * </code>
  *
  * @param string|object $nameOrObject The classname or object
  * @return array Names of all subclasses as an associative array.
  */
 public static function subclassesFor($nameOrObject)
 {
     if (is_string($nameOrObject) && !class_exists($nameOrObject)) {
         return [];
     }
     //normalise class case
     $className = self::class_name($nameOrObject);
     $descendants = ClassLoader::instance()->getManifest()->getDescendantsOf($className);
     $result = array($className => $className);
     if ($descendants) {
         return $result + ArrayLib::valuekey($descendants);
     } else {
         return $result;
     }
 }
 public function testValuekey()
 {
     $this->assertEquals(ArrayLib::valuekey(array('testkey1' => 'testvalue1', 'testkey2' => 'testvalue2')), array('testvalue1' => 'testvalue1', 'testvalue2' => 'testvalue2'));
 }
 /**
  * Add {@link RequiredField} objects together
  *
  * @param RequiredFields $requiredFields
  * @return RequiredFields
  */
 public function appendRequiredFields($requiredFields)
 {
     $this->required = $this->required + ArrayLib::valuekey($requiredFields->getRequired());
     return $this;
 }