-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConvertTest.php
65 lines (54 loc) · 1.41 KB
/
ConvertTest.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Bakame\Aide\Enum;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class ConvertTest extends TestCase
{
#[Test]
public function it_can_get_information_from_a_pure_enumeration(): void
{
self::assertSame([], Direction::toAssociative());
$expected = <<<JS
const Direction = Object.freeze({
Top: Symbol(0),
Down: Symbol(1),
Left: Symbol(2),
Right: Symbol(3)
})
JS;
self::assertSame($expected, Direction::toJavaScriptObject());
}
#[Test]
public function it_can_get_information_from_a_backed_enumeration(): void
{
$expectedAssociative = [
'North' => 'north',
'South' => 'south',
'East' => 'east',
'West' => 'west',
];
$expectedObject = <<<JS
const Cardinal = Object.freeze({
North: "north",
South: "south",
East: "east",
West: "west"
})
JS;
$expectedClass = <<<JS
class Cardinal {
static North = new Cardinal("north")
static South = new Cardinal("south")
static East = new Cardinal("east")
static West = new Cardinal("west")
constructor(name) {
this.name = name
}
}
JS;
self::assertSame($expectedAssociative, Cardinal::toAssociative());
self::assertSame($expectedObject, Cardinal::toJavaScriptObject());
self::assertSame($expectedClass, Cardinal::toJavaScriptClass());
}
}