Skip to content

Commit

Permalink
added support for class constants (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
adaamz authored and dg committed Jun 8, 2017
1 parent 8605fd1 commit ced817c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/PhpGenerator/Factory.php
Expand Up @@ -46,6 +46,7 @@ public function fromClassReflection(\ReflectionClass $from): ClassType
}
}
$class->setMethods($methods);
$class->setConstants($from->getConstants());
return $class;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PhpGenerator/ClassType.from.expect
Expand Up @@ -64,3 +64,9 @@ class Class3
public $prop1;

}

class Class4
{
const THE_CONSTANT = 9;

}
9 changes: 8 additions & 1 deletion tests/PhpGenerator/ClassType.from.php71.expect
Expand Up @@ -15,4 +15,11 @@ class ClassA
{
}

}
}

class ClassB
{
const THE_PRIVATE_CONSTANT = 9;
const THE_PUBLIC_CONSTANT = 9;

}
7 changes: 7 additions & 0 deletions tests/PhpGenerator/ClassType.from.php71.phpt
Expand Up @@ -23,7 +23,14 @@ class ClassA
function func3(): void {}
}

class ClassB
{
private const THE_PRIVATE_CONSTANT = 9;
public const THE_PUBLIC_CONSTANT = 9;
}


$res[] = ClassType::from(ClassA::class);
$res[] = ClassType::from(ClassB::class);

Assert::matchFile(__DIR__ . '/ClassType.from.php71.expect', implode("\n", $res));
6 changes: 6 additions & 0 deletions tests/PhpGenerator/ClassType.from.phpt
Expand Up @@ -69,12 +69,18 @@ class Class3
public $prop1;
}

class Class4
{
const THE_CONSTANT = 9;
}

$res[] = ClassType::from(Interface1::class);
$res[] = ClassType::from(Interface2::class);
$res[] = ClassType::from(Class1::class);
$res[] = ClassType::from(new Class2);
$obj = new Class3;
$obj->prop2 = 1;
$res[] = (new Factory)->fromClassReflection(new \ReflectionObject($obj));
$res[] = ClassType::from(Class4::class);

Assert::matchFile(__DIR__ . '/ClassType.from.expect', implode("\n", $res));

0 comments on commit ced817c

Please sign in to comment.