From 4bcff6f6144efc0b5070b15fe280a500742dbb41 Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Wed, 13 Jul 2022 16:50:41 +0200 Subject: [PATCH] Rename create to forProvider --- src/Options.php | 2 +- tests/OptionsTest.php | 22 +++++++++---------- tests/Providers/ArrayProviderTest.php | 4 ++-- tests/Providers/AsyncModelProviderTest.php | 2 +- tests/Providers/EmptyProviderTest.php | 2 +- tests/Providers/EnumProviderTest.php | 4 ++-- tests/Providers/ModelProviderTest.php | 20 ++++++++--------- tests/Providers/MyClabsEnumProviderTest.php | 4 ++-- tests/Providers/NativeEnumProviderTest.php | 4 ++-- tests/Providers/SelectOptionsProviderTest.php | 12 +++++----- tests/Providers/SpatieEnumProviderTest.php | 2 +- tests/Providers/SpatieStateProviderTest.php | 8 +++---- 12 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/Options.php b/src/Options.php index ce14276..d214d10 100644 --- a/src/Options.php +++ b/src/Options.php @@ -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); } diff --git a/tests/OptionsTest.php b/tests/OptionsTest.php index 76d0f1c..8e4af8e 100644 --- a/tests/OptionsTest.php +++ b/tests/OptionsTest.php @@ -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(); @@ -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(); @@ -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(); @@ -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, @@ -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, @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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() @@ -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(); diff --git a/tests/Providers/ArrayProviderTest.php b/tests/Providers/ArrayProviderTest.php index 51e1693..4c59be2 100644 --- a/tests/Providers/ArrayProviderTest.php +++ b/tests/Providers/ArrayProviderTest.php @@ -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', @@ -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', diff --git a/tests/Providers/AsyncModelProviderTest.php b/tests/Providers/AsyncModelProviderTest.php index f491f91..700a313 100644 --- a/tests/Providers/AsyncModelProviderTest.php +++ b/tests/Providers/AsyncModelProviderTest.php @@ -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([]); }); diff --git a/tests/Providers/EmptyProviderTest.php b/tests/Providers/EmptyProviderTest.php index d08c010..5297a4b 100644 --- a/tests/Providers/EmptyProviderTest.php +++ b/tests/Providers/EmptyProviderTest.php @@ -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([]); }); diff --git a/tests/Providers/EnumProviderTest.php b/tests/Providers/EnumProviderTest.php index 4018fe8..5d09f52 100644 --- a/tests/Providers/EnumProviderTest.php +++ b/tests/Providers/EnumProviderTest.php @@ -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'], @@ -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'], diff --git a/tests/Providers/ModelProviderTest.php b/tests/Providers/ModelProviderTest.php index cec7829..fa0dff4 100644 --- a/tests/Providers/ModelProviderTest.php +++ b/tests/Providers/ModelProviderTest.php @@ -17,7 +17,7 @@ ->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], @@ -25,7 +25,7 @@ }); 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], @@ -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(); @@ -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(); @@ -61,7 +61,7 @@ }); 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], @@ -69,7 +69,7 @@ }); 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], @@ -77,7 +77,7 @@ }); it('can use another field as label', function () { - $options = Options::create(new ModelProvider( + $options = Options::forProvider(new ModelProvider( Character::first(), label: 'kind', ))->toArray(); @@ -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(); @@ -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(); @@ -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(); diff --git a/tests/Providers/MyClabsEnumProviderTest.php b/tests/Providers/MyClabsEnumProviderTest.php index 0e5cc38..4872c46 100644 --- a/tests/Providers/MyClabsEnumProviderTest.php +++ b/tests/Providers/MyClabsEnumProviderTest.php @@ -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'], @@ -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'], diff --git a/tests/Providers/NativeEnumProviderTest.php b/tests/Providers/NativeEnumProviderTest.php index ce9187c..c97c513 100644 --- a/tests/Providers/NativeEnumProviderTest.php +++ b/tests/Providers/NativeEnumProviderTest.php @@ -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'], @@ -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], diff --git a/tests/Providers/SelectOptionsProviderTest.php b/tests/Providers/SelectOptionsProviderTest.php index 3c7a42b..8520ff5 100644 --- a/tests/Providers/SelectOptionsProviderTest.php +++ b/tests/Providers/SelectOptionsProviderTest.php @@ -6,7 +6,7 @@ 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'], @@ -14,7 +14,7 @@ }); 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'), @@ -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'), @@ -46,7 +46,7 @@ }); 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'], @@ -54,7 +54,7 @@ }); 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'), @@ -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'), diff --git a/tests/Providers/SpatieEnumProviderTest.php b/tests/Providers/SpatieEnumProviderTest.php index c46b78a..28adf39 100644 --- a/tests/Providers/SpatieEnumProviderTest.php +++ b/tests/Providers/SpatieEnumProviderTest.php @@ -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'], diff --git a/tests/Providers/SpatieStateProviderTest.php b/tests/Providers/SpatieStateProviderTest.php index 58b147b..3f96d30 100644 --- a/tests/Providers/SpatieStateProviderTest.php +++ b/tests/Providers/SpatieStateProviderTest.php @@ -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'], @@ -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'], @@ -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'], @@ -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();