Skip to content

Commit 11636ed

Browse files
authored
Refactor and Improvements (#5)
* Resolved existing test conflicts * Formatted all code * Refactored enums to support native enums in php 8.1 * Added more note tests * Improved LeadTests * Added ProjectTests * Improved doc blocks of all models * Added dockblocks to all factories
1 parent 60e622e commit 11636ed

26 files changed

+348
-316
lines changed

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.0",
19-
"spatie/laravel-enum": "^3.0",
18+
"php": "^8.1",
19+
"datomatic/enum-helper": "^1.0",
2020
"spatie/laravel-package-tools": "^1.11"
2121
},
2222
"require-dev": {
@@ -48,7 +48,11 @@
4848
"test-coverage": "vendor/bin/pest --coverage"
4949
},
5050
"config": {
51-
"sort-packages": true
51+
"sort-packages": true,
52+
"allow-plugins": {
53+
"pestphp/pest-plugin": true,
54+
"phpstan/extension-installer": true
55+
}
5256
},
5357
"extra": {
5458
"laravel": {

database/factories/LeadFactory.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,91 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadStatus;
7-
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadType;
6+
use Tepuilabs\SimpleCrm\Enums\Lead\LeadStatus;
7+
use Tepuilabs\SimpleCrm\Enums\Lead\LeadType;
88
use Tepuilabs\SimpleCrm\Models\Lead;
99

1010
class LeadFactory extends Factory
1111
{
1212
/**
13-
* {@inheritdoc}
13+
* The name of the factory's corresponding model.
14+
*
15+
* @var class-string<\Illuminate\Database\Eloquent\Model>
1416
*/
1517
protected $model = Lead::class;
1618

1719
/**
18-
* {@inheritdoc}
20+
* Define the model's default state.
21+
*
22+
* @return array
1923
*/
2024
public function definition()
2125
{
2226
return [
2327
'name' => $this->faker->name,
2428
'email' => $this->faker->email,
29+
'type' => $this->faker->randomElement(LeadType::values()),
30+
'status' => $this->faker->randomElement(LeadStatus::values()),
2531
];
2632
}
2733

28-
public function organicType(): LeadFactory
34+
/**
35+
* Indicate that the lead type is organic .
36+
*
37+
* @return \Illuminate\Database\Eloquent\Factories\Factory
38+
*/
39+
public function organicType(): Factory
2940
{
3041
return $this->state([
3142
'type' => LeadType::ORGANIC_TYPE(),
3243
]);
3344
}
3445

35-
public function userSubmittedType(): LeadFactory
46+
/**
47+
* Indicate that the lead type is submitted .
48+
*
49+
* @return \Illuminate\Database\Eloquent\Factories\Factory
50+
*/
51+
public function userSubmittedType(): Factory
3652
{
3753
return $this->state([
3854
'type' => LeadType::USER_SUBMITTED_TYPE(),
3955
]);
4056
}
4157

42-
public function leadStatus(): LeadFactory
58+
/**
59+
* Indicate that the lead status is lead.
60+
*
61+
* @return \Illuminate\Database\Eloquent\Factories\Factory
62+
*/
63+
public function leadStatus(): Factory
4364
{
4465
return $this->state([
45-
'status' => LeadStatus::LEAD_STATUS()
66+
'status' => LeadStatus::LEAD_STATUS(),
4667
]);
4768
}
4869

49-
public function prospectStatus(): LeadFactory
70+
/**
71+
* Indicate that the lead status is prospect.
72+
*
73+
* @return \Illuminate\Database\Eloquent\Factories\Factory
74+
*/
75+
public function prospectStatus(): Factory
5076
{
5177
return $this->state([
52-
'status' => LeadStatus::PROSPECT_STATUS()
78+
'status' => LeadStatus::PROSPECT_STATUS(),
5379
]);
5480
}
5581

56-
public function customerStatus(): LeadFactory
82+
/**
83+
* Indicate that the lead status is customer.
84+
*
85+
* @return \Illuminate\Database\Eloquent\Factories\Factory
86+
*/
87+
public function customerStatus(): Factory
5788
{
5889
return $this->state([
59-
'status' => LeadStatus::CUSTOMER_STATUS()
90+
'status' => LeadStatus::CUSTOMER_STATUS(),
6091
]);
6192
}
6293
}

database/factories/NoteFactory.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,65 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Tepuilabs\SimpleCrm\Models\Enums\Note\NotePriority;
7-
use Tepuilabs\SimpleCrm\Models\Lead;
6+
use Tepuilabs\SimpleCrm\Enums\Note\NotePriority;
87
use Tepuilabs\SimpleCrm\Models\Note;
9-
use Tepuilabs\SimpleCrm\Tests\Models\User;
108

119
class NoteFactory extends Factory
1210
{
1311
/**
14-
* {@inheritdoc}
12+
* The name of the factory's corresponding model.
13+
*
14+
* @var class-string<\Illuminate\Database\Eloquent\Model>
1515
*/
1616
protected $model = Note::class;
1717

1818
/**
19-
* {@inheritdoc}
19+
* Define the model's default state.
20+
*
21+
* @return array
2022
*/
2123
public function definition()
2224
{
23-
$author = User::factory()->create();
24-
$lead = Lead::factory()->create();
25-
2625
return [
27-
'title' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
28-
'body' => $this->faker->paragraphs($nb = 3, $asText = false),
29-
'lead_id' => $lead->id,
30-
'author_id' => $author->id,
31-
'author_type' => \Tepuilabs\SimpleCrm\Tests\Models\User::class,
26+
'title' => $this->faker->sentence,
27+
'body' => $this->faker->paragraph,
28+
'priority' => $this->faker->randomElement(NotePriority::values()),
3229
];
3330
}
3431

35-
public function lowPriority(): NoteFactory
32+
/**
33+
* Indicate that the note priority is low.
34+
*
35+
* @return \Illuminate\Database\Eloquent\Factories\Factory
36+
*/
37+
public function lowPriority(): Factory
3638
{
3739
return $this->state([
38-
'priority' => NotePriority::LOW_PRIORITY()
40+
'priority' => NotePriority::LOW_PRIORITY(),
3941
]);
4042
}
4143

42-
public function mediumPriority(): NoteFactory
44+
/**
45+
* Indicate that the note priority is medium.
46+
*
47+
* @return \Illuminate\Database\Eloquent\Factories\Factory
48+
*/
49+
public function mediumPriority(): Factory
4350
{
4451
return $this->state([
45-
'priority' => NotePriority::MEDIUM_PRIORITY()
52+
'priority' => NotePriority::MEDIUM_PRIORITY(),
4653
]);
4754
}
4855

49-
public function highPriority(): NoteFactory
56+
/**
57+
* Indicate that the note priority is high.
58+
*
59+
* @return \Illuminate\Database\Eloquent\Factories\Factory
60+
*/
61+
public function highPriority(): Factory
5062
{
5163
return $this->state([
52-
'priority' => NotePriority::HIGH_PRIORITY()
64+
'priority' => NotePriority::HIGH_PRIORITY(),
5365
]);
5466
}
5567
}

database/factories/ProjectFactory.php

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Illuminate\Database\Eloquent\Model;
7-
use Tepuilabs\SimpleCrm\Models\Enums\ProjectStatus;
6+
use Tepuilabs\SimpleCrm\Enums\Project\ProjectStatus;
87
use Tepuilabs\SimpleCrm\Models\Project;
98

109
class ProjectFactory extends Factory
1110
{
1211
/**
1312
* The name of the factory's corresponding model.
1413
*
15-
* @var class-string<Model>
14+
* @var class-string<\Illuminate\Database\Eloquent\Model>
1615
*/
1716
protected $model = Project::class;
1817

@@ -24,51 +23,70 @@ class ProjectFactory extends Factory
2423
public function definition(): array
2524
{
2625
return [
27-
'title' => $this->faker->jobTitle(),
28-
'description' => $this->faker->paragraphs(),
26+
'title' => $this->faker->jobTitle,
27+
'description' => $this->faker->paragraph,
2928
'deadline' => $this->faker->date(),
30-
'status' => $this->faker->randomElement([
31-
ProjectStatus::OPEN(),
32-
ProjectStatus::CANCELED(),
33-
ProjectStatus::WIP(),
34-
ProjectStatus::BLOCKED(),
35-
ProjectStatus::COMPLETED(),
36-
])
29+
'status' => $this->faker->randomElement(ProjectStatus::values()),
3730
];
3831
}
3932

40-
public function statusOpen()
33+
/**
34+
* Indicate that the project status is open.
35+
*
36+
* @return \Illuminate\Database\Eloquent\Factories\Factory
37+
*/
38+
public function statusOpen(): Factory
4139
{
4240
return $this->state([
43-
'status' => ProjectStatus::OPEN()
41+
'status' => ProjectStatus::OPEN(),
4442
]);
4543
}
4644

47-
public function statusCanceled()
45+
/**
46+
* Indicate that the project status is canceled.
47+
*
48+
* @return \Illuminate\Database\Eloquent\Factories\Factory
49+
*/
50+
public function statusCanceled(): Factory
4851
{
4952
return $this->state([
50-
'status' => ProjectStatus::CANCELED()
53+
'status' => ProjectStatus::CANCELED(),
5154
]);
5255
}
5356

54-
public function statusWip()
57+
/**
58+
* Indicate that the project status is work in progress.
59+
*
60+
* @return \Illuminate\Database\Eloquent\Factories\Factory
61+
*/
62+
public function statusWip(): Factory
5563
{
5664
return $this->state([
57-
'status' => ProjectStatus::WIP()
65+
'status' => ProjectStatus::WIP(),
5866
]);
5967
}
6068

61-
public function statusBlocked()
69+
/**
70+
* Indicate that the project status is blocked.
71+
*
72+
* @return \Illuminate\Database\Eloquent\Factories\Factory
73+
*/
74+
public function statusBlocked(): Factory
6275
{
6376
return $this->state([
64-
'status' => ProjectStatus::BLOCKED()
77+
'status' => ProjectStatus::BLOCKED(),
6578
]);
6679
}
6780

68-
public function statusCompleted()
81+
/**
82+
* Indicate that the project status is completed.
83+
*
84+
* @return \Illuminate\Database\Eloquent\Factories\Factory
85+
*/
86+
public function statusCompleted(): Factory
6987
{
7088
return $this->state([
71-
'status' => ProjectStatus::COMPLETED()
89+
'status' => ProjectStatus::COMPLETED(),
7290
]);
7391
}
7492
}

database/factories/ServiceFactory.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,29 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
use Tepuilabs\SimpleCrm\Models\Enums\StatusEnum;
6+
use Tepuilabs\SimpleCrm\Enums\StatusEnum;
77
use Tepuilabs\SimpleCrm\Models\Service;
88

99
class ServiceFactory extends Factory
1010
{
1111
/**
12-
* {@inheritdoc}
12+
* The name of the factory's corresponding model.
13+
*
14+
* @var class-string<\Illuminate\Database\Eloquent\Model>
1315
*/
1416
protected $model = Service::class;
1517

1618
/**
17-
* {@inheritdoc}
19+
* Define the model's default state.
20+
*
21+
* @return array
1822
*/
1923
public function definition(): array
2024
{
2125
return [
2226
'name' => $this->faker->sentence(6, true),
2327
'description' => $this->faker->sentence(6, true),
24-
'status' => $this->faker->randomElement([
25-
StatusEnum::PUBLISHED(),
26-
StatusEnum::DRAFT()
27-
]),
28+
'status' => $this->faker->randomElement(StatusEnum::values()),
2829
];
2930
}
3031
}

database/factories/UserFactory.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Support\Str;
75
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Support\Str;
87
use Tepuilabs\SimpleCrm\Tests\Models\User;
98

109
class UserFactory extends Factory
1110
{
1211
/**
1312
* The name of the factory's corresponding model.
1413
*
15-
* @var class-string<Model>
14+
* @var class-string<\Illuminate\Database\Eloquent\Model>
1615
*/
1716
protected $model = User::class;
1817

19-
2018
/**
2119
* Define the model's default state.
2220
*

0 commit comments

Comments
 (0)