-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add integration tests #121
Conversation
…into feat-integration-tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do a deeper dive later tonight, this thought just crossed my mind.
@@ -0,0 +1,4 @@ | |||
#[test] | |||
fn binary_works() { | |||
assert!(crate::integration::run_php("array.php")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a 100% happy how the PHP code is executed using a hardcoded path to the compiled extension. Nontheless, I think that is a good start for the first iteration
And idea that might work is to put together a simple macro and embed the php snippet directly into this file:
#[test]
fn binary_works() {
php_test!(r#"
// Tests sequential arrays
$array = test_array(['a', 'b', 'c']);
assert(is_array($array));
assert(count($array) === 3);
assert(in_array('a', $array));
assert(in_array('b', $array));
assert(in_array('c', $array));
// Tests associative arrays
$assoc = test_array_assoc([
'a' => '1',
'b' => '2',
'c' => '3'
]);
assert(array_key_exists('a', $assoc));
assert(array_key_exists('b', $assoc));
assert(array_key_exists('c', $assoc));
assert(in_array('1', $assoc));
assert(in_array('2', $assoc));
assert(in_array('3', $assoc));
"#);
}
For the initial version, we could either automatically write out a file an execute it or - I believe this should work - pipe the input into php without touching the filesystem.
I will resume working on my execution support, after which this could mature into something entirely in process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a solid start to me 👍
@TorstenDittmann how are you feeling about that state of this PR? I may be able to help finish it if you're short on time. |
What's the status on this ? I feel like such test would be very helpful when developing this library |
It's the most critical feature that I want, but this PR is abandoned. |
Yeah, it kinda got abandoned due to many reason. If there is interest I can spend a weekend to probably create the PR again from scratch 👀 |
That would be nice, it could even be used by people creating extension with this lib to test there code. I think this would be possible if there was a possibility to compile php with code from this library under a new binary, which would also allow to create binary in rust that can execute php code (like a new sapi ?) |
There is this experimental module here https://github.com/php/php-src/tree/master/sapi/embed to produce a single binary with the Zend engine entry point. I did a small PoC with it and Tauri to reproduce what NativePHP does: it works well. |
Can you share your PoC with Tauri ? i would be interested in how you did that |
I made an example on #270 It works great, it even allow to put test directly in the wanted file, i will try to do a wrapper so we can execute code directly in it, thanks for the input @ptondereau about embed this is certainly the best way to go for that |
Implemented a very basic test suite for all Datatypes that can be passed as an argument or returned.
I am not sure what kind of conventions you would like to follow here, so I kept the PHP files very stupid - same with the assertion texts. So we would need to decide on a proper way of how to pass the results from PHP to Rust.
Not a 100% happy how the PHP code is executed using a hardcoded path to the compiled extension. Nontheless, I think that is a good start for the first iteration 👍🏻