Skip to content

Commit b3bc078

Browse files
committed
✨ laravel integration
0 parents  commit b3bc078

File tree

11 files changed

+234
-0
lines changed

11 files changed

+234
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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/[email protected]
18+
with:
19+
username: "GautierDele"
20+
api_token: ${{ secrets.PACKAGIST_TOKEN }}

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
19+
name: Tests on PHP ${{ matrix.php-version }}
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: ${{ matrix.php-version }}
29+
coverage: none
30+
31+
- name: Validate composer.json and composer.lock
32+
run: composer validate
33+
34+
- name: Cache Composer packages
35+
id: composer-cache
36+
uses: actions/cache@v4
37+
with:
38+
path: vendor
39+
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
40+
restore-keys: |
41+
${{ runner.os }}-php-${{ matrix.php-version }}-
42+
43+
- name: Install dependencies
44+
if: steps.composer-cache.outputs.cache-hit != 'true'
45+
run: composer i --prefer-dist --no-progress
46+
47+
- name: Run test suite
48+
run: vendor/bin/phpunit

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.lock
3+
.phpunit*
4+
.idea

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

composer.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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",
20+
"php": "^8.3",
21+
"xefi/faker-php": "^0",
22+
"illuminate/support": "^11.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+
}

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
displayDetailsOnTestsThatTriggerWarnings="true"
7+
displayDetailsOnTestsThatTriggerDeprecations="true"
8+
backupStaticProperties="true"
9+
>
10+
<testsuites>
11+
<testsuite name="Unit">
12+
<directory>tests/Unit</directory>
13+
</testsuite>
14+
</testsuites>
15+
<source>
16+
<include>
17+
<directory>src</directory>
18+
</include>
19+
</source>
20+
<php>
21+
</php>
22+
</phpunit>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Contracts\Foundation\Application;
4+
use Illuminate\Support\Facades\Config;
5+
6+
class FakerLaravelServiceProvider extends \Illuminate\Support\ServiceProvider
7+
{
8+
/**
9+
* Register the service provider.
10+
*
11+
* @return void
12+
*/
13+
public function register(): void
14+
{
15+
$this->registerServices();
16+
}
17+
18+
/**
19+
* Register Rest's services in the container.
20+
*
21+
* @return void
22+
*/
23+
protected function registerServices(): void
24+
{
25+
$this->app->singleton(Xefi\Faker\Faker::class, function (Application $app) {
26+
return new Xefi\Faker\Faker(
27+
Config::get('app.faker_locale')
28+
);
29+
});
30+
}
31+
}

src/helpers.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
if (! function_exists('faker')) {
4+
/**
5+
* Get a faker instance.
6+
*
7+
* @param string|null $locale
8+
*/
9+
function faker(string $locale = null) : \Xefi\Faker\Faker
10+
{
11+
if (app()->bound('config')) {
12+
$locale ??= app('config')->get('app.faker_locale');
13+
}
14+
15+
$locale ??= 'en_US';
16+
17+
return app()->makeWith(\Xefi\Faker\Faker::class, compact('locale'));
18+
}
19+
}

tests/Unit/HelperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Xefi\Faker\Laravel\Tests\Unit;
4+
5+
use Xefi\Faker\Faker;
6+
7+
class HelperTest extends TestCase
8+
{
9+
public function testFakerHelper() {
10+
$faker = faker();
11+
12+
$this->assertInstanceOf(Faker::class, $faker);
13+
}
14+
}

0 commit comments

Comments
 (0)