Skip to content

Commit

Permalink
Use Faker methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Nov 25, 2023
1 parent 46a2db9 commit 6d1bcf6
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 103 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"illuminate/console": "^10.0",
"illuminate/filesystem": "^10.0",
"illuminate/support": "^10.0",
"laravel-shift/faker-registry": "^0.2.0",
"laravel-shift/faker-registry": "^0.3.0",
"symfony/yaml": "^6.2"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Generators/FactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ protected function buildDefinition(Model $model): string
$faker = FakerRegistry::fakerData($column->name()) ?? (FakerRegistry::fakerDataType($type) ?? FakerRegistry::fakerDataType($column->dataType()));

if ($faker === null) {
$faker = 'word';
$faker = 'word()';
}

if (($faker === 'word') && (!empty($column->attributes()))) {
if ($faker === 'word()' && !empty($column->attributes())) {
$faker = sprintf("regexify('[A-Za-z0-9]{%s}')", current($column->attributes()));
}

Expand Down
46 changes: 23 additions & 23 deletions tests/fixtures/factories/all-column-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,41 @@ public function definition(): array
{
return [
'bigInteger' => $this->faker->numberBetween(-100000, 100000),
'binary' => $this->faker->sha256,
'boolean' => $this->faker->boolean,
'char' => $this->faker->randomLetter,
'binary' => $this->faker->sha256(),
'boolean' => $this->faker->boolean(),
'char' => $this->faker->randomLetter(),
'date' => $this->faker->date(),
'dateTime' => $this->faker->dateTime(),
'dateTimeTz' => $this->faker->dateTime(),
'decimal' => $this->faker->randomFloat(0, 0, 9999999999.),
'double' => $this->faker->randomFloat(0, 0, 9999999999.),
'enum' => $this->faker->randomElement(["1","2","3"]),
'float' => $this->faker->randomFloat(0, 0, 9999999999.),
'fullText' => $this->faker->text,
'geometry' => $this->faker->word,
'geometryCollection' => $this->faker->word,
'fullText' => $this->faker->text(),
'geometry' => $this->faker->word(),
'geometryCollection' => $this->faker->word(),
'integer' => $this->faker->numberBetween(-10000, 10000),
'ipAddress' => $this->faker->ipv4,
'ipAddress' => $this->faker->ipv4(),
'json' => '{}',
'jsonb' => '{}',
'lineString' => $this->faker->word,
'longText' => $this->faker->text,
'macAddress' => $this->faker->macAddress,
'lineString' => $this->faker->word(),
'longText' => $this->faker->text(),
'macAddress' => $this->faker->macAddress(),
'mediumInteger' => $this->faker->numberBetween(-10000, 10000),
'mediumText' => $this->faker->text,
'morphs_id' => $this->faker->randomDigitNotNull,
'morphs_type' => $this->faker->word,
'uuidMorphs' => $this->faker->word,
'multiLineString' => $this->faker->word,
'multiPoint' => $this->faker->word,
'multiPolygon' => $this->faker->word,
'point' => $this->faker->word,
'polygon' => $this->faker->word,
'mediumText' => $this->faker->text(),
'morphs_id' => $this->faker->randomDigitNotNull(),
'morphs_type' => $this->faker->word(),
'uuidMorphs' => $this->faker->word(),
'multiLineString' => $this->faker->word(),
'multiPoint' => $this->faker->word(),
'multiPolygon' => $this->faker->word(),
'point' => $this->faker->word(),
'polygon' => $this->faker->word(),
'rememberToken' => Str::random(10),
'set' => $this->faker->randomElement(["1","2","3"]),
'smallInteger' => $this->faker->numberBetween(-1000, 1000),
'string' => $this->faker->word,
'text' => $this->faker->text,
'string' => $this->faker->word(),
'text' => $this->faker->text(),
'time' => $this->faker->time(),
'timeTz' => $this->faker->time(),
'timestamp' => $this->faker->dateTime(),
Expand All @@ -67,8 +67,8 @@ public function definition(): array
'unsignedInteger' => $this->faker->randomNumber(),
'unsignedMediumInteger' => $this->faker->randomNumber(),
'unsignedSmallInteger' => $this->faker->randomNumber(),
'unsignedTinyInteger' => $this->faker->randomDigitNotNull,
'uuid' => $this->faker->uuid,
'unsignedTinyInteger' => $this->faker->randomDigitNotNull(),
'uuid' => $this->faker->uuid(),
'year' => $this->faker->year(),
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/model-key-constraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function definition(): array
{
return [
'user_id' => User::factory(),
'external_id' => $this->faker->word,
'external_id' => $this->faker->word(),
'sub_id' => Subscription::factory(),
'expires_at' => $this->faker->dateTime(),
'meta' => '[]',
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/factories/model-modifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function definition(): array
{
return [
'title' => $this->faker->sentence(4),
'name' => $this->faker->name,
'name' => $this->faker->name(),
'content' => $this->faker->paragraphs(3, true),
'amount' => $this->faker->randomFloat(3, 0, 999999.999),
'total' => $this->faker->randomFloat(2, 0, 99999999.99),
'overflow' => $this->faker->randomFloat(30, 0, 99999999999999999999999999999999999.999999999999999999999999999999),
'ssn' => $this->faker->ssn,
'ssn' => $this->faker->ssn(),
'role' => $this->faker->randomElement(["user","admin","owner"]),
];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/factories/nested-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name,
'password' => $this->faker->password,
'name' => $this->faker->name(),
'password' => $this->faker->password(),
];
}
}
8 changes: 4 additions & 4 deletions tests/fixtures/factories/phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class PhoneFactory extends Factory
public function definition(): array
{
return [
'label' => $this->faker->word,
'label' => $this->faker->word(),
'user_id' => User::factory(),
'phone_number' => $this->faker->phoneNumber,
'phone_number' => $this->faker->phoneNumber(),
'type' => $this->faker->randomElement(["home","cell"]),
'status' => $this->faker->randomElement(["archived","deleted"]),
'foo_id' => $this->faker->randomDigitNotNull,
'foo_type' => $this->faker->word,
'foo_id' => $this->faker->randomDigitNotNull(),
'foo_type' => $this->faker->word(),
'tag' => $this->faker->regexify('[A-Za-z0-9]{3}'),
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/post-configured.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function definition(): array
return [
'title' => $this->faker->sentence(4),
'author_id' => Author::factory(),
'author_bio' => $this->faker->text,
'author_bio' => $this->faker->text(),
'content' => $this->faker->paragraphs(3, true),
'published_at' => $this->faker->dateTime(),
'updated_at' => $this->faker->dateTime(),
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function definition(): array
return [
'title' => $this->faker->sentence(4),
'author_id' => Author::factory(),
'author_bio' => $this->faker->text,
'author_bio' => $this->faker->text(),
'content' => $this->faker->paragraphs(3, true),
'published_at' => $this->faker->dateTime(),
'updated_at' => $this->faker->dateTime(),
Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/factories/resource-statements.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name,
'email' => $this->faker->safeEmail,
'password' => $this->faker->password,
'name' => $this->faker->name(),
'email' => $this->faker->safeEmail(),
'password' => $this->faker->password(),
'remember_token' => Str::random(10),
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/team.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TeamFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name,
'name' => $this->faker->name(),
'owner_id' => User::factory(),
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/unconventional-foreign-key.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StateFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name,
'name' => $this->faker->name(),
'countries_id' => Country::factory(),
'country_code' => Country::factory()->create()->code,
'ccid' => Country::factory()->create()->ccid,
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/factories/unconventional.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TeamFactory extends Factory
public function definition(): array
{
return [
'name' => $this->faker->name,
'name' => $this->faker->name(),
'owner' => Owner::factory(),
'manager' => User::factory(),
'options' => '{}',
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/tests/pest/api-shorthand-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
);

test('store saves', function (): void {
$name = fake()->name;
$name = fake()->name();
$certificate_type = CertificateType::factory()->create();
$reference = fake()->word;
$document = fake()->word;
$reference = fake()->word();
$document = fake()->word();
$expiry_date = fake()->date();

$response = post(route('certificate.store'), [
Expand Down Expand Up @@ -78,10 +78,10 @@

test('update behaves as expected', function (): void {
$certificate = Certificate::factory()->create();
$name = fake()->name;
$name = fake()->name();
$certificate_type = CertificateType::factory()->create();
$reference = fake()->word;
$document = fake()->word;
$reference = fake()->word();
$document = fake()->word();
$expiry_date = fake()->date();

$response = put(route('certificate.update', $certificate), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
);

test('store saves and responds with', function (): void {
$status = fake()->word;
$status = fake()->word();
$amount = fake()->randomFloat(/** decimal_attributes **/);
$user = User::factory()->create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
);

test('store saves and redirects', function (): void {
$status = fake()->word;
$status = fake()->word();
$amount = fake()->randomFloat(/** decimal_attributes **/);
$user = User::factory()->create();

Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/tests/pest/certificate-pascal-case-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
);

test('store saves', function (): void {
$name = fake()->name;
$name = fake()->name();
$certificate_type = CertificateType::factory()->create();
$reference = fake()->word;
$document = fake()->word;
$reference = fake()->word();
$document = fake()->word();
$expiry_date = fake()->date();

$response = post(route('certificate.store'), [
Expand Down Expand Up @@ -78,10 +78,10 @@

test('update behaves as expected', function (): void {
$certificate = Certificate::factory()->create();
$name = fake()->name;
$name = fake()->name();
$certificate_type = CertificateType::factory()->create();
$reference = fake()->word;
$document = fake()->word;
$reference = fake()->word();
$document = fake()->word();
$expiry_date = fake()->date();

$response = put(route('certificate.update', $certificate), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
);

test('store saves', function (): void {
$name = fake()->name;
$name = fake()->name();

$response = post(route('certificate-type.store'), [
'name' => $name,
Expand Down Expand Up @@ -64,7 +64,7 @@

test('update behaves as expected', function (): void {
$certificateType = CertificateType::factory()->create();
$name = fake()->name;
$name = fake()->name();

$response = put(route('certificate-type.update', $certificateType), [
'name' => $name,
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/tests/pest/models-with-custom-namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
);

test('store saves', function (): void {
$name = fake()->name;
$image = fake()->word;
$active = fake()->boolean;
$name = fake()->name();
$image = fake()->word();
$active = fake()->boolean();

$response = post(route('category.store'), [
'name' => $name,
Expand Down Expand Up @@ -70,9 +70,9 @@

test('update behaves as expected', function (): void {
$category = Category::factory()->create();
$name = fake()->name;
$image = fake()->word;
$active = fake()->boolean;
$name = fake()->name();
$image = fake()->word();
$active = fake()->boolean();

$response = put(route('category.update', $category), [
'name' => $name,
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/tests/pest/reference-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
);

test('store saves and redirects', function (): void {
$email = fake()->safeEmail;
$password = fake()->password;
$email = fake()->safeEmail();
$password = fake()->password();

$response = post(route('user.store'), [
'email' => $email,
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/tests/pest/routes-with-pluralized-names.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
);

test('store saves', function (): void {
$name = fake()->name;
$image = fake()->word;
$active = fake()->boolean;
$name = fake()->name();
$image = fake()->word();
$active = fake()->boolean();

$response = post(route('categories.store'), [
'name' => $name,
Expand Down Expand Up @@ -70,9 +70,9 @@

test('update behaves as expected', function (): void {
$category = Category::factory()->create();
$name = fake()->name;
$image = fake()->word;
$active = fake()->boolean;
$name = fake()->name();
$image = fake()->word();
$active = fake()->boolean();

$response = put(route('categories.update', $category), [
'name' => $name,
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/tests/phpunit/api-shorthand-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function store_uses_form_request_validation(): void
#[Test]
public function store_saves(): void
{
$name = $this->faker->name;
$name = $this->faker->name();
$certificate_type = CertificateType::factory()->create();
$reference = $this->faker->word;
$document = $this->faker->word;
$reference = $this->faker->word();
$document = $this->faker->word();
$expiry_date = $this->faker->date();

$response = $this->post(route('certificate.store'), [
Expand Down Expand Up @@ -98,10 +98,10 @@ public function update_uses_form_request_validation(): void
public function update_behaves_as_expected(): void
{
$certificate = Certificate::factory()->create();
$name = $this->faker->name;
$name = $this->faker->name();
$certificate_type = CertificateType::factory()->create();
$reference = $this->faker->word;
$document = $this->faker->word;
$reference = $this->faker->word();
$document = $this->faker->word();
$expiry_date = $this->faker->date();

$response = $this->put(route('certificate.update', $certificate), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function store_uses_form_request_validation(): void
#[Test]
public function store_saves_and_responds_with(): void
{
$status = $this->faker->word;
$status = $this->faker->word();
$amount = $this->faker->randomFloat(/** decimal_attributes **/);
$user = User::factory()->create();

Expand Down
Loading

0 comments on commit 6d1bcf6

Please sign in to comment.