From 4a38508411b2b8a160aa36acaa54aad9708c80a2 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 11 Jun 2026 17:06:02 +0800 Subject: [PATCH] =?UTF-8?q?test(core):=20=E6=B7=BB=E5=8A=A0=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E6=AF=94=E8=BE=83=E5=92=8C=E7=B1=BB=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=87=BD=E6=95=B0=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 strcmp、strncmp、strcasecmp、strncasecmp 字符串比较函数测试 - 添加 class_exists、interface_exists、trait_exists、enum_exists 类存在性检查函数测试 - 添加 method_exists、property_exists 方法和属性存在性检查函数测试 - 添加 is_a、is_subclass_of 类型检查函数测试 - 添加 defined 常量定义检查函数测试 - 添加 get_parent_class 获取父类函数测试 --- tests/std/core/001_strcmp.phpt | 41 +++++++++++++++++++++ tests/std/core/002_class_exists.phpt | 42 +++++++++++++++++++++ tests/std/core/003_method_exists.phpt | 47 ++++++++++++++++++++++++ tests/std/core/004_is_a.phpt | 39 ++++++++++++++++++++ tests/std/core/005_defined.phpt | 23 ++++++++++++ tests/std/core/006_get_parent_class.phpt | 27 ++++++++++++++ 6 files changed, 219 insertions(+) create mode 100644 tests/std/core/001_strcmp.phpt create mode 100644 tests/std/core/002_class_exists.phpt create mode 100644 tests/std/core/003_method_exists.phpt create mode 100644 tests/std/core/004_is_a.phpt create mode 100644 tests/std/core/005_defined.phpt create mode 100644 tests/std/core/006_get_parent_class.phpt diff --git a/tests/std/core/001_strcmp.phpt b/tests/std/core/001_strcmp.phpt new file mode 100644 index 00000000..315e927a --- /dev/null +++ b/tests/std/core/001_strcmp.phpt @@ -0,0 +1,41 @@ +--TEST-- +strcmp() / strncmp() / strcasecmp() / strncasecmp() functions +--FILE-- + 0 ? "ok-greater\n" : "fail\n"; +echo strcmp("", "") === 0 ? "ok-empty\n" : "fail\n"; + +echo "strncmp:\n"; +echo strncmp("abcdef", "abcxyz", 3) === 0 ? "ok-equal3\n" : "fail\n"; +echo strncmp("abcdef", "abcxyz", 6) < 0 ? "ok-less6\n" : "fail\n"; +echo strncmp("abc", "abc", 5) === 0 ? "ok-overflow\n" : "fail\n"; + +echo "strcasecmp:\n"; +echo strcasecmp("ABC", "abc") === 0 ? "ok-equal\n" : "fail\n"; +echo strcasecmp("ABC", "abd") < 0 ? "ok-less\n" : "fail\n"; + +echo "strncasecmp:\n"; +echo strncasecmp("ABCDEF", "abcxyz", 3) === 0 ? "ok-equal3\n" : "fail\n"; +echo strncasecmp("ABCDEF", "abcxyz", 6) < 0 ? "ok-less6\n" : "fail\n"; + +?> +--EXPECT-- +strcmp: +ok-equal +ok-less +ok-greater +ok-empty +strncmp: +ok-equal3 +ok-less6 +ok-overflow +strcasecmp: +ok-equal +ok-less +strncasecmp: +ok-equal3 +ok-less6 diff --git a/tests/std/core/002_class_exists.phpt b/tests/std/core/002_class_exists.phpt new file mode 100644 index 00000000..4c4c81c5 --- /dev/null +++ b/tests/std/core/002_class_exists.phpt @@ -0,0 +1,42 @@ +--TEST-- +class_exists() / interface_exists() / trait_exists() / enum_exists() functions +--FILE-- + +--EXPECT-- +class_exists: +ok-true +ok-false +interface_exists: +ok-true +ok-false +trait_exists: +ok-true +ok-false +enum_exists: +ok-true +ok-false +done diff --git a/tests/std/core/003_method_exists.phpt b/tests/std/core/003_method_exists.phpt new file mode 100644 index 00000000..8e7cc7e8 --- /dev/null +++ b/tests/std/core/003_method_exists.phpt @@ -0,0 +1,47 @@ +--TEST-- +method_exists() / property_exists() functions +--FILE-- + +--EXPECT-- +method_exists: +ok-obj-pub +ok-obj-priv +ok-obj-none +ok-cls-pub +ok-cls-none +property_exists: +ok-obj-pub +ok-obj-priv +ok-obj-none +ok-cls-pub +ok-cls-priv +ok-cls-none +done diff --git a/tests/std/core/004_is_a.phpt b/tests/std/core/004_is_a.phpt new file mode 100644 index 00000000..f58c8d8a --- /dev/null +++ b/tests/std/core/004_is_a.phpt @@ -0,0 +1,39 @@ +--TEST-- +is_a() / is_subclass_of() functions +--FILE-- + +--EXPECT-- +is_a: +ok-obj-class +ok-obj-parent +ok-obj-none +is_subclass_of: +ok-obj-parent +ok-obj-same +ok-cls-parent +ok-cls-same +ok-none +done diff --git a/tests/std/core/005_defined.phpt b/tests/std/core/005_defined.phpt new file mode 100644 index 00000000..485b0135 --- /dev/null +++ b/tests/std/core/005_defined.phpt @@ -0,0 +1,23 @@ +--TEST-- +defined() function +--FILE-- + +--EXPECT-- +defined: +ok-defined +ok-string-defined +ok-php-version +ok-undefined +done diff --git a/tests/std/core/006_get_parent_class.phpt b/tests/std/core/006_get_parent_class.phpt new file mode 100644 index 00000000..b5679859 --- /dev/null +++ b/tests/std/core/006_get_parent_class.phpt @@ -0,0 +1,27 @@ +--TEST-- +get_parent_class() function +--FILE-- + +--EXPECT-- +get_parent_class: +ok-obj +ok-cls +ok-obj-false +ok-cls-false +done