-
Notifications
You must be signed in to change notification settings - Fork 3
Add repository generator tests #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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.
11a1c0c
Merge branch 'master' into 49-add-repository-generator-tests
db89113
chore: correct tests.
6071eda
test: add tests for repository generator.
f7f1b13
chore: remove fixture export.
4ca3368
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 694ee92
refactor: tests
pirs1337 fec7db2
refactor: remove useless classes
pirs1337 47b57bd
Merge remote-tracking branch 'origin/master' into 49-add-repository-g…
pirs1337 e29f790
Merge remote-tracking branch 'origin/49-add-model-generator-tests-2' …
pirs1337 3f66a2f
feat: change tests
pirs1337 3fca4a6
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 8a4cd74
refactor: code
pirs1337 ef0b6e1
Merge branch 'master' into 49-add-repository-generator-tests
DenTray 57702c7
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 87cc3b7
fix: conflicts
pirs1337 52f06a8
Merge remote-tracking branch 'origin/49-add-repository-generator-test…
pirs1337 e3bacf1
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 adff8ab
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 97931b2
feat: add tests
pirs1337 b9d4aa3
Merge remote-tracking branch 'origin/49-add-model-generator-tests' in…
pirs1337 c0e714b
refactor: code
pirs1337 4943946
Merge remote-tracking branch 'origin/master' into 49-add-repository-g…
pirs1337 40fdcb2
refactor: tests
pirs1337 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. " | ||
| . "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.', | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
||
|
|
||
| public function mockFilesystem(): void | ||
| { | ||
| $structure = [ | ||
| 'app' => [ | ||
| 'Models' => [ | ||
| 'Post.php' => '<?php', | ||
| ], | ||
| 'Repositories' => [], | ||
| ], | ||
| ]; | ||
|
|
||
| vfsStream::create($structure); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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