Skip to content

Commit 589fee9

Browse files
committed
1 parent 89bbaf5 commit 589fee9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+886
-21
lines changed

Zend/tests/enum/001.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Enum comparison
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
case Baz;
9+
}
10+
11+
$bar = Foo::Bar;
12+
$baz = Foo::Baz;
13+
14+
var_dump($bar === $bar);
15+
var_dump($bar == $bar);
16+
17+
var_dump($bar === $baz);
18+
var_dump($bar == $baz);
19+
20+
var_dump($baz === $bar);
21+
var_dump($baz == $bar);
22+
23+
?>
24+
--EXPECT--
25+
bool(true)
26+
bool(true)
27+
bool(false)
28+
bool(false)
29+
bool(false)
30+
bool(false)

Zend/tests/enum/002.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Enum methods
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
case Baz;
9+
10+
public function dump() {
11+
var_dump($this);
12+
}
13+
}
14+
15+
Foo::Bar->dump();
16+
Foo::Baz->dump();
17+
18+
?>
19+
--EXPECT--
20+
enum(Foo::Bar)
21+
enum(Foo::Baz)

Zend/tests/enum/003.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Enum type hints
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
}
9+
10+
enum Baz {
11+
case Qux;
12+
}
13+
14+
function takesFoo(Foo $foo) {}
15+
function takesBaz(Baz $baz) {}
16+
17+
takesFoo(Foo::Bar);
18+
takesBaz(Baz::Qux);
19+
20+
try {
21+
takesBaz(Foo::Bar);
22+
} catch (Error $e) {
23+
echo $e->getMessage() . "\n";
24+
}
25+
26+
try {
27+
takesFoo(Baz::Qux);
28+
} catch (Error $e) {
29+
echo $e->getMessage() . "\n";
30+
}
31+
32+
?>
33+
--EXPECTF--
34+
takesBaz(): Argument #1 ($baz) must be of type Baz, Foo::Bar given, called in %s on line %d
35+
takesFoo(): Argument #1 ($foo) must be of type Foo, Baz::Qux given, called in %s on line %d

Zend/tests/enum/004.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Enum instanceof
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
}
9+
10+
enum Baz {
11+
case Qux;
12+
}
13+
14+
var_dump(Foo::Bar instanceof Foo);
15+
var_dump(Baz::Qux instanceof Baz);
16+
17+
var_dump(Foo::Bar instanceof Baz);
18+
var_dump(Baz::Qux instanceof Foo);
19+
20+
?>
21+
--EXPECT--
22+
bool(true)
23+
bool(true)
24+
bool(false)
25+
bool(false)

Zend/tests/enum/005.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Enum implements implemented in enum
3+
--FILE--
4+
<?php
5+
6+
interface Colorful {
7+
public function color(): string;
8+
}
9+
10+
enum Suit /* implements Colorful */ {
11+
case Hearts;
12+
case Diamonds;
13+
case Clubs;
14+
case Spades;
15+
16+
public function color(): string {
17+
return match ($this) {
18+
self::Hearts, self::Diamonds => 'Red',
19+
self::Clubs, self::Spades => 'Black',
20+
};
21+
}
22+
}
23+
24+
echo Suit::Hearts->color() . "\n";
25+
echo Suit::Diamonds->color() . "\n";
26+
echo Suit::Clubs->color() . "\n";
27+
echo Suit::Spades->color() . "\n";
28+
29+
?>
30+
--EXPECT--
31+
Red
32+
Red
33+
Black
34+
Black

Zend/tests/enum/006.phpt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Enum implements implemented in cases
3+
--FILE--
4+
<?php
5+
6+
interface Colorful {
7+
public function color(): string;
8+
}
9+
10+
enum Suit /* implements Colorful */ {
11+
case Hearts {
12+
public function color(): string {
13+
return 'Red';
14+
}
15+
}
16+
17+
case Diamonds {
18+
public function color(): string {
19+
return 'Red';
20+
}
21+
}
22+
23+
case Clubs {
24+
public function color(): string {
25+
return 'Black';
26+
}
27+
}
28+
29+
case Spades {
30+
public function color(): string {
31+
return 'Black';
32+
}
33+
}
34+
}
35+
36+
echo Suit::Hearts->color() . "\n";
37+
echo Suit::Diamonds->color() . "\n";
38+
echo Suit::Clubs->color() . "\n";
39+
echo Suit::Spades->color() . "\n";
40+
41+
?>
42+
--EXPECT--
43+
Red
44+
Red
45+
Black
46+
Black

Zend/tests/enum/007.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Enum is final
3+
--FILE--
4+
<?php
5+
6+
enum Foo {}
7+
8+
class Bar extends Foo {}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Class Bar may not inherit from final class (Foo) in %s on line %d

Zend/tests/enum/008.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Enum case is final
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar;
8+
}
9+
10+
class_alias('Foo::Bar', 'Bar');
11+
12+
class Baz extends Bar {}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Class Baz may not inherit from final class (Foo::Bar) in %s on line %d

Zend/tests/enum/009.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Enum disallows properties
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
public $bar;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Enums may not include member variables in %s on line %d

Zend/tests/enum/010.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Enum case disallows properties
3+
--FILE--
4+
<?php
5+
6+
enum Foo {
7+
case Bar {
8+
public $baz;
9+
}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Enum cases may not include member variables in %s on line %d

0 commit comments

Comments
 (0)