Skip to content

Commit b5bde5c

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

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-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: 42 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,40 @@ 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+
ProcessGlobals::get().http_server_vars().unwrap().to_owned()
85+
}
86+
87+
#[php_function]
88+
pub fn test_globals_http_request() -> ZBox<ZendHashTable> {
89+
ProcessGlobals::get()
90+
.http_request_vars()
91+
.unwrap()
92+
.to_owned()
93+
}
94+
95+
#[php_function]
96+
pub fn test_globals_http_files() -> ZBox<ZendHashTable> {
97+
ProcessGlobals::get().http_files_vars().to_owned()
98+
}
99+
60100
#[php_function]
61101
pub fn test_closure() -> Closure {
62102
Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>)
@@ -179,6 +219,7 @@ mod integration {
179219
mod callable;
180220
mod class;
181221
mod closure;
222+
mod globals;
182223
mod nullable;
183224
mod number;
184225
mod object;

0 commit comments

Comments
 (0)