Skip to content

Commit a842364

Browse files
[feature] upgrade laravel to v8.0
- updates composer.json to use laravel 8.0 depdencies - adds factory classes for models Co-authored-by: Roshan Gautam <[email protected]>
1 parent 64596a1 commit a842364

13 files changed

+139
-81
lines changed

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.2",
19+
"php": ">=7.3",
2020
"doctrine/dbal": "^2.9",
21-
"illuminate/bus": "^7.0",
22-
"illuminate/console": "^7.0",
23-
"illuminate/contracts": "^7.0",
24-
"illuminate/database": "^7.0",
25-
"illuminate/events": "^7.0",
26-
"illuminate/notifications": "^7.0",
21+
"illuminate/bus": "^8.11",
22+
"illuminate/console": "^8.11",
23+
"illuminate/contracts": "^8.11",
24+
"illuminate/database": "^8.11",
25+
"illuminate/events": "^8.11",
26+
"illuminate/notifications": "^8.11",
2727
"laravelcollective/html": "^6.0"
2828
},
2929
"require-dev": {
3030
"mockery/mockery": "^1.0",
31-
"orchestra/database": "^5.0",
32-
"orchestra/testbench" : "^5.0",
31+
"orchestra/database": "^6.0",
32+
"orchestra/testbench" : "^6.0",
3333
"phpunit/phpunit": "^9.0"
3434
},
3535
"suggest": {
@@ -38,13 +38,14 @@
3838
"autoload": {
3939
"psr-4": {
4040
"Studio\\Totem\\": "src/",
41-
"Studio\\Totem\\Tests\\": "tests/"
41+
"Studio\\Totem\\Tests\\": "tests/",
42+
"Database\\Factories\\": "database/factories/"
4243
}
4344
},
4445
"extra": {
4546
"component": "package",
4647
"branch-alias": {
47-
"dev-7.0": "7.0.x-dev"
48+
"dev-8.0": "8.0.x-dev"
4849
},
4950
"laravel": {
5051
"providers": [

database/factories/ModelFactory.php

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Studio\Totem\Result;
7+
8+
class TotemResultFactory extends Factory
9+
{
10+
protected $model = Result::class;
11+
12+
public function definition()
13+
{
14+
return [
15+
'task_id' => $this->faker->randomDigit,
16+
'ran_at' => $this->faker->dateTimeBetween('-1 hour'),
17+
'duration' => (string) $this->faker->randomFloat(11, 0, 8000000),
18+
'result' => $this->faker->sentence,
19+
'created_at' => $this->faker->dateTimeBetween('-1 year', '-6 months'),
20+
'updated_at' => $this->faker->dateTimeBetween('-6 months'),
21+
];
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Studio\Totem\Task;
7+
8+
class TotemTaskFactory extends Factory
9+
{
10+
protected $model = Task::class;
11+
12+
public function definition()
13+
{
14+
return [
15+
'description' => $this->faker->sentence,
16+
'command' => 'Studio\Totem\Console\Commands\ListSchedule',
17+
'expression' => '* * * * *',
18+
];
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Support\Str;
7+
use Studio\Totem\User;
8+
9+
class TotemUserFactory extends Factory
10+
{
11+
protected $model = User::class;
12+
13+
public function definition()
14+
{
15+
static $password;
16+
17+
return [
18+
'name' => $this->faker->name,
19+
'email' => $this->faker->unique()->safeEmail,
20+
'password' => $password ?: $password = bcrypt('secret'),
21+
'remember_token' => Str::random(10),
22+
];
23+
}
24+
}

src/Result.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace Studio\Totem;
44

5+
use Database\Factories\TotemResultFactory;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
57
use Illuminate\Database\Query\Builder;
68
use Illuminate\Support\Facades\DB;
79

810
class Result extends TotemModel
911
{
12+
use HasFactory;
13+
1014
protected $table = 'task_results';
1115

1216
protected $fillable = [
@@ -44,4 +48,14 @@ public function getAverageRunTime(): Builder
4448
->whereColumn('task_id', TOTEM_TABLE_PREFIX.'tasks.id')
4549
->getQuery();
4650
}
51+
52+
/**
53+
* Create a new factory instance for the model.
54+
*
55+
* @return \Illuminate\Database\Eloquent\Factories\Factory
56+
*/
57+
protected static function newFactory()
58+
{
59+
return TotemResultFactory::new();
60+
}
4761
}

src/Task.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
use Carbon\Carbon;
66
use Cron\CronExpression;
7+
use Database\Factories\TotemTaskFactory;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
79
use Illuminate\Notifications\Notifiable;
810
use Illuminate\Support\Str;
911
use Studio\Totem\Traits\FrontendSortable;
1012
use Studio\Totem\Traits\HasFrequencies;
1113

1214
class Task extends TotemModel
1315
{
14-
use Notifiable, HasFrequencies, FrontendSortable;
16+
use Notifiable, HasFrequencies, FrontendSortable, HasFactory;
1517

1618
/**
1719
* The attributes that are mass assignable.
@@ -205,4 +207,14 @@ public function autoCleanup()
205207
}
206208
}
207209
}
210+
211+
/**
212+
* Create a new factory instance for the model.
213+
*
214+
* @return \Illuminate\Database\Eloquent\Factories\Factory
215+
*/
216+
protected static function newFactory()
217+
{
218+
return TotemTaskFactory::new();
219+
}
208220
}

src/User.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Studio\Totem;
44

5+
use Database\Factories\TotemUserFactory;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
57
use Illuminate\Foundation\Auth\User as Authenticatable;
68
use Illuminate\Notifications\Notifiable;
79

810
class User extends Authenticatable
911
{
10-
use Notifiable;
12+
use Notifiable, HasFactory;
1113

1214
/**
1315
* The attributes that are mass assignable.
@@ -26,4 +28,14 @@ class User extends Authenticatable
2628
protected $hidden = [
2729
'password', 'remember_token',
2830
];
31+
32+
/**
33+
* Create a new factory instance for the model.
34+
*
35+
* @return \Illuminate\Database\Eloquent\Factories\Factory
36+
*/
37+
protected static function newFactory()
38+
{
39+
return TotemUserFactory::new();
40+
}
2941
}

tests/Feature/CompileParametersTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class CompileParametersTest extends TestCase
99
{
1010
public function test_no_paramters()
1111
{
12-
$task = factory(Task::class)->create();
12+
$task = Task::factory()->create();
1313
$parameters = $task->compileParameters();
1414

1515
$this->assertEmpty($parameters);
1616
}
1717

1818
public function test_multiple_paramters()
1919
{
20-
$task = factory(Task::class)->create();
20+
$task = Task::factory()->create();
2121
$task->parameters = '--parameter-1=value --parameter-2=value --parameter-3=value';
2222
$parameters = $task->compileParameters();
2323

@@ -29,7 +29,7 @@ public function test_multiple_paramters()
2929

3030
public function test_flag_and_paramter()
3131
{
32-
$task = factory(Task::class)->create();
32+
$task = Task::factory()->create();
3333
$task->parameters = '--parameter-1=value --dry-run';
3434
$parameters = $task->compileParameters();
3535

@@ -41,7 +41,7 @@ public function test_flag_and_paramter()
4141

4242
public function test_multiple_flags()
4343
{
44-
$task = factory(Task::class)->create();
44+
$task = Task::factory()->create();
4545
$task->parameters = '--dry-run --debug --log-output';
4646
$parameters = $task->compileParameters();
4747

@@ -56,7 +56,7 @@ public function test_multiple_flags()
5656

5757
public function test_multiple_arguments()
5858
{
59-
$task = factory(Task::class)->create();
59+
$task = Task::factory()->create();
6060
$task->parameters = 'arg1 arg2 arg3';
6161
$parameters = $task->compileParameters();
6262

@@ -68,7 +68,7 @@ public function test_multiple_arguments()
6868

6969
public function test_multiple_named_arguments()
7070
{
71-
$task = factory(Task::class)->create();
71+
$task = Task::factory()->create();
7272
$task->parameters = 'arg1=name arg2=airport arg3=100';
7373
$parameters = $task->compileParameters();
7474

@@ -80,7 +80,7 @@ public function test_multiple_named_arguments()
8080

8181
public function test_multiple_mixed_arguments()
8282
{
83-
$task = factory(Task::class)->create();
83+
$task = Task::factory()->create();
8484
$task->parameters = 'arg1 arg2=test arg3=15 arg4';
8585
$parameters = $task->compileParameters();
8686

@@ -93,7 +93,7 @@ public function test_multiple_mixed_arguments()
9393

9494
public function test_all_mixed_arguments()
9595
{
96-
$task = factory(Task::class)->create();
96+
$task = Task::factory()->create();
9797
$task->parameters = 'arg1 arg2=test arg3=15 arg4 --flag --flag2 --option=yes --someplace=warm';
9898
$parameters = $task->compileParameters();
9999

@@ -110,7 +110,7 @@ public function test_all_mixed_arguments()
110110

111111
public function test_all_mixed_arguments_console()
112112
{
113-
$task = factory(Task::class)->create();
113+
$task = Task::factory()->create();
114114
$task->parameters = 'arg1 arg2=test arg3=15 arg4 --flag --flag2 --option=yes --someplace=warm';
115115
$parameters = $task->compileParameters(true);
116116

@@ -127,7 +127,7 @@ public function test_all_mixed_arguments_console()
127127

128128
public function test_single_dash()
129129
{
130-
$task = factory(Task::class)->create();
130+
$task = Task::factory()->create();
131131
$task->parameters = '-osTeSt';
132132
$parameters = $task->compileParameters(true);
133133

@@ -137,7 +137,7 @@ public function test_single_dash()
137137

138138
public function test_array_argument()
139139
{
140-
$task = factory(Task::class)->create();
140+
$task = Task::factory()->create();
141141
$task->parameters = '--id=1 --id=2';
142142
$parameters = $task->compileParameters(true);
143143

tests/Feature/EditTaskTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class EditTaskTest extends TestCase
1111
public function user_can_view_edit_task_form()
1212
{
1313
$this->disableExceptionHandling()->signIn();
14-
$task = factory(Task::class)->create();
14+
$task = Task::factory()->create();
1515
$response = $this->get(route('totem.task.edit', $task));
1616
$response->assertStatus(200);
1717
$response->assertSee($task->description);
@@ -21,7 +21,7 @@ public function user_can_view_edit_task_form()
2121
/** @test */
2222
public function guest_can_not_view_edit_task_form()
2323
{
24-
$task = factory(Task::class)->create();
24+
$task = Task::factory()->create();
2525
$response = $this->get(route('totem.task.edit', $task));
2626
$response->assertStatus(403);
2727
}
@@ -30,7 +30,7 @@ public function guest_can_not_view_edit_task_form()
3030
public function user_can_edit_task()
3131
{
3232
$this->disableExceptionHandling()->signIn();
33-
$task = factory(Task::class)->create();
33+
$task = Task::factory()->create();
3434
$response = $this->post(route('totem.task.edit', $task), [
3535
'description' => 'List All Scheduled Commands',
3636
'command' => 'Studio\Totem\Console\Commands\ListSchedule',

0 commit comments

Comments
 (0)