Fix onNotSuccessfulTest skipping the latest query #5740
Closed
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.
... + fix SQL queries numbering in test failure output, as doctrine/dbal#2340
The bottom modification in commit 0fa136e (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
N
be 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.:N
is1
: it iterates “from0
(included) down to0
excluded”, i.e. it doesn't iterate at all!N
is10
: it iterates from9
(included) down to0
excluded, i.e. from9
down to1
;N
is35
: it iterates from34
(included) down to10
excluded, i.e. from34
down 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 doctrine/dbal@8cbb70c#diff-9997e1f6eb43e2dcdf6f284b1d49164e, before which the
DebugStack
was storing its queries at indices0
toN-1
, but since this change (more than 5 years ago) it has been storing them at indices1
toN
(and there are even tests that depend on that, for example: https://github.com/doctrine/dbal/blob/0d76c6e952bd97f2ccc9232b1e0e64cb79cf5652/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php#L22 (and also line 33) and https://github.com/doctrine/doctrine2/blob/97cc49033ee18e2ecb5803f95732ecdc6875aec0/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
-1
in the initialization of$i
(and let the>
in the condition), so as to have:N
is1
: it should iterate from1
(included) down to0
excluded, i.e.1
only;N
is10
: it should iterate from10
(included) down to0
excluded, i.e. from10
down to1
;N
is35
: it should iterate from35
(included) down to10
excluded, i.e. from35
down to11
;and lastly, the loop body should output
$i
directly 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...)