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

RonasIT / laravel-entity-generator / 12195557862

06 Dec 2024 08:33AM UTC coverage: 48.31% (+0.1%) from 48.198%
12195557862

push

github

web-flow
Merge pull request #108 from RonasIT/skip-generation-for-invalid-stubs

feat: skip generation for invalid stubs

33 of 55 new or added lines in 15 files covered. (60.0%)

1 existing line in 1 file now uncovered.

443 of 917 relevant lines covered (48.31%)

1.65 hits per line

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

0.0
/src/Generators/TestsGenerator.php
1
<?php
2

3
namespace RonasIT\Support\Generators;
4

5
use RonasIT\Support\Events\SuccessCreateMessage;
6

7
class TestsGenerator extends AbstractTestsGenerator
8
{
9
    public function getTestClassName(): string
10
    {
11
        return "{$this->model}Test";
×
12
    }
13

14
    protected function generateExistedEntityFixture()
15
    {
16
        $object = $this->getFixtureValuesList($this->model);
×
17
        $entity = Str::snake($this->model);
×
18

19
        foreach (self::FIXTURE_TYPES as $type => $modifications) {
×
20
            if ($this->isFixtureNeeded($type)) {
×
21
                foreach ($modifications as $modification) {
×
22
                    $excepts = [];
×
23
                    if ($modification === 'request') {
×
24
                        $excepts = ['id'];
×
25
                    }
26
                    $this->generateFixture("{$type}_{$entity}_{$modification}.json", Arr::except($object, $excepts));
×
27
                }
28
            }
29
        }
30
    }
31

32
    protected function isFixtureNeeded($type): bool
33
    {
34
        $firstLetter = strtoupper($type[0]);
×
35

36
        return in_array($firstLetter, $this->crudOptions);
×
37
    }
38

39
    protected function generateFixture($fixtureName, $data): void
40
    {
41
        $fixturePath = $this->getFixturesPath($fixtureName);
×
42
        $content = json_encode($data, JSON_PRETTY_PRINT);
×
43
        $fixtureRelativePath = "{$this->paths['tests']}/fixtures/{$this->getTestClassName()}/{$fixtureName}";
×
44
        $createMessage = "Created a new Test fixture on path: {$fixtureRelativePath}";
×
45

46
        file_put_contents($fixturePath, $content);
×
47

48
        event(new SuccessCreateMessage($createMessage));
×
49
    }
50

51
    protected function generateTests(): void
52
    {
NEW
53
        if (!$this->isStubExists('test')) {
×
NEW
54
            return;
×
55
        }
56

57
        $content = $this->getStub('test', [
×
58
            'entity' => $this->model,
×
59
            'databaseTableName' => $this->getTableName($this->model),
×
60
            'entities' => $this->getTableName($this->model, '-'),
×
61
            'withAuth' => $this->withAuth,
×
62
            'modelsNamespace' => $this->getOrCreateNamespace('models'),
×
63
            'hasModificationEndpoints' => !empty(array_intersect($this->crudOptions, ['C', 'U', 'D'])),
×
64
        ]);
×
65

66
        $testName = $this->getTestClassName();
×
67
        $createMessage = "Created a new Test: {$testName}";
×
68

69
        $this->saveClass('tests', $testName, $content);
×
70

71
        event(new SuccessCreateMessage($createMessage));
×
72
    }
73
}
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