Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ae0b552
test: add repository generator test skeleton.
Dec 21, 2023
11a1c0c
Merge branch 'master' into 49-add-repository-generator-tests
Dec 21, 2023
db89113
chore: correct tests.
Dec 21, 2023
6071eda
test: add tests for repository generator.
Dec 21, 2023
f7f1b13
chore: remove fixture export.
Dec 21, 2023
4ca3368
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Dec 9, 2024
694ee92
refactor: tests
pirs1337 Dec 17, 2024
fec7db2
refactor: remove useless classes
pirs1337 Dec 18, 2024
47b57bd
Merge remote-tracking branch 'origin/master' into 49-add-repository-g…
pirs1337 Dec 18, 2024
e29f790
Merge remote-tracking branch 'origin/49-add-model-generator-tests-2' …
pirs1337 Dec 18, 2024
3f66a2f
feat: change tests
pirs1337 Dec 18, 2024
3fca4a6
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Dec 19, 2024
8a4cd74
refactor: code
pirs1337 Dec 19, 2024
ef0b6e1
Merge branch 'master' into 49-add-repository-generator-tests
DenTray Dec 23, 2024
57702c7
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Jan 10, 2025
87cc3b7
fix: conflicts
pirs1337 Jan 10, 2025
52f06a8
Merge remote-tracking branch 'origin/49-add-repository-generator-test…
pirs1337 Jan 10, 2025
e3bacf1
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Jan 10, 2025
adff8ab
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Jan 10, 2025
97931b2
feat: add tests
pirs1337 Jan 10, 2025
b9d4aa3
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 Jan 10, 2025
c0e714b
refactor: code
pirs1337 Jan 10, 2025
4943946
Merge remote-tracking branch 'origin/master' into 49-add-repository-g…
pirs1337 Jan 16, 2025
40fdcb2
refactor: tests
pirs1337 Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/FactoryGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ className: ViewException::class,
])
->setModel('Post')
->generate();

}

public function testCreateSuccess()
Expand Down
67 changes: 67 additions & 0 deletions tests/RepositoryGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace RonasIT\Support\Tests;

use RonasIT\Support\Events\SuccessCreateMessage;
use RonasIT\Support\Events\WarningEvent;
use RonasIT\Support\Exceptions\ClassNotExistsException;
use RonasIT\Support\Generators\RepositoryGenerator;
use RonasIT\Support\Tests\Support\Repository\RepositoryMockTrait;

class RepositoryGeneratorTest extends TestCase
{
use RepositoryMockTrait;

public function testModelNotExist()
{
$this->mockClass(RepositoryGenerator::class, [
$this->classExistsMethodCall(['models', 'Post'], false),
]);

$this->assertExceptionThrew(
className: ClassNotExistsException::class,
message: "Cannot create Post Model cause Post Model does not exists. "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check exception message, seems we need to throw next text

Suggested change
message: "Cannot create Post Model cause Post Model does not exists. "
message: "Cannot create PostRepository 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')
->generate();

$this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php');
}

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

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

$this->assertGeneratedFileEquals('repository.php', 'app/Repositories/PostRepository.php');

$this->assertEventPushed(
className: SuccessCreateMessage::class,
message: 'Created a new Repository: PostRepository',
);
}

public function testCreateRepositoryStubNotExist()
{
config(['entity-generator.stubs.repository' => 'incorrect_stub']);

$this->mockFilesystem();

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

$this->assertFileDoesNotExist('repository.php', 'app/Repositories/PostRepository.php');

$this->assertEventPushed(
className: WarningEvent::class,
message: 'Generation of repository has been skipped cause the view incorrect_stub from the config entity-generator.stubs.repository is not exists. Please check that config has the correct view name value.',
);
}
}
26 changes: 26 additions & 0 deletions tests/Support/Repository/RepositoryMockTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace RonasIT\Support\Tests\Support\Repository;

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

trait RepositoryMockTrait
{
use GeneratorMockTrait, MockTrait;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could GeneratorMockTrait use MockTrait directly?


public function mockFilesystem(): void
{
$structure = [
'app' => [
'Models' => [
'Post.php' => '<?php',
],
'Repositories' => [],
],
];

vfsStream::create($structure);
}
}
17 changes: 17 additions & 0 deletions tests/fixtures/RepositoryGeneratorTest/repository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Repositories;

use App\Models\Post;
use RonasIT\Support\Repositories\BaseRepository;

/**
* @property Post $model
*/
class PostRepository extends BaseRepository
{
public function __construct()
{
$this->setModel(Post::class);
}
}
Loading