Skip to content

Commit

Permalink
feat: change tests
Browse files Browse the repository at this point in the history
refs: #49
  • Loading branch information
pirs1337 committed Dec 18, 2024
1 parent e29f790 commit 3f66a2f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
12 changes: 5 additions & 7 deletions tests/RepositoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public function testModelDoesntExists()
{
$this->mockGeneratorForMissingModel();

$this->expectException(ClassNotExistsException::class);
$this->expectErrorMessage("Cannot create Post Model cause Post Model does not exists. "
. "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.");
$this->assertExceptionThrew(
className: ClassNotExistsException::class,
message: "Cannot create Post Model cause Post Model does not exists. "
. "Create a Post Model by himself or run command 'php artisan make:entity Post --only-model'.",
);

app(RepositoryGenerator::class)
->setModel('Post')
Expand All @@ -25,16 +27,12 @@ public function testModelDoesntExists()

public function testCreateRepository()
{
$this->mockConfigurations();
$this->mockViewsNamespace();
$this->mockFilesystem();

app(RepositoryGenerator::class)
->setModel('Post')
->generate();

$this->rollbackToDefaultBasePath();

$this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php');
}
}
26 changes: 6 additions & 20 deletions tests/Support/Repository/RepositoryMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,17 @@

use org\bovigo\vfs\vfsStream;
use RonasIT\Support\Generators\RepositoryGenerator;
use RonasIT\Support\Tests\Support\Shared\GeneratorMockTrait;
use RonasIT\Support\Tests\Support\GeneratorMockTrait;
use RonasIT\Support\Traits\MockTrait;

trait RepositoryMockTrait
{
use GeneratorMockTrait;
use GeneratorMockTrait, MockTrait;

public function mockGeneratorForMissingModel(): void
{
$this->mockClass(RepositoryGenerator::class, [
[
'method' => 'classExists',
'arguments' => ['models', 'Post'],
'result' => false
],
]);
}

public function mockConfigurations(): void
{
config([
'entity-generator.stubs.repository' => 'entity-generator::repository',
'entity-generator.paths' => [
'repositories' => 'app/Repositories',
'models' => 'app/Models',
]
$this->classExistsMethodCall(['models', 'Post'], false),
]);
}

Expand All @@ -37,9 +23,9 @@ public function mockFilesystem(): void
$structure = [
'app' => [
'Models' => [
'Post.php' => '<?php'
'Post.php' => '<?php',
],
'Repositories' => []
'Repositories' => [],
],
];

Expand Down

0 comments on commit 3f66a2f

Please sign in to comment.