Skip to content

Commit 1c0d655

Browse files
committed
test(globals): add integration tests
Refs: #331
1 parent 2ad07b9 commit 1c0d655

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

tests/src/integration/globals.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
assert(test_globals_http_get() === []);
4+
assert(test_globals_http_post() === []);
5+
assert(test_globals_http_cookie() === []);
6+
assert(!empty(test_globals_http_server()));
7+
assert(test_globals_http_request() === []);
8+
assert(test_globals_http_files() === []);

tests/src/integration/globals.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn globals_works() {
3+
assert!(crate::integration::run_php("globals.php"));
4+
}

tests/src/lib.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![cfg_attr(windows, feature(abi_vectorcall))]
2-
use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval};
2+
use ext_php_rs::{
3+
binary::Binary,
4+
boxed::ZBox,
5+
prelude::*,
6+
types::{ZendHashTable, ZendObject, Zval},
7+
zend::ProcessGlobals,
8+
};
39
use std::collections::HashMap;
410

511
#[php_function]
@@ -57,6 +63,41 @@ pub fn test_object(a: &mut ZendObject) -> &mut ZendObject {
5763
a
5864
}
5965

66+
// GLOBALS
67+
#[php_function]
68+
pub fn test_globals_http_get() -> ZBox<ZendHashTable> {
69+
ProcessGlobals::get().http_get_vars().to_owned()
70+
}
71+
72+
#[php_function]
73+
pub fn test_globals_http_post() -> ZBox<ZendHashTable> {
74+
ProcessGlobals::get().http_post_vars().to_owned()
75+
}
76+
77+
#[php_function]
78+
pub fn test_globals_http_cookie() -> ZBox<ZendHashTable> {
79+
ProcessGlobals::get().http_cookie_vars().to_owned()
80+
}
81+
82+
#[php_function]
83+
pub fn test_globals_http_server() -> ZBox<ZendHashTable> {
84+
println!("{:?}", ProcessGlobals::get().http_server_vars());
85+
ProcessGlobals::get().http_server_vars().unwrap().to_owned()
86+
}
87+
88+
#[php_function]
89+
pub fn test_globals_http_request() -> ZBox<ZendHashTable> {
90+
ProcessGlobals::get()
91+
.http_request_vars()
92+
.unwrap()
93+
.to_owned()
94+
}
95+
96+
#[php_function]
97+
pub fn test_globals_http_files() -> ZBox<ZendHashTable> {
98+
ProcessGlobals::get().http_files_vars().to_owned()
99+
}
100+
60101
#[php_function]
61102
pub fn test_closure() -> Closure {
62103
Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>)
@@ -179,6 +220,7 @@ mod integration {
179220
mod callable;
180221
mod class;
181222
mod closure;
223+
mod globals;
182224
mod nullable;
183225
mod number;
184226
mod object;

0 commit comments

Comments
 (0)