Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Rumpel committed Oct 23, 2020
2 parents 3df40a9 + 4705972 commit ab0df8f
Show file tree
Hide file tree
Showing 27 changed files with 369 additions and 245 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: true
matrix:
php: [7.4]
laravel: [6.*, 7.*]
laravel: [8.*]
dependency-version: [prefer-stable]
include:
- laravel: 6.*
testbench: 4.*
- laravel: 7.*
testbench: 5.*
- laravel: 8.*
testbench: 6.*


name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
],
"require": {
"php": "^7.4",
"christophrumpel/laravel-command-file-picker": "^1.0",
"illuminate/support": "^6.0|^7.0",
"laravel/framework": "^6.0|^7.0",
"nikic/php-parser": "^4.3"
"christophrumpel/laravel-command-file-picker": "^1.1",
"illuminate/support": "^6.0|^7.0|^8.0",
"laravel/framework": "^6.0|^7.0|^8.0",
"nikic/php-parser": "^4.3",
"roave/better-reflection": "^4.9"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"mockery/mockery": "^1.2",
"orchestra/testbench": "^4.0|^5.0",
"phpunit/phpunit": "^8.4"
"orchestra/testbench": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "^8.4|^9.3"
},
"autoload": {
"psr-4": {
Expand All @@ -39,8 +40,9 @@
],
"psr-4": {
"Christophrumpel\\LaravelFactoriesReloaded\\Tests\\": "tests",
"ExampleApp\\": "example/app/",
"ExampleAppTests\\": "example/tests/"
"App\\": "example/app/",
"ExampleAppTests\\": "example/tests/",
"Database\\Factories\\": "database/factories/"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion config/factories-reloaded.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Will be used to find your models while generating new factories.
*/
'models_paths' => [
base_path('app'),
base_path('app/Models'),
],

/**
Expand Down
5 changes: 4 additions & 1 deletion example/app/Models/DifferentLocation/Comment.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

namespace ExampleApp\Models\DifferentLocation;
namespace App\Models\DifferentLocation;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
use HasFactory;

protected $fillable = [
'content',
];
Expand Down
5 changes: 4 additions & 1 deletion example/app/Models/Group.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

namespace ExampleApp\Models;
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Group extends Model
{
use HasFactory;

protected $fillable = [
'name',
'size',
Expand Down
5 changes: 4 additions & 1 deletion example/app/Models/Ingredient.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace ExampleApp\Models;
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Ingredient extends Model
{
use HasFactory;

protected $fillable = ['name', 'description'];
}
5 changes: 4 additions & 1 deletion example/app/Models/ModelsWithArrayState/Book.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php

namespace ExampleApp\Models\ModelsWithArrayState;
namespace App\Models\ModelsWithArrayState;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Book extends Model
{
use HasFactory;

protected $fillable = ['name'];
}
5 changes: 4 additions & 1 deletion example/app/Models/Recipe.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

namespace ExampleApp\Models;
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Recipe extends Model
{
use HasFactory;

protected $fillable = ['name', 'description', 'group_id'];

public function group(): BelongsTo
Expand Down
47 changes: 33 additions & 14 deletions example/database/factories/BookFactory.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;

use Faker\Generator as Faker;
use App\Models\ModelsWithArrayState\Book;
use Illuminate\Database\Eloquent\Factories\Factory;

$factory->define(\ExampleApp\Models\ModelsWithArrayState\Book::class, function (Faker $faker) {
return [
'name' => $faker->word,
];
});
class BookFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Book::class;

$factory->state(
\ExampleApp\Models\ModelsWithArrayState\Book::class,
'customName',
[
'name' => 'custom-name',
]
);
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return ['name' => $this->faker->word];
}

/**
* Indicate that the user is suspended.
*
* @return Factory
*/
public function customName(): Factory
{
return $this->state([
'name' => 'custom-name',
]);
}
}
34 changes: 25 additions & 9 deletions example/database/factories/GroupFactory.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;

use ExampleApp\Models\Group;
use Faker\Generator as Faker;
use App\Models\Group;
use Illuminate\Database\Eloquent\Factories\Factory;

$factory->define(Group::class, function (Faker $faker) {
return [
'name' => $faker->word,
'size' => $faker->numberBetween(1, 10),
];
});
class GroupFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Group::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word,
'size' => $this->faker->numberBetween(1, 10),
];
}
}
107 changes: 69 additions & 38 deletions example/database/factories/RecipeFactory.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,71 @@
<?php

/** @var \Illuminate\Database\Eloquent\Factory $factory */

use ExampleApp\Models\Group;
use ExampleApp\Models\Recipe;
use Faker\Generator as Faker;

$factory->define(Recipe::class, function (Faker $faker) {
return [
'name' => $faker->word,
'description' => $faker->sentence,
];
});

$factory->state(Recipe::class, 'withGroup', function () {
return [
'group_id' => factory(Group::class),
];
});

$factory->state(Recipe::class, 'withDifferentGroup', function () {
$group = factory(Group::class)->create();

return [
'group_id' => $group->id,
];
});

$factory->state(Recipe::class, 'withOneLineGroup', function () {
return ['group_id' => factory(Group::class)];
});

$factory->state(Recipe::class, 'withReturnGroupName', function () {
return ['group_name' => 'return all'];
});

$factory->state(Recipe::class, 'withSquareBracketGroupName', function () {
return ['group_name' => 'something];'];
});
namespace Database\Factories;

use App\Models\Group;
use App\Models\Recipe;
use Illuminate\Database\Eloquent\Factories\Factory;

class RecipeFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Recipe::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word,
'description' => $this->faker->sentence,
];
}

public function withGroup(): Factory
{
return $this->state([
'group_id' => Group::factory(),
]);
}

public function withDifferentGroup(): Factory
{
$group = GroupFactory::new()
->create();

return $this->state([
'group_id' => $group->id,
]);
}

public function withOneLineGroup(): Factory
{
return $this->state(['group_id' => Group::factory()]);
}

public function withReturnGroupName(): Factory
{
return $this->state(['group_name' => 'return all']);
}

public function withClosureGroupName(): Factory
{
return $this->state(function (array $attributes) {
return [
'name' => $attributes['name'] . ' New Name',
];
});
}

public function withSquareBracketGroupName(): Factory
{
return $this->state(['group_name' => 'something];']);
}
}
2 changes: 1 addition & 1 deletion example/tests/Factories/GroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace ExampleAppTests\Factories;

use App\Models\Group;
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory;
use ExampleApp\Models\Group;
use Faker\Generator;

class GroupFactory extends BaseFactory
Expand Down
2 changes: 1 addition & 1 deletion example/tests/Factories/GroupFactoryUsingFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace ExampleAppTests\Factories;

use App\Models\Group;
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory;
use ExampleApp\Models\Group;
use Faker\Generator;

class GroupFactoryUsingFaker extends BaseFactory
Expand Down
2 changes: 1 addition & 1 deletion example/tests/Factories/IngredientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace ExampleAppTests\Factories;

use App\Models\Ingredient;
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory;
use ExampleApp\Models\Ingredient;
use Faker\Generator;

class IngredientFactory extends BaseFactory
Expand Down
2 changes: 1 addition & 1 deletion example/tests/Factories/IngredientFactoryUsingClosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace ExampleAppTests\Factories;

use App\Models\Ingredient;
use Christophrumpel\LaravelFactoriesReloaded\BaseFactory;
use ExampleApp\Models\Ingredient;
use Faker\Generator;

class IngredientFactoryUsingClosure extends BaseFactory
Expand Down

0 comments on commit ab0df8f

Please sign in to comment.