Skip to content

Commit 901d6a7

Browse files
authored
adding test for bind_class (#178)
1 parent 16932a1 commit 901d6a7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tests/integration/src/classes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn integrate(module: &mut Module) {
3131

3232
fn integrate_a(module: &mut Module) {
3333
let mut class = ClassEntity::new("IntegrationTest\\A");
34+
let integrate_a_class = class.bind_class();
3435

3536
class.add_property("name", Visibility::Private, "default");
3637
class.add_property("number", Visibility::Private, 100);
@@ -51,6 +52,11 @@ fn integrate_a(module: &mut Module) {
5152
})
5253
.arguments([Argument::by_val("name"), Argument::by_val("number")]);
5354

55+
class.add_static_method("newInstance", Visibility::Public, move |_| {
56+
let object = integrate_a_class.init_object()?;
57+
Ok::<_, phper::Error>(object)
58+
});
59+
5460
class.add_method("speak", Visibility::Public, |this, _arguments| {
5561
let name = this
5662
.get_property("name")

tests/integration/tests/php/classes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
$property_name = $reflection_class->getProperty("name");
3030
assert_true($property_name->isPrivate());
3131

32+
// Test bind_class
33+
$a_instance = IntegrationTest\A::newInstance();
34+
assert_true($a_instance instanceof IntegrationTest\A);
35+
assert_eq($a_instance->speak(), "name: default, number: 100");
36+
3237
// Test registering class;
3338
$foo = new \IntegrationTest\Foo();
3439

0 commit comments

Comments
 (0)