- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2k
 
fix: workaround for Faker deprecation errors in PHP 8.2 #6758
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: workaround for Faker deprecation errors in PHP 8.2 #6758
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little uneasy about the vendor-specific exception workaround. That said, we have so few dependencies, and this one is dev only. Let's see what other opinions surface.
| 
           Another case against this: it might hide errors that people would actually like to see. This is, after all, what deprecations are for. For example, did you know Faker has deprecated magic property access? I didn't until something went wrong in some code last week and I accidentally found the deprecations due to a dependency mishap, because of the way they handle them. // deprecated:
$faker->firstName;
// use:
$faker->firstName()Ref:  | 
    
| 
           The Faker deprecated magic property access error never shows in CI4 testing. The      function trigger_deprecation(string $package, string $version, string $message, ...$args): void
    {
        @trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED);
    }In PHP 7.4,  CodeIgniter4/system/Debug/Exceptions.php Lines 152 to 159 in e0779d7 
 In PHP 8, the  In both cases, E_USER_DEPRECATED error is not shown.  | 
    
          --- a/system/Debug/Exceptions.php
+++ b/system/Debug/Exceptions.php
@@ -151,7 +151,7 @@ class Exceptions
      */
     public function errorHandler(int $severity, string $message, ?string $file = null, ?int $line = null)
     {
-        if (error_reporting() & $severity) {
+        if (E_ALL & $severity) {
             throw new ErrorException($message, 0, $severity, $file, $line);
         }
 $ ./phpunit tests/system/Test/FabricatorTest.php
PHPUnit 9.5.25 #StandWithUkraine
Runtime:       PHP 8.1.11
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml
.........E...........EEEEEEEEEEEEEEEE..........                   47 / 47 (100%)
Time: 00:00.625, Memory: 18.00 MB
There were 17 errors:
1) CodeIgniter\Test\FabricatorTest::testGetFakerReturnsUsableGenerator
ErrorException: Since fakerphp/faker 1.14: Accessing property "randomDigit" is deprecated, use "randomDigit()" instead.
/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/symfony/deprecation-contracts/function.php:25
/Users/kenji/work/codeigniter/official/CodeIgniter4/vendor/fakerphp/faker/src/Faker/Generator.php:950
/Users/kenji/work/codeigniter/official/CodeIgniter4/tests/system/Test/FabricatorTest.php:123
...
ERRORS!
Tests: 47, Assertions: 32, Errors: 17. | 
    
e3d4fa1    to
    7bd1ed5      
    Compare
  
    
          
 I changed to limit only the error   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making it specific. I'm okay with this under the banner of "workaround to support 8.2", since it is actually just a deprecation upstream. Let's be sure to pull this whenever Faker updates.
Description
See #6170
Suppress the following error in PHP 8.2.
This error prevents our app and library developments to support 8.2. See #6172 (comment)
Checklist: