mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[PR #5740] Fix onNotSuccessfulTest skipping the latest query #9711
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/doctrine/orm/pull/5740
State: closed
Merged: No
... + fix SQL queries numbering in test failure output, as doctrine/dbal#2340
The bottom modification in commit
0fa136e369(whose effect is still there in https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/OrmFunctionalTestCase.php) was supposedly intended to output only the 25 (max) latest queries from the most recent to the oldest (rather than all the queries from the first to the latest), but it introduced a regression:let
Nbe a shorthand forcount($this->_sqlLoggerStack->queries),given that we're inside the condition that
N!=0, i.e.N>0, i.e.N>=1,the loop
for($i = N-1; $i > max(N-25, 0); $i--)iterates from
N-1(included) down tomax(N-25, 0)excluded, so e.g.:Nis1: it iterates “from0(included) down to0excluded”, i.e. it doesn't iterate at all!Nis10: it iterates from9(included) down to0excluded, i.e. from9down to1;Nis35: it iterates from34(included) down to10excluded, i.e. from34down to11;so it should rather have been iterating from
N-1(included) down tomax(N-25, 0)(included),i.e. the
>should have been>=in the loop condition.... At least until the change
8cbb70c61a (diff-9997e1f6eb43e2dcdf6f284b1d49164e), before which theDebugStackwas storing its queries at indices0toN-1, but since this change (more than 5 years ago) it has been storing them at indices1toN(and there are even tests that depend on that, for example:0d76c6e952/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php (L22)(and also line 33) and97cc49033e/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1595Test.php (L41)),so now the loop should rather iterate from
N(included) down tomax(N-25, 0)excluded,i.e. we should remove the
-1in the initialization of$i(and let the>in the condition), so as to have:Nis1: it should iterate from1(included) down to0excluded, i.e.1only;Nis10: it should iterate from10(included) down to0excluded, i.e. from10down to1;Nis35: it should iterate from35(included) down to10excluded, i.e. from35down to11;and lastly, the loop body should output
$idirectly for numbering rather than$i+1(same as PR doctrine/dbal#2340).(PS: I don't know how to write a unit-test for this fix, as it concerns the debug output for test failures...)