├── .github └── workflows │ ├── packagist-deploy.yml │ └── tests.yml ├── .gitignore ├── Dockerfile ├── composer.json ├── docker-compose.yml ├── phpunit.xml ├── src ├── FakerLaravelServiceProvider.php └── helpers.php └── tests └── Unit ├── HelperTest.php └── TestCase.php /.github/workflows/packagist-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Packagist Deploy 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: read 13 | packages: write 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: mnavarrocarter/packagist-update@v1.0.0 18 | with: 19 | username: "GautierDele" 20 | api_token: ${{ secrets.PACKAGIST_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | php-version: [ '8.3', '8.4' ] 18 | laravel-version: [ '^10.0', '^11.0', '^12.0' ] 19 | 20 | name: Tests on PHP ${{ matrix.php-version }} 21 | 22 | steps: 23 | - name: Checkout 24 | uses: actions/checkout@v4 25 | 26 | - name: Setup PHP 27 | uses: shivammathur/setup-php@v2 28 | with: 29 | php-version: ${{ matrix.php-version }} 30 | coverage: none 31 | 32 | - name: Validate composer.json and composer.lock 33 | run: composer validate 34 | 35 | - name: Cache Composer packages 36 | id: composer-cache 37 | uses: actions/cache@v4 38 | with: 39 | path: vendor 40 | key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} 41 | restore-keys: | 42 | ${{ runner.os }}-php-${{ matrix.php-version }}- 43 | 44 | - name: Install dependencies 45 | if: steps.composer-cache.outputs.cache-hit != 'true' 46 | run: composer i --prefer-dist --no-progress 47 | 48 | - name: Run test suite 49 | run: vendor/bin/phpunit -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | .phpunit* 4 | .idea -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:latest 2 | 3 | RUN apt update 4 | RUN apt install unzip curl -y 5 | 6 | RUN curl -sS https://getcomposer.org/installer -o /usr/local/composer-setup.php 7 | 8 | RUN php /usr/local/composer-setup.php --install-dir=/usr/local/bin --filename=composer 9 | 10 | RUN rm /usr/local/composer-setup.php 11 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "xefi/faker-php-laravel", 3 | "type": "library", 4 | "description": "Faker php integration with laravel", 5 | "keywords": [ 6 | "faker", 7 | "data", 8 | "seeding", 9 | "fixtures", 10 | "laravel" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Gautier Deleglise" 16 | } 17 | ], 18 | "require": { 19 | "orchestra/testbench": "^9.0|^10.0", 20 | "php": "^8.3", 21 | "xefi/faker-php": "^1", 22 | "illuminate/support": "^11.0|^12.0", 23 | "psr/container": "^2.0" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^11" 27 | }, 28 | "autoload": { 29 | "files": [ 30 | "src/helpers.php" 31 | ], 32 | "psr-4": { 33 | "Xefi\\Faker\\Laravel\\": "src/" 34 | } 35 | }, 36 | "autoload-dev": { 37 | "psr-4": { 38 | "Xefi\\Faker\\Laravel\\Tests\\": "tests/" 39 | } 40 | }, 41 | "config": { 42 | "sort-packages": true 43 | }, 44 | "extra": { 45 | "laravel": { 46 | "providers": [ 47 | "Xefi\\Faker\\Laravel\\FakerLaravelServiceProvider" 48 | ] 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | php: 3 | build: . 4 | image: php:latest 5 | volumes: 6 | - ./:/var/www/html 7 | working_dir: /var/www/html 8 | tty: true -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | tests/Unit 13 | 14 | 15 | 16 | 17 | src 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/FakerLaravelServiceProvider.php: -------------------------------------------------------------------------------- 1 | registerServices(); 28 | } 29 | 30 | /** 31 | * Register Rest's services in the container. 32 | * 33 | * @return void 34 | */ 35 | protected function registerServices(): void 36 | { 37 | $this->app->singleton(Xefi\Faker\Faker::class, function (Application $app) { 38 | return new Xefi\Faker\Faker( 39 | Config::get('app.faker_locale') 40 | ); 41 | }); 42 | } 43 | } -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | bound('config') ? 13 | app('config')->get('app.faker_locale') 14 | : 'en_US'; 15 | } 16 | 17 | $abstract = \Xefi\Faker\Faker::class.':'.$locale; 18 | 19 | if (! app()->bound($abstract)) { 20 | app()->singleton($abstract, fn () => new \Xefi\Faker\Faker($locale)); 21 | } 22 | 23 | return app()->make($abstract); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/Unit/HelperTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(Faker::class, $faker); 13 | } 14 | 15 | public function testFakerHelperWithNullLocale() { 16 | $faker = faker(null); 17 | 18 | $this->assertEquals(null, $faker->getLocale()); 19 | } 20 | } -------------------------------------------------------------------------------- /tests/Unit/TestCase.php: -------------------------------------------------------------------------------- 1 |