Skip to content

Commit c5aee5b

Browse files
committed
test(macro): migrate tests to outer macro pattern
Refs: 335
1 parent e6a1d53 commit c5aee5b

File tree

1 file changed

+93
-93
lines changed

1 file changed

+93
-93
lines changed

tests/src/lib.rs

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,120 @@
11
#![cfg_attr(windows, feature(abi_vectorcall))]
2-
use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval};
3-
use std::collections::HashMap;
2+
use ext_php_rs::prelude::php_module;
43

5-
#[php_function]
6-
pub fn test_str(a: &str) -> &str {
7-
a
8-
}
9-
10-
#[php_function]
11-
pub fn test_string(a: String) -> String {
12-
a
13-
}
14-
15-
#[php_function]
16-
pub fn test_bool(a: bool) -> bool {
17-
a
18-
}
19-
20-
#[php_function]
21-
pub fn test_number_signed(a: i32) -> i32 {
22-
a
23-
}
4+
#[php_module]
5+
mod module {
6+
use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval};
7+
use std::collections::HashMap;
248

25-
#[php_function]
26-
pub fn test_number_unsigned(a: u32) -> u32 {
27-
a
28-
}
9+
#[php_function()]
10+
pub fn test_str(a: &str) -> &str {
11+
a
12+
}
2913

30-
#[php_function]
31-
pub fn test_number_float(a: f32) -> f32 {
32-
a
33-
}
14+
#[php_function()]
15+
pub fn test_string(a: String) -> String {
16+
a
17+
}
3418

35-
#[php_function]
36-
pub fn test_array(a: Vec<String>) -> Vec<String> {
37-
a
38-
}
19+
#[php_function()]
20+
pub fn test_bool(a: bool) -> bool {
21+
a
22+
}
3923

40-
#[php_function]
41-
pub fn test_array_assoc(a: HashMap<String, String>) -> HashMap<String, String> {
42-
a
43-
}
24+
#[php_function()]
25+
pub fn test_number_signed(a: i32) -> i32 {
26+
a
27+
}
4428

45-
#[php_function]
46-
pub fn test_binary(a: Binary<u32>) -> Binary<u32> {
47-
a
48-
}
29+
#[php_function()]
30+
pub fn test_number_unsigned(a: u32) -> u32 {
31+
a
32+
}
4933

50-
#[php_function]
51-
pub fn test_nullable(a: Option<String>) -> Option<String> {
52-
a
53-
}
34+
#[php_function()]
35+
pub fn test_number_float(a: f32) -> f32 {
36+
a
37+
}
5438

55-
#[php_function]
56-
pub fn test_object(a: &mut ZendObject) -> &mut ZendObject {
57-
a
58-
}
39+
#[php_function()]
40+
pub fn test_array(a: Vec<String>) -> Vec<String> {
41+
a
42+
}
5943

60-
#[php_function]
61-
pub fn test_closure() -> Closure {
62-
Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>)
63-
}
44+
#[php_function()]
45+
pub fn test_array_assoc(a: HashMap<String, String>) -> HashMap<String, String> {
46+
a
47+
}
6448

65-
#[php_function]
66-
pub fn test_closure_once(a: String) -> Closure {
67-
Closure::wrap_once(Box::new(move || a) as Box<dyn FnOnce() -> String>)
68-
}
49+
#[php_function()]
50+
pub fn test_binary(a: Binary<u32>) -> Binary<u32> {
51+
a
52+
}
6953

70-
#[php_function]
71-
pub fn test_callable(call: ZendCallable, a: String) -> Zval {
72-
call.try_call(vec![&a]).expect("Failed to call function")
73-
}
54+
#[php_function()]
55+
pub fn test_nullable(a: Option<String>) -> Option<String> {
56+
a
57+
}
7458

75-
#[php_class]
76-
pub struct TestClass {
77-
string: String,
78-
number: i32,
79-
#[prop]
80-
boolean: bool,
81-
}
59+
#[php_function()]
60+
pub fn test_object(a: &mut ZendObject) -> &mut ZendObject {
61+
a
62+
}
8263

83-
#[php_impl]
84-
impl TestClass {
85-
#[getter]
86-
pub fn get_string(&self) -> String {
87-
self.string.to_string()
64+
#[php_function()]
65+
pub fn test_closure() -> Closure {
66+
Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>)
8867
}
8968

90-
#[setter]
91-
pub fn set_string(&mut self, string: String) {
92-
self.string = string;
69+
#[php_function()]
70+
pub fn test_closure_once(a: String) -> Closure {
71+
Closure::wrap_once(Box::new(move || a) as Box<dyn FnOnce() -> String>)
9372
}
9473

95-
#[getter]
96-
pub fn get_number(&self) -> i32 {
97-
self.number
74+
#[php_function()]
75+
pub fn test_callable(call: ZendCallable, a: String) -> Zval {
76+
call.try_call(vec![&a]).expect("Failed to call function")
9877
}
9978

100-
#[setter]
101-
pub fn set_number(&mut self, number: i32) {
102-
self.number = number;
79+
#[php_class]
80+
pub struct TestClass {
81+
string: String,
82+
number: i32,
83+
#[prop]
84+
boolean: bool,
10385
}
104-
}
10586

106-
#[php_function]
107-
pub fn test_class(string: String, number: i32) -> TestClass {
108-
TestClass {
109-
string,
110-
number,
111-
boolean: true,
87+
#[php_impl]
88+
impl TestClass {
89+
#[getter]
90+
pub fn get_string(&self) -> String {
91+
self.string.to_string()
92+
}
93+
94+
#[setter]
95+
pub fn set_string(&mut self, string: String) {
96+
self.string = string;
97+
}
98+
99+
#[getter]
100+
pub fn get_number(&self) -> i32 {
101+
self.number
102+
}
103+
104+
#[setter]
105+
pub fn set_number(&mut self, number: i32) {
106+
self.number = number;
107+
}
112108
}
113-
}
114109

115-
#[php_module]
116-
pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
117-
module
110+
#[php_function()]
111+
pub fn test_class(string: String, number: i32) -> TestClass {
112+
TestClass {
113+
string,
114+
number,
115+
boolean: true,
116+
}
117+
}
118118
}
119119

120120
#[cfg(test)]

0 commit comments

Comments
 (0)