Closed
Description
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;
}