Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
refs: #49
  • Loading branch information
pirs1337 committed Jan 14, 2025
1 parent db624fc commit 8442381
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/Generators/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class EntityGenerator
protected $paths = [];
protected $model;
protected $fields;
protected $relations;
protected $relations = [];
protected $crudOptions;

/**
Expand Down
8 changes: 0 additions & 8 deletions tests/ControllerGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace RonasIT\Support\Tests;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\View;
use RonasIT\Support\Events\SuccessCreateMessage;
use RonasIT\Support\Events\WarningEvent;
Expand All @@ -16,13 +15,6 @@ class ControllerGeneratorTest extends TestCase
{
use ControllerGeneratorMockTrait;

public function setUp(): void
{
parent::setUp();

Event::fake();
}

public function testControllerAlreadyExists()
{
$this->mockClass(ControllerGenerator::class, [
Expand Down
7 changes: 0 additions & 7 deletions tests/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ class FactoryGeneratorTest extends TestCase
{
use FactoryMockTrait;

public function setUp(): void
{
parent::setUp();

Event::fake();
}

public function testModelNotExists()
{
$this->assertExceptionThrew(
Expand Down
17 changes: 2 additions & 15 deletions tests/ModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
use RonasIT\Support\Exceptions\ClassNotExistsException;
use RonasIT\Support\Generators\ModelGenerator;
use RonasIT\Support\Tests\Support\Model\ModelMockTrait;
use RonasIT\Support\Traits\MockTrait;

class ModelGeneratorTest extends TestCase
{
use ModelMockTrait, MockTrait;
use ModelMockTrait;

public function testModelAlreadyExists()
{
Expand Down Expand Up @@ -69,7 +68,7 @@ public function testCreateModel()

$this->assertGeneratedFileEquals('new_model.php', 'app/Models/Post.php');
$this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/Comment.php');
$this->assertGeneratedFileEquals('user_relation_model.php', 'app/Models/User.php');
$this->assertGeneratedFileEquals('comment_relation_model.php', 'app/Models/User.php');

$this->assertEventPushed(
className: SuccessCreateMessage::class,
Expand All @@ -86,12 +85,6 @@ public function testCreateModelStubNotExist()
app(ModelGenerator::class)
->setModel('Post')
->setFields([])
->setRelations([
'hasOne' => [],
'hasMany' => [],
'belongsTo' => [],
'belongsToMany' => [],
])
->generate();

$this->assertFileDoesNotExist('app/Models/Post.php');
Expand All @@ -113,12 +106,6 @@ public function testCreateModelWithoutRelationsRelationStubNotExist()
app(ModelGenerator::class)
->setModel('Post')
->setFields([])
->setRelations([
'hasOne' => [],
'hasMany' => [],
'belongsTo' => [],
'belongsToMany' => [],
])
->generate();

$this->assertGeneratedFileEquals('new_model_without_fields_and_relations.php', 'app/Models/Post.php');
Expand Down
8 changes: 0 additions & 8 deletions tests/NovaResourceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\Support\Tests;

use Illuminate\Support\Facades\Event;
use RonasIT\Support\Events\SuccessCreateMessage;
use RonasIT\Support\Events\WarningEvent;
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
Expand All @@ -14,13 +13,6 @@ class NovaResourceGeneratorTest extends TestCase
{
use NovaResourceGeneratorMockTrait;

public function setUp(): void
{
parent::setUp();

Event::fake();
}

public function testCreateWithMissingNovaPackage()
{
$this->mockNovaServiceProviderExists(false);
Expand Down
7 changes: 0 additions & 7 deletions tests/NovaTestGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace RonasIT\Support\Tests;

use RonasIT\Support\Tests\Support\Models\WelcomeBonus;
use Illuminate\Support\Facades\Event;
use RonasIT\Support\Events\SuccessCreateMessage;
use RonasIT\Support\Events\WarningEvent;
use RonasIT\Support\Exceptions\ClassAlreadyExistsException;
Expand Down Expand Up @@ -58,8 +57,6 @@ className: ClassAlreadyExistsException::class,

public function testNovaTestStubNotExist()
{
Event::fake();

$this->mockNativeGeneratorFunctions(
$this->nativeClassExistsMethodCall([NovaServiceProvider::class, true]),
$this->nativeClassExistsMethodCall([WelcomeBonus::class, true]),
Expand Down Expand Up @@ -96,8 +93,6 @@ className: WarningEvent::class,

public function testDumpStubNotExist()
{
Event::fake();

$this->mockNovaServiceProviderExists();

$this->mockFilesystem();
Expand Down Expand Up @@ -156,8 +151,6 @@ public function testSuccess()

public function testGenerateNovaPackageNotInstall()
{
Event::fake();

$this->mockNovaServiceProviderExists(false);

app(NovaTestGenerator::class)
Expand Down
8 changes: 0 additions & 8 deletions tests/SeederGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace RonasIT\Support\Tests;

use Illuminate\Support\Facades\Event;
use RonasIT\Support\Events\WarningEvent;
use RonasIT\Support\Generators\SeederGenerator;
use RonasIT\Support\Tests\Support\SeederGeneratorMockTrait;
Expand All @@ -11,13 +10,6 @@ class SeederGeneratorTest extends TestCase
{
use SeederGeneratorMockTrait;

public function setUp(): void
{
parent::setUp();

Event::fake();
}

public function testCreateSeeder()
{
$this->mockFilesystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

use RonasIT\Support\Tests\Support\FileSystemMock;
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
use RonasIT\Support\Traits\MockTrait;

trait ControllerGeneratorMockTrait
{
use GeneratorMockTrait;
use MockTrait;

public function mockFilesystemWithoutRoutesFile(): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/Support/Factory/FactoryMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use org\bovigo\vfs\vfsStream;
use RonasIT\Support\Generators\FactoryGenerator;
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
use RonasIT\Support\Traits\MockTrait;

trait FactoryMockTrait
{
use GeneratorMockTrait, MockTrait;
use GeneratorMockTrait;

public function mockFactoryGenerator(array ...$functionCalls): void
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Support/GeneratorMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace RonasIT\Support\Tests\Support;

use Laravel\Nova\NovaServiceProvider;
use RonasIT\Support\Traits\MockTrait;

trait GeneratorMockTrait
{
use MockTrait;

public function mockNativeGeneratorFunctions(...$functionCalls): void
{
$this->mockNativeFunction('\RonasIT\Support\Generators', $functionCalls);
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/Model/ModelMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function mockFilesystem(): void
$structure = [
'app' => [
'Models' => [
'Comment.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php'),
'User.php' => file_get_contents(getcwd() . '/tests/Support/Model/RelationModelMock.php'),
'Comment.php' => file_get_contents(getcwd() . '/tests/Support/Models/WelcomeBonus.php'),
'User.php' => file_get_contents(getcwd() . '/tests/Support/Models/WelcomeBonus.php'),
],
],
];
Expand Down
10 changes: 0 additions & 10 deletions tests/Support/Model/RelationModelMock.php

This file was deleted.

4 changes: 4 additions & 0 deletions tests/Support/Models/WelcomeBonus.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public function getConnectionName(): string
'title',
'name',
];

public function some_relation()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use Mockery;
use RonasIT\Support\Tests\Support\FileSystemMock;
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
use RonasIT\Support\Traits\MockTrait;

trait NovaResourceGeneratorMockTrait
{
use GeneratorMockTrait;
use MockTrait;

public function mockFilesystem(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use Mockery;
use RonasIT\Support\Tests\Support\FileSystemMock;
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
use RonasIT\Support\Traits\MockTrait;

trait NovaTestGeneratorMockTrait
{
use GeneratorMockTrait;
use MockTrait;

public function mockNovaRequestClassCall(): void
{
Expand Down
21 changes: 18 additions & 3 deletions tests/fixtures/ModelGeneratorTest/comment_relation_model.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
<?php

namespace RonasIT\Support\Tests\Support\Model;
namespace RonasIT\Support\Tests\Support\Models;

class RelationModelMock
use Illuminate\Database\Eloquent\Model;
use RonasIT\Support\Traits\ModelTrait;

class WelcomeBonus extends Model
{
use ModelTrait;

public function getConnectionName(): string
{
return 'pgsql';
}

protected $fillable = [
'title',
'name',
];

public function some_relation()
{
}
Expand All @@ -12,4 +27,4 @@ public function post()
{
return $this->belongsTo(Post::class);
}
}
}
15 changes: 0 additions & 15 deletions tests/fixtures/ModelGeneratorTest/user_relation_model.php

This file was deleted.

0 comments on commit 8442381

Please sign in to comment.