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

Impossible to test php errors in phtml with PHPUnit #67

Open
rarog opened this issue Oct 13, 2020 · 1 comment
Open

Impossible to test php errors in phtml with PHPUnit #67

rarog opened this issue Oct 13, 2020 · 1 comment

Comments

@rarog
Copy link

rarog commented Oct 13, 2020

Bug Report

Q A
Version(s) 3.1.1

Summary

Currently I'm developing with php 7.4, for CLI and Apache I have set error_reporting to E_ALL, php errors during rendering of phtml

Current behavior

The deprecation notice inside whateverAction is raising exception and fails test as expected.
The deprecation notice inside whatever.phtml file rendering an exception visible in browser but it passes the test. The visible error in browser is Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /path/to/whatever.phtml on line xy

How to reproduce

  1. Use php 7.4
  2. Set up error_reporting for CLI to E_ALL in php.ini
  3. Use current PHPUnit (version shouldn't matter, I'm using 9.4.1) and use default configuration with convertDeprecationsToExceptions set to true
  4. Use following piece of code in any action and the corresponding phtml file:
if (array_key_exists('test', new \ArrayObject())) {
    // This triggers deprecated error
}

Expected behavior

While testing with this configuration the rendering of a phtml file should obey the same rules as the normal php files.

@Xerkus
Copy link
Member

Xerkus commented Dec 12, 2020

That is expected outcome depending on how your test is setup. View rendering happens after main dispatch event and outside of the controller.

Generally, any exception in view script would be intercepted and passed to render.error (MvcEvent::EVENT_RENDER_ERROR) event. Unless exception happens while already inside render.error event, at which point it will be allowed to bubble all the way up and kill the application with the unhandled exception error.

This package does not provide testing facilities, so this looks to be either a support question or a laminas-test issue.

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

No branches or pull requests

2 participants