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

Version 2.0 #26

Draft
wants to merge 130 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
7d55c4c
Betterify command
aerni Apr 5, 2024
190fef8
Refactor into seperate content factories
aerni Apr 5, 2024
7a28edb
Make code more concise
aerni Apr 5, 2024
7b03221
Prettify code
aerni Apr 5, 2024
0df0d5e
Fix styling
aerni Apr 5, 2024
fbd461f
Add todo
aerni Aug 9, 2024
4b56882
wip
aerni Aug 10, 2024
c78a08c
wip
aerni Aug 15, 2024
0269c36
Fix styling
aerni Aug 15, 2024
aab8cee
Make it possible to update the definition
aerni Aug 15, 2024
ed59fd5
Correct questions
aerni Aug 15, 2024
d3e2744
Add make:seeder command
aerni Aug 16, 2024
e4681e0
Delete class
aerni Aug 16, 2024
559252f
Fix styling
aerni Aug 16, 2024
2e9d00e
Add seed command
aerni Aug 16, 2024
66ee8d2
Fix styling
aerni Aug 16, 2024
de9492f
Move method to Utils class
aerni Aug 16, 2024
dde7140
Fix styling
aerni Aug 16, 2024
d08b310
Move commands
aerni Aug 16, 2024
56ce452
Fix util
aerni Aug 16, 2024
e14e7c1
Cleanup command
aerni Aug 16, 2024
7f84548
Fix styling
aerni Aug 16, 2024
2318986
Cleanup
aerni Aug 16, 2024
96973c4
Fix styling
aerni Aug 16, 2024
04de083
Move return statement into stub
aerni Aug 16, 2024
ab5f942
Delete old files
aerni Aug 16, 2024
fbce594
Move class
aerni Aug 16, 2024
af6c591
Remove old command
aerni Aug 16, 2024
b5a00d9
Update description
aerni Aug 16, 2024
e7c892c
Delete old class
aerni Aug 16, 2024
9c41363
Set container and command
aerni Aug 21, 2024
eced32a
Make multi-word handles work
aerni Aug 21, 2024
a6a2eab
Add posibility to create seeder alongside factory
aerni Aug 21, 2024
4a9636b
Rename method
aerni Aug 23, 2024
bf84abc
Update TestCase
aerni Aug 23, 2024
bd5be5f
Require laravel/pint
aerni Aug 23, 2024
88cbd80
Run pint
aerni Aug 23, 2024
4903d67
Add faker to factory
aerni Aug 23, 2024
0d301ea
Allow overriding the model
aerni Aug 23, 2024
2fdad50
Set data in localized term
aerni Aug 23, 2024
12bfae9
The blueprint may be null to fallback to default
aerni Aug 23, 2024
b81165e
Add basic tests
aerni Aug 23, 2024
6583fc1
Fix styling
aerni Aug 23, 2024
15e9f9f
Use phpunit to run tests
aerni Aug 23, 2024
9f19879
Add makeOne()
aerni Aug 23, 2024
57c91ef
Add createOne()
aerni Aug 23, 2024
54c6b47
Add some todos
aerni Aug 23, 2024
ce51337
Add new methods
aerni Aug 23, 2024
6711a2c
Add more tests
aerni Aug 23, 2024
9299c7a
Fix styling
aerni Aug 23, 2024
fbf93a4
Add more tests
aerni Aug 23, 2024
47d4995
Reorder tests
aerni Aug 23, 2024
761b96f
Add createMany()
aerni Aug 23, 2024
d28808a
Add more tests
aerni Aug 23, 2024
7c26ea6
Require Laravel 11
aerni Aug 26, 2024
26fc7df
Fix using Laravel 11’s implementation
aerni Aug 26, 2024
c423fcc
Add more tests
aerni Aug 26, 2024
6d2aad8
Make expanded attributes and recylce work
aerni Aug 26, 2024
855f8f6
Fix styling
aerni Aug 26, 2024
118c809
Add lazy method
aerni Aug 26, 2024
52642d0
Add tests
aerni Aug 26, 2024
574d8db
Add more sequence support
aerni Aug 26, 2024
7164e29
Fix styling
aerni Aug 26, 2024
6142405
Add conditionable trait
aerni Aug 26, 2024
9b6ffd4
Add macroable trait
aerni Aug 26, 2024
4568a48
Fix styling
aerni Aug 26, 2024
c95f879
Refactor content model name determination
aerni Aug 27, 2024
3e25086
Fix styling
aerni Aug 27, 2024
e5b0101
Rename method
aerni Aug 27, 2024
e157640
Just use Laravel’s Sequence classes
aerni Aug 27, 2024
d1ed5ca
Update commands
aerni Aug 27, 2024
558c31f
Fix styling
aerni Aug 27, 2024
468f042
Fix tests
aerni Aug 27, 2024
9e50808
Fix styling
aerni Aug 27, 2024
42178ff
Betterify commands
aerni Aug 28, 2024
bb028b7
Fix styling
aerni Aug 28, 2024
c0e1389
Align seed command with Laravel’s
aerni Aug 28, 2024
c544b7a
Update description
aerni Aug 28, 2024
23430d9
Add todos
aerni Aug 28, 2024
5a8a19b
Fix styling
aerni Aug 28, 2024
c76ea55
Update comments
aerni Aug 28, 2024
5ebf501
Update commands
aerni Aug 28, 2024
374ee32
Make it work with imported fieldsets
aerni Aug 28, 2024
d35b878
Ensure ensured fields are added to definition
aerni Aug 28, 2024
29497ee
Fix styling
aerni Aug 28, 2024
1492728
Make it possible to localize content
aerni Aug 29, 2024
58cafe6
Add published state method
aerni Aug 30, 2024
6e82f85
Fix styling
aerni Aug 30, 2024
eaa1177
Fix default published state
aerni Aug 30, 2024
b3f718c
Use id() methods instead
aerni Aug 30, 2024
1db91e9
Prepare tests for multi-sites
aerni Aug 30, 2024
4514088
Fix tests. need to find another way to set faker.
aerni Aug 30, 2024
5144d77
Fix tests
aerni Aug 30, 2024
6ac80b0
Fix term localization
aerni Aug 30, 2024
e7310b7
Add localization tests
aerni Aug 30, 2024
50a1bb3
Fix styling
aerni Aug 30, 2024
5fd4b11
Add test for publish state
aerni Aug 30, 2024
59ca67f
Fix localization issue
aerni Aug 30, 2024
4ae3d1b
Make site sequence work
aerni Sep 2, 2024
7be8fdf
Use different approach for localization
aerni Sep 2, 2024
64af5b0
Fix styling
aerni Sep 2, 2024
277380b
Remove unused property
aerni Sep 2, 2024
9347328
Fix default entry site
aerni Sep 3, 2024
73dee17
Make it more readable
aerni Sep 3, 2024
480a59d
Simplify
aerni Sep 3, 2024
b0bc354
Add comment
aerni Sep 3, 2024
9f96d4e
Evaluate site when using createMany()
aerni Sep 3, 2024
1f40126
Add test for site sequence
aerni Sep 3, 2024
ee2f587
Add term sites tests
aerni Sep 3, 2024
79835e4
Add option for published sequence
aerni Sep 3, 2024
ee4813e
Better site methods
aerni Sep 7, 2024
02a577f
Simplify published state method
aerni Sep 9, 2024
00ae9c2
Fix styling
aerni Sep 9, 2024
24bbd0a
Save resources
aerni Sep 9, 2024
0a5e05c
Refactor into traits
aerni Sep 10, 2024
119894c
Simplify site evaluation
aerni Sep 10, 2024
7b4f3aa
Fix styling
aerni Sep 10, 2024
2972f59
wip
aerni Sep 11, 2024
e3b88a1
wip
aerni Sep 11, 2024
2464b35
Fix styling
aerni Sep 11, 2024
38a596f
Rename method and accept argument
aerni Sep 11, 2024
723d2af
Only evaluate site when trait is present
aerni Sep 11, 2024
ba5ffad
Add return type
aerni Sep 11, 2024
337b00f
Add basic support for creating users
aerni Sep 11, 2024
3c11767
Fix styling
aerni Sep 11, 2024
f0c8af8
Add test for user
aerni Sep 11, 2024
a6aa6bd
Update README.md
aerni Sep 11, 2024
b7ca659
Also check for user
aerni Sep 11, 2024
d985659
Add return types
aerni Sep 11, 2024
46d54f8
Fix styling
aerni Sep 11, 2024
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
7 changes: 2 additions & 5 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: [11.*, 10.*]
laravel: [11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
Expand All @@ -42,4 +39,4 @@ jobs:
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea
.phpunit.cache
.phpunit.result.cache
.php-cs-fixer.cache
.php_cs.cache
Expand Down
182 changes: 1 addition & 181 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,191 +2,11 @@

# Factory

This addon provides an easy way to quickly whip up fake data for your `Collection Entries`, `Taxonomy Terms` and `Globals` using [Faker](https://github.com/FakerPHP/Faker).

This addon features the Statamic equivalent of [Laravel model factories](https://laravel.com/docs/master/eloquent-factories#main-content).

## Installation
Install the addon using Composer:

```bash
composer require aerni/factory
```

Publish the config of the package:

```bash
php please vendor:publish --tag=factory-config
```

The following config will be published to `config/factory.php`:

```php
return [

/*
|--------------------------------------------------------------------------
| Publish Status
|--------------------------------------------------------------------------
|
| The publish status of collection entries and taxonomy terms
| created by the factory.
|
| Tip: Randomize the status by setting this to '(bool) random_int(0, 1)'.
|
*/

'published' => true,

/*
|--------------------------------------------------------------------------
| Title Fallback Settings
|--------------------------------------------------------------------------
|
| These title settings will function as a fallback to create titles for
| your collection entries and taxonomy terms, if you didn't explicitly set
| a 'title' field in the respective blueprint.
|
| 'chars': The character count of the title will be in this range.
| 'real_text': Use real english words instead of Lorem Ipsum.
|
*/

'title' => [
'chars' => [$min = 20, $max = 30],
'real_text' => true,
],

];
```

## Basic Usage

Before you go crazy whipping up fake goodies, you need to let the Factory know what fields you want it to create. You do so by defining a `factory` key on each field in your blueprint that you want to fake. The value of the key is a Faker formatter for simple fieldtypes and an array of options for advanced fieldtypes like a grid. Please consult the [Faker Documentation](https://github.com/FakerPHP/Faker) for available formatters.

This is an example blueprint for a collection of people:
```yaml
title: Person
sections:
main:
display: Main
fields:
-
handle: first_name
field:
type: text
factory: firstName
-
handle: last_name
field:
type: text
factory: lastName
-
handle: age
field:
type: number
factory: numberBetween(20, 50)
-
handle: bio
field:
type: textarea
factory: paragraph(3, true)
```

Run the factory in your terminal and follow the instructions:

```bash
php please factory
```

## Special Fieldtypes

The above example works great for basic fieldtypes. But what about Bard, Replicator, Grid and Tables? I'm glad you asked. To fake content for these "Special Fieldtypes" you need to change the blueprint according to the examples below.

### Bard & Replicator
`min_sets` defines the minimum number of sets to create.
`max_sets` defines the maximum number of sets to create.

```yaml
title: 'Bard & Replicator'
sections:
main:
display: Main
fields:
-
handle: replicator
field:
type: replicator
sets:
text:
display: Text
factory:
min_sets: 1
max_sets: 3
fields:
-
handle: text
field:
type: text
factory: word
-
handle: textarea
field:
type: textarea
factory: 'paragraph(3, true)'

```

### Grid
`min_rows` defines the minimum number of rows to create.
`max_rows` defines the maximum number of rows to create.

```yaml
title: Table
sections:
main:
display: Main
fields:
-
handle: grid
field:
type: grid
factory:
min_rows: 1
max_rows: 4
fields:
-
handle: first_name
field:
type: text
factory: firstName
-
handle: last_name
field:
type: text
factory: lastName
```

### Table
`min_rows` defines the minimum number of rows you want to create.
`max_rows` defines the maximum number of rows you want to create.
`min_cells` defines the minimum number of cells you want to create.
`max_cells` defines the maximum number of cells you want to create.
`formatter` defines the faker formatter to use.

```yaml
title: Table
sections:
main:
display: Main
fields:
-
handle: table
field:
type: table
factory:
min_rows: 1
max_rows: 3
min_cells: 3
max_cells: 5
formatter: word
```
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aerni/factory",
"description": "Quickly whip up fake content",
"description": "The Statamic equivalent of Laravel model factories",
"keywords": [
"statamic",
"factory"
Expand All @@ -18,12 +18,13 @@
"require": {
"php": "^8.1",
"fakerphp/faker": "^1.23.0",
"laravel/prompts": "^0.1.17",
"statamic/cms": "^5.0",
"stillat/primitives": "^1.4.1"
"laravel/framework": "^11.21",
"laravel/prompts": "^0.1.24",
"statamic/cms": "^5.0"
},
"require-dev": {
"orchestra/testbench": "^8.0|^9.0",
"laravel/pint": "^1.17",
"orchestra/testbench": "^9.0",
"phpunit/phpunit": "^10.0"
},
"autoload": {
Expand All @@ -41,7 +42,7 @@
},
"scripts": {
"test": "vendor/bin/phpunit",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
"format": "vendor/bin/pint"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -54,7 +55,7 @@
"extra": {
"statamic": {
"name": "Factory",
"description": "Quicly whip up fake content"
"description": "The Statamic equivalent of Laravel model factories"
},
"laravel": {
"providers": [
Expand Down
38 changes: 0 additions & 38 deletions config/factory.php

This file was deleted.

Loading