Skip to content

Zend: Add tests for offsets and containers #12723

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 30 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c12bbd4
Zend: Add tests for offsets and containers
Girgias Nov 19, 2023
282c5bb
Add an appending test
Girgias Nov 20, 2023
f1eb4a7
Generate tests comparing compile time to runtime offset behaviour
Girgias Nov 20, 2023
35fc83a
Generate tests for invalid containers and check output
Girgias Nov 28, 2023
38087dd
Generate tests for null container and check output
Girgias Nov 29, 2023
a49c505
Use helper file
Girgias Nov 29, 2023
b490523
Generate tests for object container and check output
Girgias Nov 29, 2023
355e65b
Generate tests for false container and check output
Girgias Nov 29, 2023
f2bd69d
Generate tests for array container and check output
Girgias Nov 29, 2023
fe2e94f
Generate tests for string container and check output
Girgias Nov 29, 2023
79aa4e0
Revert run test
Girgias Nov 29, 2023
fc1a3a2
Add unset()
Girgias Dec 2, 2023
fc7aa51
Add more containers
Girgias Dec 3, 2023
a0425d5
Add more offsets
Girgias Dec 3, 2023
81fb17a
Fix string container behaviour test
Girgias Dec 3, 2023
d9ff087
Add empty array as offset in tests
Girgias Dec 10, 2023
b5bb4b8
Unify the var_export helper
Girgias Dec 10, 2023
53c32f3
Add objects as offset in tests
Girgias Dec 10, 2023
083c5e5
Add STDERR resource as offset in tests
Girgias Dec 10, 2023
b03a539
Add dimension handler internal object to zend_test
Girgias Jan 15, 2024
405d7eb
Add test demonstrating internal objects need to opt-in to supporting …
Girgias Jan 15, 2024
ab562c6
Fix wording/comments
Girgias Jan 16, 2024
7ecc1fd
Use arithmetic operation instead of concat
Girgias Jan 16, 2024
898a0ec
Add tests for nesting dimensions
Girgias Jan 16, 2024
fe0f6e5
Add test for no offset in read op
Girgias Jan 17, 2024
b766187
Address review comments
Girgias Jan 17, 2024
ff2a92a
Improve test for internal handlers
Girgias Jan 17, 2024
0ebbd7d
Add container test for ArrayAccess
Girgias Jan 18, 2024
b12bdf2
Add container test for ArrayObject
Girgias Jan 18, 2024
7daec93
Check also extended ArrayObject
Girgias Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions Zend/tests/offsets/ArrayAccess_container_offset_behaviour.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
--TEST--
ArrayAccess containers behaviour with offsets
--FILE--
<?php

require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';

const EXPECTED_OUTPUT = <<<OUTPUT
Read before write:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
int(5)
Write:
string(12) "CLASS_NAME::offsetSet"
VAR_DUMP_OF_OFFSET
int(5)
Read:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
int(5)
Read-Write:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetSet"
VAR_DUMP_OF_OFFSET
int(25)
isset():
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
bool(true)
empty():
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
bool(false)
null coalesce:
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
int(5)
unset():
string(14) "CLASS_NAME::offsetUnset"
VAR_DUMP_OF_OFFSET
Nested read:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET

Warning: Trying to access array offset on int in %s on line 62
NULL
Nested write:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET

Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 69
Cannot use a scalar value as an array
Nested Read-Write:
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET

Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 76
Cannot use a scalar value as an array
Nested isset():
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
bool(false)
Nested empty():
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
bool(true)
Nested null coalesce:
string(15) "CLASS_NAME::offsetExists"
VAR_DUMP_OF_OFFSET
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET
string(7) "default"
Nested unset():
string(12) "CLASS_NAME::offsetGet"
VAR_DUMP_OF_OFFSET

Notice: Indirect modification of overloaded element of CLASS_NAME has no effect in %s on line 102
Cannot unset offset in a non-array variable

OUTPUT;

ob_start();
foreach (['A', 'B'] as $class) {
foreach ($offsets as $dimension) {
$container = new $class();
$error = "(new $class())[" . zend_test_var_export($dimension) . '] has different outputs' . "\n";
ob_start();
var_dump($dimension);
$var_dump_output = ob_get_clean();

include $var_dim_filename;
$varOutput = ob_get_contents();
ob_clean();
$varOutput = str_replace(
[$var_dim_filename],
['%s'],
$varOutput
);

$expected_output = str_replace(
["VAR_DUMP_OF_OFFSET\n", "CLASS_NAME"],
[$var_dump_output, $class],
EXPECTED_OUTPUT
);

if ($varOutput !== $expected_output) {
file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_ArrayAccess_container_{$failuresNb}.txt", $varOutput);
++$failuresNb;
$failures[] = $error;
}
++$testCasesTotal;
}
}
ob_end_clean();

echo "Executed tests\n";
if ($failures !== []) {
echo "Failures:\n" . implode($failures);
}

?>
--EXPECT--
Executed tests
Loading