Skip to content

Commit 432b52b

Browse files
committed
test(interface): add macro expansion tests
Refs: davidcole1340#533
1 parent c0dcacd commit 432b52b

File tree

4 files changed

+236
-0
lines changed

4 files changed

+236
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#[macro_use]
2+
extern crate ext_php_rs_derive;
3+
/// Doc comments for MyClass.
4+
/// This is a basic class example.
5+
pub struct MyClass {}
6+
impl ::ext_php_rs::class::RegisteredClass for MyClass {
7+
const CLASS_NAME: &'static str = "MyClass";
8+
const BUILDER_MODIFIER: ::std::option::Option<
9+
fn(::ext_php_rs::builders::ClassBuilder) -> ::ext_php_rs::builders::ClassBuilder,
10+
> = ::std::option::Option::None;
11+
const EXTENDS: ::std::option::Option<::ext_php_rs::class::ClassEntryInfo> = None;
12+
const IMPLEMENTS: &'static [::ext_php_rs::class::ClassEntryInfo] = &[];
13+
const FLAGS: ::ext_php_rs::flags::ClassFlags = ::ext_php_rs::flags::ClassFlags::empty();
14+
const DOC_COMMENTS: &'static [&'static str] = &[
15+
" Doc comments for MyClass.",
16+
" This is a basic class example.",
17+
];
18+
#[inline]
19+
fn get_metadata() -> &'static ::ext_php_rs::class::ClassMetadata<Self> {
20+
static METADATA: ::ext_php_rs::class::ClassMetadata<MyClass> = ::ext_php_rs::class::ClassMetadata::new();
21+
&METADATA
22+
}
23+
fn get_properties<'a>() -> ::std::collections::HashMap<
24+
&'static str,
25+
::ext_php_rs::internal::property::PropertyInfo<'a, Self>,
26+
> {
27+
use ::std::iter::FromIterator;
28+
::std::collections::HashMap::from_iter([])
29+
}
30+
#[inline]
31+
fn method_builders() -> ::std::vec::Vec<
32+
(
33+
::ext_php_rs::builders::FunctionBuilder<'static>,
34+
::ext_php_rs::flags::MethodFlags,
35+
),
36+
> {
37+
use ::ext_php_rs::internal::class::PhpClassImpl;
38+
::ext_php_rs::internal::class::PhpClassImplCollector::<Self>::default()
39+
.get_methods()
40+
}
41+
#[inline]
42+
fn constructor() -> ::std::option::Option<
43+
::ext_php_rs::class::ConstructorMeta<Self>,
44+
> {
45+
use ::ext_php_rs::internal::class::PhpClassImpl;
46+
::ext_php_rs::internal::class::PhpClassImplCollector::<Self>::default()
47+
.get_constructor()
48+
}
49+
#[inline]
50+
fn constants() -> &'static [(
51+
&'static str,
52+
&'static dyn ::ext_php_rs::convert::IntoZvalDyn,
53+
&'static [&'static str],
54+
)] {
55+
use ::ext_php_rs::internal::class::PhpClassImpl;
56+
::ext_php_rs::internal::class::PhpClassImplCollector::<Self>::default()
57+
.get_constants()
58+
}
59+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[macro_use]
2+
extern crate ext_php_rs_derive;
3+
4+
/// Doc comments for MyClass.
5+
/// This is a basic class example.
6+
#[php_class]
7+
pub struct MyClass {}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#[macro_use]
2+
extern crate ext_php_rs_derive;
3+
/// Doc comments for MyInterface.
4+
/// This is a basic interface example.
5+
trait MyInterface {
6+
/// Doc comments for my_method.
7+
/// This method does something.
8+
fn my_method(&self, arg: i32) -> String;
9+
}
10+
pub struct PhpInterfaceMyInterface;
11+
impl ::ext_php_rs::class::RegisteredClass for PhpInterfaceMyInterface {
12+
const CLASS_NAME: &'static str = "MyInterface";
13+
const BUILDER_MODIFIER: Option<
14+
fn(::ext_php_rs::builders::ClassBuilder) -> ::ext_php_rs::builders::ClassBuilder,
15+
> = None;
16+
const EXTENDS: Option<::ext_php_rs::class::ClassEntryInfo> = None;
17+
const FLAGS: ::ext_php_rs::flags::ClassFlags = ::ext_php_rs::flags::ClassFlags::Interface;
18+
const IMPLEMENTS: &'static [::ext_php_rs::class::ClassEntryInfo] = &[];
19+
const DOC_COMMENTS: &'static [String] = &[
20+
" Doc comments for MyInterface.",
21+
" This is a basic interface example.",
22+
];
23+
fn get_metadata() -> &'static ::ext_php_rs::class::ClassMetadata<Self> {
24+
static METADATA: ::ext_php_rs::class::ClassMetadata<PhpInterfaceMyInterface> = ::ext_php_rs::class::ClassMetadata::new();
25+
&METADATA
26+
}
27+
fn method_builders() -> Vec<
28+
(
29+
::ext_php_rs::builders::FunctionBuilder<'static>,
30+
::ext_php_rs::flags::MethodFlags,
31+
),
32+
> {
33+
<[_]>::into_vec(
34+
::alloc::boxed::box_new([
35+
(
36+
::ext_php_rs::builders::FunctionBuilder::new_abstract("myMethod")
37+
.arg(
38+
::ext_php_rs::args::Arg::new(
39+
"arg",
40+
<i32 as ::ext_php_rs::convert::FromZvalMut>::TYPE,
41+
),
42+
)
43+
.not_required()
44+
.returns(
45+
<String as ::ext_php_rs::convert::IntoZval>::TYPE,
46+
false,
47+
<String as ::ext_php_rs::convert::IntoZval>::NULLABLE,
48+
)
49+
.docs(
50+
&[
51+
" Doc comments for my_method.",
52+
" This method does something.",
53+
],
54+
),
55+
::ext_php_rs::flags::MethodFlags::Public
56+
| ::ext_php_rs::flags::MethodFlags::Abstract,
57+
),
58+
]),
59+
)
60+
}
61+
fn constructor() -> Option<::ext_php_rs::class::ConstructorMeta<Self>> {
62+
None
63+
}
64+
fn constants() -> &'static [(
65+
&'static str,
66+
&'static dyn ext_php_rs::convert::IntoZvalDyn,
67+
ext_php_rs::describe::DocComments,
68+
)] {
69+
&[]
70+
}
71+
fn get_properties<'a>() -> ::std::collections::HashMap<
72+
&'static str,
73+
::ext_php_rs::internal::property::PropertyInfo<'a, Self>,
74+
> {
75+
{
76+
::core::panicking::panic_fmt(format_args!("Not supported for Interface"));
77+
};
78+
}
79+
}
80+
impl<'a> ::ext_php_rs::convert::FromZendObject<'a> for &'a PhpInterfaceMyInterface {
81+
#[inline]
82+
fn from_zend_object(
83+
obj: &'a ::ext_php_rs::types::ZendObject,
84+
) -> ::ext_php_rs::error::Result<Self> {
85+
let obj = ::ext_php_rs::types::ZendClassObject::<
86+
PhpInterfaceMyInterface,
87+
>::from_zend_obj(obj)
88+
.ok_or(::ext_php_rs::error::Error::InvalidScope)?;
89+
Ok(&**obj)
90+
}
91+
}
92+
impl<'a> ::ext_php_rs::convert::FromZendObjectMut<'a>
93+
for &'a mut PhpInterfaceMyInterface {
94+
#[inline]
95+
fn from_zend_object_mut(
96+
obj: &'a mut ::ext_php_rs::types::ZendObject,
97+
) -> ::ext_php_rs::error::Result<Self> {
98+
let obj = ::ext_php_rs::types::ZendClassObject::<
99+
PhpInterfaceMyInterface,
100+
>::from_zend_obj_mut(obj)
101+
.ok_or(::ext_php_rs::error::Error::InvalidScope)?;
102+
Ok(&mut **obj)
103+
}
104+
}
105+
impl<'a> ::ext_php_rs::convert::FromZval<'a> for &'a PhpInterfaceMyInterface {
106+
const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object(
107+
Some(
108+
<PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME,
109+
),
110+
);
111+
#[inline]
112+
fn from_zval(zval: &'a ::ext_php_rs::types::Zval) -> ::std::option::Option<Self> {
113+
<Self as ::ext_php_rs::convert::FromZendObject>::from_zend_object(zval.object()?)
114+
.ok()
115+
}
116+
}
117+
impl<'a> ::ext_php_rs::convert::FromZvalMut<'a> for &'a mut PhpInterfaceMyInterface {
118+
const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object(
119+
Some(
120+
<PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME,
121+
),
122+
);
123+
#[inline]
124+
fn from_zval_mut(
125+
zval: &'a mut ::ext_php_rs::types::Zval,
126+
) -> ::std::option::Option<Self> {
127+
<Self as ::ext_php_rs::convert::FromZendObjectMut>::from_zend_object_mut(
128+
zval.object_mut()?,
129+
)
130+
.ok()
131+
}
132+
}
133+
impl ::ext_php_rs::convert::IntoZendObject for PhpInterfaceMyInterface {
134+
#[inline]
135+
fn into_zend_object(
136+
self,
137+
) -> ::ext_php_rs::error::Result<
138+
::ext_php_rs::boxed::ZBox<::ext_php_rs::types::ZendObject>,
139+
> {
140+
Ok(::ext_php_rs::types::ZendClassObject::new(self).into())
141+
}
142+
}
143+
impl ::ext_php_rs::convert::IntoZval for PhpInterfaceMyInterface {
144+
const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object(
145+
Some(
146+
<PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME,
147+
),
148+
);
149+
const NULLABLE: bool = false;
150+
#[inline]
151+
fn set_zval(
152+
self,
153+
zv: &mut ::ext_php_rs::types::Zval,
154+
persistent: bool,
155+
) -> ::ext_php_rs::error::Result<()> {
156+
use ::ext_php_rs::convert::IntoZendObject;
157+
self.into_zend_object()?.set_zval(zv, persistent)
158+
}
159+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[macro_use]
2+
extern crate ext_php_rs_derive;
3+
4+
/// Doc comments for MyInterface.
5+
/// This is a basic interface example.
6+
#[php_interface]
7+
trait MyInterface {
8+
/// Doc comments for my_method.
9+
/// This method does something.
10+
fn my_method(&self, arg: i32) -> String;
11+
}

0 commit comments

Comments
 (0)