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

Issue when try to use the create() function in the class_exists, throws an error when the documentation says the the function should not returns error just bool value. #861

Open
SystemBack opened this issue Feb 13, 2024 · 1 comment
Labels
invalid This doesn't seem right

Comments

@SystemBack
Copy link

SystemBack commented Feb 13, 2024

Summary

I am having an issue when I try to use Faker::create() in a Seeder with Phinx and PHPUnit in a docker container the error occurs in this line the error is the next:

unit-test-cli-1  | PHPUnit 10.5.5 by Sebastian Bergmann and contributors.
unit-test-cli-1  |
unit-test-cli-1  | Runtime:       PHP 8.2.15
unit-test-cli-1  | Configuration: /tests/phpunit.xml
unit-test-cli-1  |
unit-test-cli-1  |
unit-test-cli-1  |
unit-test-cli-1  |
unit-test-cli-1  | Testing: AhmTest
unit-test-cli-1  |
unit-test-cli-1  | E                                                                   1 / 1 (100%)
unit-test-cli-1  |
unit-test-cli-1  | Time: 00:00.303, Memory: 16.00 MB
unit-test-cli-1  |
unit-test-cli-1  | There was 1 error:
unit-test-cli-1  |
unit-test-cli-1  | 1) SomeTest::testInfo
unit-test-cli-1  | ParseError: syntax error, unexpected namespaced name "Faker\Provider\en_US\Barcode", expecting identifier
unit-test-cli-1  |
unit-test-cli-1  | /var/www/webdcs/vendor/fakerphp/faker/src/Faker/Factory.php:65
unit-test-cli-1  | /var/www/webdcs/vendor/fakerphp/faker/src/Faker/Factory.php:38
unit-test-cli-1  | /var/www/webdcs/vendor/fakerphp/faker/src/Faker/Factory.php:23
unit-test-cli-1  | /var/www/webdcs/db/seeds/SomeSeeder.php:38
unit-test-cli-1  | /var/www/webdcs/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php:147
unit-test-cli-1  | /var/www/webdcs/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php:421
unit-test-cli-1  | /var/www/webdcs/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php:619
unit-test-cli-1  | /tests/unit/includes/SomeTest.php:175
unit-test-cli-1  |
unit-test-cli-1  | ERRORS!
unit-test-cli-1  | Tests: 1, Assertions: 0, Errors: 1, Warnings: 2, Deprecations: 1.

Versions

Version
PHP 8.2.15
fakerphp/faker ^1.23
PPHPUnit 10.5.5
robmorgan/phinx ^0.16.0

Self-enclosed code snippet for reproduction

# replace this with a self-enclosed usage example
Faker::create();

Expected output

Create a new faker but instead of that the library throws an error in a core function.

Actual output

I put the output in the summary

I think that is so strange error but we can manage this situation in different ways some that I suggest is to put the logic inside of a try/catch, since this error from POV is not part of the library, like this example.

    protected static function findProviderClassname($provider, $locale = '')
    {
        $providerClass = 'Faker\\' . ($locale ? sprintf('Provider\%s\%s', $locale, $provider) : sprintf('Provider\%s', $provider));

        try {
          if (class_exists($providerClass, true)) {
              return $providerClass;
          }
        } catch(\Exception $e) {
          return null;
        }

        return null;
    }
@pimjansen
Copy link

pimjansen commented Feb 14, 2024

No idea about phinx but is there are reproduction step? How is the lib autoloaded etc?

@pimjansen pimjansen added the invalid This doesn't seem right label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants