-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
laravel 11 + remove legacy factories
- Loading branch information
Showing
29 changed files
with
420 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ composer.lock | |
.env.php | ||
.env | ||
.phpunit.result.cache | ||
.DS_Store | ||
.DS_Store | ||
phpunit.xml.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,25 @@ | |
"email": "[email protected]" | ||
}], | ||
"require": { | ||
"php": "^8.0|^8.1|^8.2", | ||
"laravel/framework": "^8.0|^9.0|^10.0", | ||
"php": "^8.0|^8.1|^8.2|^8.3", | ||
"laravel/framework": "^8.0|^9.0|^10.0|^11.0", | ||
"nesbot/carbon": "^2.0", | ||
"maatwebsite/excel": "^3.1", | ||
"ext-zip": "*", | ||
"laravel/legacy-factories": "^1.1" | ||
"ext-zip": "*" | ||
}, | ||
"require-dev": { | ||
"fakerphp/faker": "^1.19.0", | ||
"mockery/mockery": "^1.3.0", | ||
"phpunit/phpunit": "^9.5", | ||
"phpunit/phpunit": "^10.0", | ||
"doctrine/dbal": "~2.5", | ||
"orchestra/testbench": "6.*|7.*|8.*", | ||
"orchestra/testbench": "6.*|7.*|8.*|9.*", | ||
"code16/sharp": "^8.0", | ||
"ext-json": "*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Code16\\Formoj\\": "src/" | ||
"Code16\\Formoj\\": "src/", | ||
"Code16\\Formoj\\Database\\Factories\\": "database/factories/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Code16\Formoj\Database\Factories; | ||
|
||
use Code16\Formoj\Models\Answer; | ||
use Code16\Formoj\Models\Form; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class AnswerFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Answer::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'content' => [ | ||
"field 1" => $this->faker->sentence | ||
], | ||
'form_id' => function() { | ||
return Form::factory()->create()->id; | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Code16\Formoj\Database\Factories; | ||
|
||
use Code16\Formoj\Models\Field; | ||
use Code16\Formoj\Models\Section; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Str; | ||
|
||
class FieldFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Field::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
$type = $attributes["type"] ?? $this->faker->randomElement([ | ||
\Code16\Formoj\Models\Field::TYPE_TEXT, | ||
\Code16\Formoj\Models\Field::TYPE_TEXTAREA, | ||
\Code16\Formoj\Models\Field::TYPE_SELECT, | ||
\Code16\Formoj\Models\Field::TYPE_UPLOAD, | ||
\Code16\Formoj\Models\Field::TYPE_RATING, | ||
]); | ||
|
||
$fieldAttributes = []; | ||
|
||
if($type == \Code16\Formoj\Models\Field::TYPE_SELECT) { | ||
for($i=0; $i<rand(3, 12); $i++) { | ||
$fieldAttributes["options"][] = $this->faker->word; | ||
} | ||
if($this->faker->boolean(40)) { | ||
$fieldAttributes["multiple"] = true; | ||
$fieldAttributes["max_options"] = $this->faker->boolean() ? $this->faker->numberBetween(2, 4) : null; | ||
} | ||
} elseif($type == \Code16\Formoj\Models\Field::TYPE_UPLOAD) { | ||
$fieldAttributes["max_size"] = 4; | ||
$fieldAttributes["accept"] = ".jpeg,.jpg,.gif,.png,.pdf"; | ||
} elseif ($type == \Code16\Formoj\Models\Field::TYPE_RATING) { | ||
$fieldAttributes["lowest_label"] = $this->faker->word; | ||
$fieldAttributes["highest_label"] = $this->faker->word; | ||
} | ||
|
||
$label = $this->faker->words(3, true); | ||
|
||
return [ | ||
'label' => $label, | ||
'identifier' => Str::slug($label,'_'), | ||
'help_text' => $this->faker->boolean(25) ? $this->faker->paragraph : null, | ||
'type' => $type, | ||
'field_attributes' => $fieldAttributes, | ||
'required' => $type == \Code16\Formoj\Models\Field::TYPE_HEADING ? false : $this->faker->boolean(40), | ||
'section_id' => function() { | ||
return Section::factory()->create()->id; | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Code16\Formoj\Database\Factories; | ||
|
||
use Code16\Formoj\Models\Form; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class FormFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Form::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
$hasPublishedDate = $this->faker->boolean(); | ||
$publishedDate = $hasPublishedDate ? $this->faker->dateTimeBetween('-10 days', '+5 days') : null; | ||
$unpublishedDate = $this->faker->boolean() | ||
? ($hasPublishedDate ? $this->faker->dateTimeBetween($publishedDate, '+15 days') : $this->faker->dateTimeBetween('-10 days', '+5 days')) | ||
: null; | ||
|
||
return [ | ||
'title' => $this->faker->words(2, true), | ||
'is_title_hidden' => $this->faker->boolean(), | ||
'description' => $this->faker->paragraph, | ||
'published_at' => $publishedDate, | ||
'unpublished_at' => $unpublishedDate, | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Code16\Formoj\Database\Factories; | ||
|
||
use Code16\Formoj\Models\Form; | ||
use Code16\Formoj\Models\Section; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SectionFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Section::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'title' => $this->faker->words(3, true), | ||
'is_title_hidden' => $this->faker->boolean(), | ||
'description' => $this->faker->paragraph, | ||
'form_id' => function() { | ||
return Form::factory()->create()->id; | ||
} | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.