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

RonasIT / laravel-entity-generator / 12117052272

02 Dec 2024 10:08AM UTC coverage: 48.198% (-0.06%) from 48.253%
12117052272

push

github

web-flow
Merge pull request #113 from RonasIT/use-model-test-states-in-tests-generator

Use model test states in tests generator

0 of 2 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

428 of 888 relevant lines covered (48.2%)

1.08 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
    {
53
        $content = $this->getStub('test', [
×
54
            'entity' => $this->model,
×
55
            'databaseTableName' => $this->getTableName($this->model),
×
56
            'entities' => $this->getTableName($this->model, '-'),
×
57
            'withAuth' => $this->withAuth,
×
NEW
58
            'modelsNamespace' => $this->getOrCreateNamespace('models'),
×
NEW
59
            'hasModificationEndpoints' => !empty(array_intersect($this->crudOptions, ['C', 'U', 'D'])),
×
UNCOV
60
        ]);
×
61

62
        $testName = $this->getTestClassName();
×
63
        $createMessage = "Created a new Test: {$testName}";
×
64

65
        $this->saveClass('tests', $testName, $content);
×
66

67
        event(new SuccessCreateMessage($createMessage));
×
68
    }
69
}
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