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

RonasIT / laravel-entity-generator / 12026977149

26 Nov 2024 08:49AM UTC coverage: 39.655% (+0.1%) from 39.537%
12026977149

Pull #108

github

web-flow
Merge ddd257d48 into 8497bb4ef
Pull Request #108: feat: skip generation for invalid stubs

33 of 75 new or added lines in 15 files covered. (44.0%)

23 existing lines in 2 files now uncovered.

391 of 986 relevant lines covered (39.66%)

1.31 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->checkStubExists('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
        ]);
×
64

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

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

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

© 2025 Coveralls, Inc