Skip to content

Commit

Permalink
Rename create to forProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jul 13, 2022
1 parent 0032c96 commit 4bcff6f
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Options implements Arrayable, Jsonable, JsonSerializable, Stringable

protected array $pushedOptions = [];

public static function create(Provider $provider): self
public static function forProvider(Provider $provider): self
{
return new self($provider);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Spatie\LaravelOptions\Tests\Fakes\NativeEnum\StringEnum;

it('can filter options', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->filter(fn(StringEnum $enum) => $enum === StringEnum::Frodo)
->toArray();

Expand All @@ -19,7 +19,7 @@
});

it('can reject options', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->reject(fn(StringEnum $enum) => $enum === StringEnum::Frodo)
->toArray();

Expand All @@ -31,7 +31,7 @@
});

it('can sort options', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->sort(true)
->toArray();

Expand All @@ -44,7 +44,7 @@
});

it('can sort options using closure', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->sort(fn(StringEnum $enum) => match ($enum) {
StringEnum::Frodo => 4,
StringEnum::Sam => 3,
Expand Down Expand Up @@ -91,7 +91,7 @@
});

it('can add a null option', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->nullable()
->sort(fn(StringEnum $enum) => match ($enum) {
StringEnum::Frodo => 4,
Expand All @@ -111,7 +111,7 @@
});

it('will keep the null option on top when sorting', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->nullable()
->sort()
->toArray();
Expand All @@ -126,7 +126,7 @@
});

it('can append data', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->append(['movie' => 'Lord Of The Rings'])
->toArray();

Expand All @@ -139,7 +139,7 @@
});

it('can append data using closure', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->append(fn(StringEnum $enum) => ['upper' => strtoupper($enum->name)])
->toArray();

Expand All @@ -152,7 +152,7 @@
});

it('can manually add an extra option', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->push(new SelectOption('Aragon', 'aragon'))
->toArray();

Expand Down Expand Up @@ -193,7 +193,7 @@
});

it('can be turned into a laravel validation rule', function () {
$rules = Options::create(new NativeEnumProvider(StringEnum::class))->toValidationRule();
$rules = Options::forProvider(new NativeEnumProvider(StringEnum::class))->toValidationRule();

expect($rules)
->toBeArray()
Expand All @@ -202,7 +202,7 @@
});

it('can be turned into a laravel validation rule when nullable', function () {
$rules = Options::create(new NativeEnumProvider(StringEnum::class))
$rules = Options::forProvider(new NativeEnumProvider(StringEnum::class))
->nullable()
->toValidationRule();

Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/ArrayProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Spatie\LaravelOptions\Providers\ArrayProvider;

it('can create options from an array', function () {
$options = Options::create(new ArrayProvider([
$options = Options::forProvider(new ArrayProvider([
'frodo' => 'Frodo',
'sam' => 'Sam',
'merry' => 'Merry',
Expand All @@ -20,7 +20,7 @@
});

it('can create options from an array without keys', function () {
$options = Options::create(new ArrayProvider([
$options = Options::forProvider(new ArrayProvider([
'Frodo',
'Sam',
'Merry',
Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/AsyncModelProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Spatie\LaravelOptions\Providers\AsyncModelProvider;

it('can provide null as an async model', function () {
$options = Options::create(new AsyncModelProvider(null))->toArray();
$options = Options::forProvider(new AsyncModelProvider(null))->toArray();

expect($options)->toBeArray()->toBe([]);
});
2 changes: 1 addition & 1 deletion tests/Providers/EmptyProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Spatie\LaravelOptions\Providers\EmptyProvider;

it('can have empty options', function () {
$options = Options::create(new EmptyProvider())->toArray();
$options = Options::forProvider(new EmptyProvider())->toArray();

expect($options)->toBeArray()->toBe([]);
});
4 changes: 2 additions & 2 deletions tests/Providers/EnumProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\LaravelOptions\Tests\Fakes\NativeEnum\StringEnumWithLabels;

it('can create labels from a label function', function () {
$options = Options::create(new NativeEnumProvider(StringEnumWithLabels::class))->toArray();
$options = Options::forProvider(new NativeEnumProvider(StringEnumWithLabels::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo Baggins', 'value' => 'frodo'],
Expand All @@ -18,7 +18,7 @@


it('can create labels from a label closure', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class, fn (StringEnum $enum) => $enum->name. ' Hobbit'))->toArray();
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class, fn (StringEnum $enum) => $enum->name. ' Hobbit'))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo Hobbit', 'value' => 'frodo'],
Expand Down
20 changes: 10 additions & 10 deletions tests/Providers/ModelProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
->create());

it('can create options from a model', function () {
$options = Options::create(new ModelProvider(Character::first()))->toArray();
$options = Options::forProvider(new ModelProvider(Character::first()))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 1],
]);
});

it('can create options from a model kind', function () {
$options = Options::create(new ModelProvider(Character::class))->toArray();
$options = Options::forProvider(new ModelProvider(Character::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 1],
Expand All @@ -37,7 +37,7 @@
});

it('can create options from an array of models', function () {
$options = Options::create(new ModelProvider([
$options = Options::forProvider(new ModelProvider([
Character::find(1),
Character::find(2),
]))->toArray();
Expand All @@ -49,7 +49,7 @@
});

it('can create options from a collection of models', function () {
$options = Options::create(new ModelProvider(collect([
$options = Options::forProvider(new ModelProvider(collect([
Character::find(1),
Character::find(2),
])))->toArray();
Expand All @@ -61,23 +61,23 @@
});

it('can create options from an eloquent collection of models', function () {
$options = Options::create(new ModelProvider(Character::query()->where('kind', 'men')->get()))->toArray();
$options = Options::forProvider(new ModelProvider(Character::query()->where('kind', 'men')->get()))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Aragon', 'value' => 5],
]);
});

it('can create options from an eloquent builder', function () {
$options = Options::create(new ModelProvider(Character::query()->where('kind', 'men')))->toArray();
$options = Options::forProvider(new ModelProvider(Character::query()->where('kind', 'men')))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Aragon', 'value' => 5],
]);
});

it('can use another field as label', function () {
$options = Options::create(new ModelProvider(
$options = Options::forProvider(new ModelProvider(
Character::first(),
label: 'kind',
))->toArray();
Expand All @@ -88,7 +88,7 @@
});

it('can use a closure as label', function () {
$options = Options::create(new ModelProvider(
$options = Options::forProvider(new ModelProvider(
Character::first(),
label: fn (Character $character) => strtoupper($character->name),
))->toArray();
Expand All @@ -99,7 +99,7 @@
});

it('can use another field as value', function () {
$options = Options::create(new ModelProvider(
$options = Options::forProvider(new ModelProvider(
Character::first(),
value: 'kind',
))->toArray();
Expand All @@ -110,7 +110,7 @@
});

it('can use a closure as value', function () {
$options = Options::create(new ModelProvider(
$options = Options::forProvider(new ModelProvider(
Character::first(),
value: fn (Character $character) => md5($character->name),
))->toArray();
Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/MyClabsEnumProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\LaravelOptions\Tests\Fakes\MyclabsEnum\MyClabsEnumHumanLabels;

it('can create options from a myclabs enum', function () {
$options = Options::create(new MyClabsEnumProvider(MyClabsEnum::class))->toArray();
$options = Options::forProvider(new MyClabsEnumProvider(MyClabsEnum::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
Expand All @@ -17,7 +17,7 @@
});

it('will humanize a myclabs enum label by default', function () {
$options = Options::create(new MyClabsEnumProvider(MyClabsEnumHumanLabels::class))->toArray();
$options = Options::forProvider(new MyClabsEnumProvider(MyClabsEnumHumanLabels::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
Expand Down
4 changes: 2 additions & 2 deletions tests/Providers/NativeEnumProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Spatie\LaravelOptions\Tests\Fakes\NativeEnum\StringEnum;

it('can create options from a string backed enum', function () {
$options = Options::create(new NativeEnumProvider(StringEnum::class))->toArray();
$options = Options::forProvider(new NativeEnumProvider(StringEnum::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
Expand All @@ -19,7 +19,7 @@
});

it('can create options from an int backed enum', function () {
$options = Options::create(new NativeEnumProvider(IntEnum::class))->toArray();
$options = Options::forProvider(new NativeEnumProvider(IntEnum::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'One', 'value' => 1],
Expand Down
12 changes: 6 additions & 6 deletions tests/Providers/SelectOptionsProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use Spatie\LaravelOptions\Tests\Fakes\Selectable\SelectableImplementation;

it('can create options from a select option', function () {
$options = Options::create(new SelectOptionsProvider(new SelectOption('Frodo', 'frodo')))->toArray();
$options = Options::forProvider(new SelectOptionsProvider(new SelectOption('Frodo', 'frodo')))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
]);
});

it('can create options from an array of select options', function () {
$options = Options::create(new SelectOptionsProvider([
$options = Options::forProvider(new SelectOptionsProvider([
new SelectOption('Frodo', 'frodo'),
new SelectOption('Sam', 'sam'),
new SelectOption('Merry', 'merry'),
Expand All @@ -30,7 +30,7 @@
});

it('can create options from an collection of select options', function () {
$options = Options::create(new SelectOptionsProvider(collect([
$options = Options::forProvider(new SelectOptionsProvider(collect([
new SelectOption('Frodo', 'frodo'),
new SelectOption('Sam', 'sam'),
new SelectOption('Merry', 'merry'),
Expand All @@ -46,15 +46,15 @@
});

it('can create options from a selectable', function () {
$options = Options::create(new SelectOptionsProvider(new SelectableImplementation('Frodo', 'frodo')))->toArray();
$options = Options::forProvider(new SelectOptionsProvider(new SelectableImplementation('Frodo', 'frodo')))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
]);
});

it('can create options from a selectable array', function () {
$options = Options::create(new SelectOptionsProvider([
$options = Options::forProvider(new SelectOptionsProvider([
new SelectableImplementation('Frodo', 'frodo'),
new SelectableImplementation('Sam', 'sam'),
new SelectableImplementation('Merry', 'merry'),
Expand All @@ -70,7 +70,7 @@
});

it('can create options from a selectable collection', function () {
$options = Options::create(new SelectOptionsProvider(collect([
$options = Options::forProvider(new SelectOptionsProvider(collect([
new SelectableImplementation('Frodo', 'frodo'),
new SelectableImplementation('Sam', 'sam'),
new SelectableImplementation('Merry', 'merry'),
Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/SpatieEnumProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\LaravelOptions\Tests\Fakes\SpatieEnum\SpatieEnum;

it('can create options from a spatie enum', function () {
$options = Options::create(new SpatieEnumProvider(SpatieEnum::class))->toArray();
$options = Options::forProvider(new SpatieEnumProvider(SpatieEnum::class))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'Frodo', 'value' => 'frodo'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Providers/SpatieStateProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Spatie\LaravelOptions\Tests\Fakes\SpatieState\SpatieState;

it('can create options from a spatie state', function () {
$options = Options::create(new SpatieStateProvider(SpatieState::class, label: null))->toArray();
$options = Options::forProvider(new SpatieStateProvider(SpatieState::class, label: null))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'aragon', 'value' => 'aragon'],
Expand All @@ -22,7 +22,7 @@
});

it('can create options from a spatie state using a label field', function () {
$options = Options::create(new SpatieStateProvider(SpatieState::class, label: 'label'))->toArray();
$options = Options::forProvider(new SpatieStateProvider(SpatieState::class, label: 'label'))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'aragon', 'value' => 'aragon'],
Expand All @@ -34,7 +34,7 @@
});

it('can create options from a spatie state using a different label method', function () {
$options = Options::create(new SpatieStateProvider(SpatieState::class, label: 'characterLabel'))->toArray();
$options = Options::forProvider(new SpatieStateProvider(SpatieState::class, label: 'characterLabel'))->toArray();

expect($options)->toBeArray()->toBe([
['label' => 'aragon', 'value' => 'aragon'],
Expand All @@ -46,7 +46,7 @@
});

it('can create options from a spatie state using a closure', function () {
$options = Options::create(new SpatieStateProvider(
$options = Options::forProvider(new SpatieStateProvider(
SpatieState::class,
label: fn (SpatieState $state) => Str::of($state::class)->after('Spatie\LaravelOptions\Tests\Fakes\SpatieState\\')->before('State')
))->toArray();
Expand Down

0 comments on commit 4bcff6f

Please sign in to comment.