• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-entity-generator / 17670553989

12 Sep 2025 09:31AM UTC coverage: 99.799% (-0.1%) from 99.898%
17670553989

Pull #193

github

web-flow
Merge c8565899f into 59bfe879c
Pull Request #193: feat: getOrCreateNamespace method refactoring

44 of 44 new or added lines in 12 files covered. (100.0%)

1 existing line in 1 file now uncovered.

993 of 995 relevant lines covered (99.8%)

7.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.56
/src/Generators/SeederGenerator.php
1
<?php
2

3
namespace RonasIT\Support\Generators;
4

5
use Illuminate\Support\Arr;
6
use RonasIT\Support\Events\SuccessCreateMessage;
7

8
class SeederGenerator extends EntityGenerator
9
{
10
    protected $seedsPath;
11
    protected $databaseSeederPath;
12

13
    public function __construct()
14
    {
15
        parent::__construct();
5✔
16

17
        $this->seedsPath = base_path(Arr::get($this->paths, 'seeders', 'database/seeders'));
5✔
18
        $this->databaseSeederPath = base_path(Arr::get($this->paths, 'database_seeder', 'database/seeders/DatabaseSeeder.php'));
5✔
19
    }
20

21
    public function generate(): void
22
    {
23
        if (!$this->isStubExists('seeder') || !$this->isStubExists('database_empty_seeder')) {
5✔
24
            return;
2✔
25
        }
26

27
        if (!file_exists($this->seedsPath)) {
3✔
28
            mkdir($this->seedsPath);
3✔
29
        }
30

31
        $this->createNamespace('seeders');
3✔
32

33
        if (!file_exists($this->databaseSeederPath)) {
3✔
34
            list($basePath, $databaseSeederDir) = extract_last_part($this->databaseSeederPath, '/');
3✔
35

36
            if (!is_dir($databaseSeederDir)) {
3✔
UNCOV
37
                mkdir($databaseSeederDir);
×
38
            }
39

40
            $this->createDatabaseSeeder();
3✔
41
        }
42

43
        $this->createEntitySeeder();
3✔
44

45
        $this->appendSeederToList();
3✔
46
    }
47

48
    protected function createDatabaseSeeder(): void
49
    {
50
        $content = "<?php\n\n" . $this->getStub('database_empty_seeder', [
3✔
51
            'namespace' => $this->getNamespace('seeders')
3✔
52
        ]);
3✔
53

54
        file_put_contents($this->databaseSeederPath, $content);
3✔
55

56
        $createMessage = "Created a new DatabaseSeeder.php on path: {$this->databaseSeederPath}";
3✔
57

58
        event(new SuccessCreateMessage($createMessage));
3✔
59
    }
60

61
    protected function createEntitySeeder(): void
62
    {
63
        $content = "<?php\n\n" . $this->getStub('seeder', [
3✔
64
            'entity' => $this->model,
3✔
65
            'relations' => $this->prepareRelations(),
3✔
66
            'namespace' => $this->getNamespace('seeders'),
3✔
67
            'factoryNamespace' => $this->getNamespace('factories'),
3✔
68
        ]) . "\n";
3✔
69

70
        $seederPath = "{$this->seedsPath}/{$this->model}Seeder.php";
3✔
71

72
        file_put_contents($seederPath, $content);
3✔
73

74
        $createMessage = "Created a new Seeder on path: {$seederPath}";
3✔
75

76
        event(new SuccessCreateMessage($createMessage));
3✔
77
    }
78

79
    protected function prepareRelations(): array
80
    {
81
        $result = [];
3✔
82

83
        foreach ($this->relations as $type => $relationsByType) {
3✔
84
            $result[$type] = [];
3✔
85

86
            foreach ($relationsByType as $relation) {
3✔
87
                $result[$type][] = class_basename($relation);
1✔
88
            }
89
        }
90

91
        return $result;
3✔
92
    }
93

94
    protected function appendSeederToList(): void
95
    {
96
        $content = file_get_contents($this->databaseSeederPath);
3✔
97

98
        $insertContent = "    \$this->call({$this->model}Seeder::class);\n    }\n}\n";
3✔
99

100
        $fixedContent = preg_replace('/\}\s*\}\s*\z/', $insertContent, $content);
3✔
101

102
        file_put_contents($this->databaseSeederPath, $fixedContent);
3✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc