-
-
Notifications
You must be signed in to change notification settings - Fork 79
Add integration tests #121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a4c61df
feat: integration tests
TorstenDittmann 216918a
fix: some leftovers in tests
TorstenDittmann ad22d0b
chore: remove todos
TorstenDittmann 09bf50d
fix: remove unnecessary lines
TorstenDittmann 2b9ca2a
chore: fix some styling
TorstenDittmann 9e15b1d
test: assert build status code
TorstenDittmann 04d81a7
test: remove unnecessary assignment
TorstenDittmann b363c1a
lint: replace assert_eq with assert
TorstenDittmann ff14190
tests: fix condition
TorstenDittmann df838e9
ci: use os from matrix
TorstenDittmann 6d80fb7
tests: restructure
TorstenDittmann b283f03
chore: run cargo fmt
TorstenDittmann aefed6e
cI: revert change for now
TorstenDittmann 854f1d6
tests: show more informations
TorstenDittmann eb5a768
tests: show stdout on error
TorstenDittmann da50c82
tests: even more verbose informations
TorstenDittmann 23a8df0
tests: revert to non-release extension for tests
TorstenDittmann 73c00bf
tests: test closure
TorstenDittmann 053e296
tests: enable closures again
TorstenDittmann eb4c9dd
tests: disable closure once test
TorstenDittmann c438b9c
Merge branch 'master' of https://github.com/davidcole1340/ext-php-rs …
TorstenDittmann 411e9a0
fix: enable closure once test again
TorstenDittmann 049f776
Merge remote-tracking branch 'origin/master' into feat-integration-tests
danog b8348fc
Fixup
danog 4a51e5d
Fixup
danog e7f4f48
Fixup
danog af8e7d0
Fix argument type allocation
danog 9547daf
Fix use after free
danog 1749f07
Fixup
danog 332b5a9
Fix tests
danog 6ae0ac4
Postpone for later
danog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "tests" | ||
| version = "0.0.0" | ||
| edition = "2021" | ||
| publish = false | ||
| license = "MIT OR Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| ext-php-rs = { path = "../", features = ["closure"] } | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| function assert_exception_thrown(callable $callback): void | ||
| { | ||
| try { | ||
| call_user_func($callback); | ||
| } catch (\Throwable $th) { | ||
| return; | ||
| } | ||
| throw new Exception("Excption was not thrown", 255); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| // 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn binary_works() { | ||
| assert!(crate::integration::run_php("array.php")); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| $bin = test_binary(pack('L*', 1, 2, 3, 4, 5)); | ||
| $result = unpack('L*', $bin); | ||
|
|
||
| assert(count($result) === 5); | ||
| assert(in_array(1, $result)); | ||
| assert(in_array(2, $result)); | ||
| assert(in_array(3, $result)); | ||
| assert(in_array(4, $result)); | ||
| assert(in_array(5, $result)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn binary_works() { | ||
| assert!(crate::integration::run_php("binary.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| assert(test_bool(true) === true); | ||
| assert(test_bool(false) === false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn bool_works() { | ||
| assert!(crate::integration::run_php("bool.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| assert(test_callable(fn (string $a) => $a, 'test') === 'test'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn callable_works() { | ||
| assert!(crate::integration::run_php("callable.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| // Tests constructor | ||
| $class = test_class('lorem ipsum', 2022); | ||
| assert($class instanceof TestClass); | ||
|
|
||
| // Tests getter/setter | ||
| assert($class->getString() === 'lorem ipsum'); | ||
| $class->setString('dolor et'); | ||
| assert($class->getString() === 'dolor et'); | ||
|
|
||
| assert($class->getNumber() === 2022); | ||
| $class->setNumber(2023); | ||
| assert($class->getNumber() === 2023); | ||
|
|
||
| // Tests #prop decorator | ||
| assert($class->boolean); | ||
| $class->boolean = false; | ||
| assert($class->boolean === false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn class_works() { | ||
| assert!(crate::integration::run_php("class.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| $v = test_closure(); | ||
|
|
||
| // Closure | ||
| assert($v('works') === 'works'); | ||
|
|
||
| // Closure once | ||
| $closure = test_closure_once('test'); | ||
|
|
||
| assert(call_user_func($closure) === 'test'); | ||
| assert_exception_thrown($closure); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn closure_works() { | ||
| assert!(crate::integration::run_php("closure.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| assert(is_null(test_nullable())); | ||
| assert(!is_null(test_nullable('value'))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn nullable_works() { | ||
| assert!(crate::integration::run_php("nullable.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| // Signed | ||
| assert(test_number_signed(-12) === -12); | ||
| assert(test_number_signed(0) === 0); | ||
| assert(test_number_signed(12) === 12); | ||
|
|
||
| // Unsigned | ||
| assert(test_number_unsigned(0) === 0); | ||
| assert(test_number_unsigned(12) === 12); | ||
| assert_exception_thrown(fn () => test_number_unsigned(-12)); | ||
|
|
||
| // Float | ||
| assert(round(test_number_float(-1.2), 2) === round(-1.2, 2)); | ||
| assert(round(test_number_float(0.0), 2) === round(0.0, 2)); | ||
| assert(round(test_number_float(1.2), 2) === round(1.2, 2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn number_works() { | ||
| assert!(crate::integration::run_php("number.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| $obj = new stdClass; | ||
| $obj->string = 'string'; | ||
| $obj->bool = true; | ||
| $obj->number = 2022; | ||
| $obj->array = [ | ||
| 1, 2, 3 | ||
| ]; | ||
|
|
||
| $test = test_object($obj); | ||
|
|
||
| assert($test->string === 'string'); | ||
| assert($test->bool === true); | ||
| assert($test->number === 2022); | ||
| assert($test->array === [1, 2, 3]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn object_works() { | ||
| assert!(crate::integration::run_php("object.php")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
|
|
||
| require('_utils.php'); | ||
|
|
||
| assert(test_str('abc') === 'abc'); | ||
| assert(test_string('abc') === 'abc'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #[test] | ||
| fn string_works() { | ||
| assert!(crate::integration::run_php("string.php")); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
And idea that might work is to put together a simple macro and embed the php snippet directly into this file:
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.