Skip to content

Commit

Permalink
test(globals): add integration tests
Browse files Browse the repository at this point in the history
Refs: #331
  • Loading branch information
Xenira committed Oct 22, 2024
1 parent 2ad07b9 commit 1c0d655
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/src/integration/globals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

assert(test_globals_http_get() === []);
assert(test_globals_http_post() === []);
assert(test_globals_http_cookie() === []);
assert(!empty(test_globals_http_server()));
assert(test_globals_http_request() === []);
assert(test_globals_http_files() === []);
4 changes: 4 additions & 0 deletions tests/src/integration/globals.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn globals_works() {
assert!(crate::integration::run_php("globals.php"));
}
44 changes: 43 additions & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#![cfg_attr(windows, feature(abi_vectorcall))]
use ext_php_rs::{binary::Binary, prelude::*, types::ZendObject, types::Zval};
use ext_php_rs::{
binary::Binary,
boxed::ZBox,
prelude::*,
types::{ZendHashTable, ZendObject, Zval},
zend::ProcessGlobals,
};
use std::collections::HashMap;

#[php_function]
Expand Down Expand Up @@ -57,6 +63,41 @@ pub fn test_object(a: &mut ZendObject) -> &mut ZendObject {
a
}

// GLOBALS
#[php_function]
pub fn test_globals_http_get() -> ZBox<ZendHashTable> {
ProcessGlobals::get().http_get_vars().to_owned()
}

#[php_function]
pub fn test_globals_http_post() -> ZBox<ZendHashTable> {
ProcessGlobals::get().http_post_vars().to_owned()
}

#[php_function]
pub fn test_globals_http_cookie() -> ZBox<ZendHashTable> {
ProcessGlobals::get().http_cookie_vars().to_owned()
}

#[php_function]
pub fn test_globals_http_server() -> ZBox<ZendHashTable> {
println!("{:?}", ProcessGlobals::get().http_server_vars());
ProcessGlobals::get().http_server_vars().unwrap().to_owned()
}

#[php_function]
pub fn test_globals_http_request() -> ZBox<ZendHashTable> {
ProcessGlobals::get()
.http_request_vars()
.unwrap()
.to_owned()
}

#[php_function]
pub fn test_globals_http_files() -> ZBox<ZendHashTable> {
ProcessGlobals::get().http_files_vars().to_owned()
}

#[php_function]
pub fn test_closure() -> Closure {
Closure::wrap(Box::new(|a| a) as Box<dyn Fn(String) -> String>)
Expand Down Expand Up @@ -179,6 +220,7 @@ mod integration {
mod callable;
mod class;
mod closure;
mod globals;
mod nullable;
mod number;
mod object;
Expand Down

0 comments on commit 1c0d655

Please sign in to comment.