Skip to content

Commit

Permalink
laravel 11 + remove legacy factories
Browse files Browse the repository at this point in the history
  • Loading branch information
smknstd committed Apr 9, 2024
1 parent a3b69d8 commit bd010b7
Show file tree
Hide file tree
Showing 29 changed files with 420 additions and 301 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@ jobs:
strategy:
matrix:
include:
- php: 8.0
env:
LARAVEL: 8.*
TESTBENCH: 6.*
- php: 8.1
env:
LARAVEL: 8.*
TESTBENCH: 6.*
- php: 8.1
env:
LARAVEL: 9.*
TESTBENCH: 7.*
- php: 8.2
env:
LARAVEL: 10.*
TESTBENCH: 8.*
- php: 8.3
env:
LARAVEL: 11.*
TESTBENCH: 9.*
env: ${{ matrix.env }}
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ composer.lock
.env.php
.env
.phpunit.result.cache
.DS_Store
.DS_Store
phpunit.xml.bak
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions database/factories/AnswerFactory.php
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;
}
];
}
}
66 changes: 66 additions & 0 deletions database/factories/FieldFactory.php
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;
}
];
}
}
38 changes: 38 additions & 0 deletions database/factories/FormFactory.php
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,
];
}
}
84 changes: 0 additions & 84 deletions database/factories/FormojFactory.php

This file was deleted.

34 changes: 34 additions & 0 deletions database/factories/SectionFactory.php
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;
}
];
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
Expand Down
3 changes: 0 additions & 3 deletions prototipoj/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Providers;

use Code16\Formoj\FormojServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -25,7 +24,5 @@ public function register()
*/
public function boot()
{
$this->app->make(Factory::class)
->load(__DIR__ . '/../../../database/factories');
}
}
3 changes: 2 additions & 1 deletion prototipoj/app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
use Notifiable;
use Notifiable, HasFactory;

/**
* The attributes that are mass assignable.
Expand Down
Loading

0 comments on commit bd010b7

Please sign in to comment.