Skip to content

Commit 632d3d3

Browse files
committed
Add tests
1 parent 1c0ad9b commit 632d3d3

File tree

9 files changed

+66
-3
lines changed

9 files changed

+66
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug GH-20914: Internal enums can be compared
2+
Enum comparison (internal enum)
33
--EXTENSIONS--
44
zend_test
55
--FILE--
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Enum implements (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
var_dump(ZendTestUnitEnum::Foo instanceof _ZendTestInterface);
9+
var_dump(ZendTestEnumWithInterface::Foo instanceof _ZendTestInterface);
10+
11+
?>
12+
--EXPECT--
13+
bool(false)
14+
bool(true)

Zend/tests/enum/instanceof-backed-enum.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Auto implement BackedEnum interface
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

@@ -13,8 +15,12 @@ enum Baz: int {
1315

1416
var_dump(Foo::Bar instanceof BackedEnum);
1517
var_dump(Baz::Qux instanceof BackedEnum);
18+
var_dump(ZendTestUnitEnum::Foo instanceof BackedEnum);
19+
var_dump(ZendTestIntEnum::Foo instanceof BackedEnum);
1620

1721
?>
1822
--EXPECT--
1923
bool(false)
2024
bool(true)
25+
bool(false)
26+
bool(true)

Zend/tests/enum/instanceof-unitenum.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Auto implement UnitEnum interface
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

@@ -11,8 +13,10 @@ class Baz {}
1113

1214
var_dump(Foo::Bar instanceof UnitEnum);
1315
var_dump((new Baz()) instanceof UnitEnum);
16+
var_dump(ZendTestUnitEnum::Foo instanceof UnitEnum);
1417

1518
?>
1619
--EXPECT--
1720
bool(true)
1821
bool(false)
22+
bool(true)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug GH-20914: Internal enums can be cloned
2+
Enum disallows cloning (internal enum)
33
--EXTENSIONS--
44
zend_test
55
--FILE--
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Enum case disallows dynamic properties (internal enum)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
$bar = ZendTestUnitEnum::Bar;
9+
10+
try {
11+
$bar->baz = 'Baz';
12+
} catch (\Error $e) {
13+
echo $e->getMessage();
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Cannot create dynamic property ZendTestUnitEnum::$baz

ext/zend_test/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static zend_class_entry *zend_test_ns2_ns_foo_class;
7474
static zend_class_entry *zend_test_unit_enum;
7575
static zend_class_entry *zend_test_string_enum;
7676
static zend_class_entry *zend_test_int_enum;
77+
static zend_class_entry *zend_test_enum_with_interface;
7778
static zend_class_entry *zend_test_magic_call;
7879
static zend_object_handlers zend_test_class_handlers;
7980

@@ -1318,6 +1319,7 @@ PHP_MINIT_FUNCTION(zend_test)
13181319
zend_test_unit_enum = register_class_ZendTestUnitEnum();
13191320
zend_test_string_enum = register_class_ZendTestStringEnum();
13201321
zend_test_int_enum = register_class_ZendTestIntEnum();
1322+
zend_test_enum_with_interface = register_class_ZendTestEnumWithInterface(zend_test_interface);
13211323

13221324
zend_test_magic_call = register_class__ZendTestMagicCall();
13231325

ext/zend_test/test.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ enum ZendTestIntEnum: int {
201201
case Baz = -1;
202202
}
203203

204+
enum ZendTestEnumWithInterface implements _ZendTestInterface {
205+
case Foo;
206+
case Bar;
207+
}
208+
204209
function zend_test_array_return(): array {}
205210

206211
/** @genstubs-expose-comment-block

ext/zend_test/test_arginfo.h

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)