forked from hhvm/xhp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HackEnumAttributeTest.php
38 lines (33 loc) · 1.02 KB
/
HackEnumAttributeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?hh
enum TestEnum: int {
HERP = 1;
DERP = 2;
}
class :test:hack-enum-attribute extends :x:element {
attribute
TestEnum foo @required;
protected function render(): XHPRoot {
$foo = TestEnum::getNames()[$this->:foo];
return <div>{$foo}</div>;
}
}
class HackEnumAttributesTest extends PHPUnit_Framework_TestCase {
public function testValidValues(): void {
$x = <test:hack-enum-attribute foo={TestEnum::HERP} />;
$this->assertSame('<div>HERP</div>', $x->toString());
$x = <test:hack-enum-attribute foo={TestEnum::DERP} />;
$this->assertSame('<div>DERP</div>', $x->toString());
}
public function testValidRawValues(): void {
$x = <test:hack-enum-attribute foo={1} />;
$this->assertSame('<div>HERP</div>', $x->toString());
$x = <test:hack-enum-attribute foo={2} />;
$this->assertSame('<div>DERP</div>', $x->toString());
}
/**
* @expectedException XHPInvalidAttributeException
*/
public function testInvalidValue(): void {
$x = <test:hack-enum-attribute foo={0} />;
}
}