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

Feature: Add more data types #30

Merged
merged 24 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Code style

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
phplint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Laravel Pint
uses: aglipanci/laravel-pint-action@latest
with:
verboseMode: true
configPath: ./pint.json
onlyDirty: true

- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Fixes coding style"
17 changes: 2 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: run-tests
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
Expand All @@ -14,7 +11,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
php: [8.1, 8.2, 8.3]
php: [8.2, 8.3]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand All @@ -36,14 +33,4 @@ jobs:
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit --coverage-clover=coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: tests
name: codecov-umbrella
#yml: ./codecov.yml
fail_ci_if_error: true

run: vendor/bin/pest --coverage-clover=coverage.xml
60 changes: 41 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Faker provider for fake car data

[![Latest Stable Version](https://poser.pugx.org/pelmered/fake-car/v/stable)](https://packagist.org/packages/pelmered/fake-car)
[![Latest Unstable Version](https://poser.pugx.org/pelmered/fake-car/v/unstable)](//packagist.org/packages/pelmered/fake-car)
[![Total Downloads](https://poser.pugx.org/pelmered/fake-car/d/total)](//packagist.org/packages/pelmered/fake-car)
[![Monthly Downloads](https://poser.pugx.org/pelmered/fake-car/d/monthly)](//packagist.org/packages/pelmered/fake-car)
[![License](https://poser.pugx.org/pelmered/fake-car/license)](https://packagist.org/packages/pelmered/fake-car)
Expand All @@ -27,10 +26,11 @@ Remove the `--dev` flag if you need it in production.
1. Now requires PHP 8.1+ (previously 7.3+)
2. The provider name has changed from `Fakecar` to `FakeCar`. This will cause problems if you are on a case-sensitive filesystem, but it is strongly recommended to change this even if you are not.
3. The methods `transliterate` and `checkDigit` on the `FakeCar` provider class are now no longer publicly available (Visibility changed to private).
4. The public methods `getRandomElementsFromArray` and `getWeighted` on the `FakeCar` provider class has been moved to a helper class. Access them like this: `\Faker\Provider\FakeCarHelper::getWeighted`
4. The public methods `getRandomElementsFromArray` and `getWeighted` on the `FakeCar` provider class has been moved to a helper class. Access them like this: `\Faker\Provider\FakeCarHelper::getWeighted()`
5. The constants `EBCDIC` and `MODELYEAR` are no longer public.

3, 4 and 5 are changes to limited to undocumented features of the public API and should therefore not impact the typical use cases of this package.
3, 4 and 5 are changes limited to undocumented features of the public API,
and should therefore not impact the typical use cases of this package.

## Basic Usage

Expand All @@ -39,50 +39,72 @@ $faker = (new \Faker\Factory())::create();
$faker->addProvider(new \Faker\Provider\FakeCar($faker));


// generate matching automobile brand and model of car as a string
echo $faker->vehicle; // Volvo 740
// generate matching automobile brand and model of a car as a string
echo $faker->vehicle(); // 'Volvo 740'

// generate matching automobile brand and model of car as an array
echo $faker->vehicleArray; // [ 'brand' => 'Hummer', 'model' => 'H1' ]
// generate matching automobile brand and model of a car as an array
echo $faker->vehicleArray(); // [ 'brand' => 'Hummer', 'model' => 'H1' ]

// generate only automobile brand
echo $faker->vehicleBrand; // Ford
echo $faker->vehicleBrand(); // 'Ford'

// generate automobile manufacturer and model of car
echo $faker->vehicleModel; // 488 Spider
echo $faker->vehicleModel(); // '488 Spider'

// generate Vehicle Identification Number(VIN) - https://en.wikipedia.org/wiki/Vehicle_identification_number
echo $faker->vin; // d0vcddxpXAcz1utgz
echo $faker->vin(); // 'd0vcddxpXAcz1utgz'

// generate automobile registration number
echo $faker->vehicleRegistration; // ABC-123
echo $faker->vehicleRegistration(); // 'ABC-123'

// generate automobile registration number with custom format
echo $faker->vehicleRegistration('[A-Z]{2}-[0-9]{5}'); // AB-12345

// generate automobile model type
echo $faker->vehicleType; // hatchback
echo $faker->vehicleType(); // 'hatchback'

// generate automobile fuel type
echo $faker->vehicleFuelType; // diesel
echo $faker->vehicleFuelType(); // 'diesel'
echo $faker->vehicleFuelType(2); // ['diesel', 'gasoline']

// generate automobile door count
echo $faker->vehicleDoorCount; // 4
echo $faker->vehicleDoorCount(); // 4

// generate automobile seat count
echo $faker->vehicleSeatCount; // 5
echo $faker->vehicleSeatCount(); // 5

// generate automobile properties
echo $faker->vehicleProperties; // ['Towbar','Aircondition','GPS', 'Leather seats']
echo $faker->vehicleProperties(); // ['Towbar','Aircondition','GPS', 'Leather seats']

// generate automobile gear type (manual or automatic)
echo $faker->vehicleGearBoxType; // manual
echo $faker->vehicleGearBoxType(); // manual

// generate automobile engine power
echo $faker->vehicleEnginePower; // 250 hp
echo $faker->vehicleEnginePower(); // '250 hp'

// generate automobile engine power without a unit
echo $faker->vehicleEnginePowerValue(); // 175

// generate automobile engine torque
echo $faker->vehicleEngineTorque; // 300 nm
echo $faker->vehicleEngineTorque(); // '300 nm'

// generate automobile engine power without a unit
echo $faker->vehicleEngineTorqueValue(); // 450

// generate automobile engine displacement
echo $faker->vehicleEngineDisplacement(); // '2.0 l'

// generate automobile engine displacement without unit
echo $faker->vehicleEngineDisplacementValue(); // 2.0

// generate automobile engine fuel consumption
echo $faker->vehicleFuelConsumption(); // '5.0 l/100km'

// generate automobile engine fuel consumption without unit
echo $faker->vehicleFuelConsumptionValue(); // 5.0

// generate automobile engine fuel consumption without unit
echo $faker->vehicleEngineCylinders(); // 4
```

### Laravel factory example
Expand Down
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"fakerphp/faker": "^1.10"
},
"require-dev": {
"phpunit/phpunit": "^10.1",
"larapack/dd": "^1.1",
"brianium/paratest": "^7.1"
"pestphp/pest": "^3.0",
"pestphp/pest-plugin-drift": "3.x-dev",
"phpstan/phpstan": "^1.12",
"laravel/pint": "^1.18"
},
"autoload": {
"psr-4": {
Expand All @@ -36,11 +38,17 @@
}
},
"scripts": {
"lint": [
"composer phpstan",
"composer pint"
],
"phpstan": "vendor/bin/phpstan analyse src --level=8",
"pint": "vendor/bin/pint",
"test": [
"./vendor/bin/phpunit -c phpunit.xml"
"./vendor/bin/pest"
],
"test-coverage": [
"./vendor/bin/phpunit -c phpunit.xml --coverage-text"
"./vendor/bin/pest --coverage-text"
],
"phpmd": [
"php ./vendor/bin/phpmd src ansi ./phpmd-ruleset.xml --ignore-violations-on-exit"
Expand All @@ -59,5 +67,12 @@
"all": [
"composer run test && composer run test-coverage && composer run phpmd && composer run codemetrics"
]
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "beta",
"prefer-stable": true
}
48 changes: 22 additions & 26 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
cacheDirectory="tests/cache/.phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
<report>
<clover outputFile="coverage/clover.xml"/>
<html outputDirectory="coverage/html" lowUpperBound="50" highLowerBound="90"/>
<text outputFile="coverage/coverage.txt" showUncoveredFiles="false" />
<xml outputDirectory="coverage/xml"/>
</report>
</coverage>
failOnWarning="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
<include>
<directory>src</directory>
</include>
</source>
<coverage includeUncoveredFiles="true" pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
<report>
<clover outputFile="coverage/clover.xml"/>
<html outputDirectory="coverage/html" lowUpperBound="50" highLowerBound="90"/>
<text outputFile="coverage/coverage.txt" showUncoveredFiles="false"/>
<xml outputDirectory="coverage/xml"/>
</report>
</coverage>
</phpunit>
11 changes: 11 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"preset": "laravel",
"rules": {
"binary_operator_spaces": {
"default": "align_single_space_minimal",
"operators": {
"=>": "align_single_space_minimal"
}
}
}
}
Loading