Skip to content
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

Fix error location #882

Closed
wants to merge 1 commit into from
Closed

Fix error location #882

wants to merge 1 commit into from

Conversation

cedric-anne
Copy link
Member

In our test suite, we have a test class that extends an abstract test class, where are located test methods. When an assertion fails in this parent class, test result are mentionning an invalid location.

=> tests\units\MyClass::testMethod():
In file /path/to/tests/MyClass.php on line 0, integer() failed: integer(1) is not greater than integer(10)

This is due to backtrace filtering, that is searching for an error on the tested class file.

@cedric-anne cedric-anne marked this pull request as ready for review April 14, 2022 14:02
$line = $backtrace['line'];
}

if ($function === null && isset($backtrace['object']) === true && isset($backtrace['function']) === true && $backtrace['object'] === $asserter && $backtrace['function'] !== '__call') {
if (isset($backtrace['object']) === true && isset($backtrace['function']) === true && $backtrace['object'] === $asserter && $backtrace['function'] !== '__call') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this cannot work. Indeed debug_backtrace(false) will not provide object (I did not changed that).
If I change the call to debug_backtrace(), messages are changed to:

 > There are 2 failures:
=> tests\units\MyClass::testMethod1():
- In file /path/to/tests/MyClass.php on line 106, boolean() failed: boolean(false) is not true
+ In file /path/to/tests/MyClass.php on line 106, boolean::isTrue() failed: boolean(false) is not true
 -Expected
 +Actual
 @@ -1 +1 @@
 -bool(true)
 +bool(false)
=> tests\units\MyClass::testMethod2():
- In file /path/to/tests/MyClass.php on line 55, array() failed: array(3) has size 3, expected size 12
+ In file /path/to/tests/MyClass.php on line 55, array::hasSize() failed: array(3) has size 3, expected size 12

Should I fix this too ?

@cedric-anne cedric-anne marked this pull request as draft April 21, 2022 08:25
@cedric-anne cedric-anne closed this Jun 8, 2022
@cedric-anne cedric-anne deleted the fix/error-location branch June 8, 2022 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant