-
Notifications
You must be signed in to change notification settings - Fork 3
[203]: add model relations property annotations #208
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
Changes from 8 commits
9b5e4b4
8b1a21e
4f8a534
48d2b8c
63a88a9
5e293d2
c928e1b
c3c6115
caf1c8c
484b184
21dd8aa
569c284
21ef6ff
69628d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,14 @@ | |
| @if($hasCarbonField) | ||
| use Carbon\Carbon; | ||
| @endif | ||
| @if($hasCollectionType) | ||
| use Illuminate\Database\Eloquent\Collection; | ||
| @endif | ||
|
|
||
| @if(!empty($anotationProperties)) | ||
| @if(!empty($annotationProperties)) | ||
| /** | ||
| @foreach($anotationProperties as $key => $value) | ||
| * @property {{ $value }} ${{ $key }} | ||
| @foreach($annotationProperties as $key => $value) | ||
| * @property {!! $value !!} ${{ $key }} | ||
|
||
| @endforeach | ||
| */ | ||
| @else | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,9 @@ className: ResourceAlreadyExistsException::class, | |
|
|
||
| public function testRelationModelMissing() | ||
| { | ||
| $this->mockFileSystemWithoutCommentModel(); | ||
| $this->mockFilesystem([ | ||
| 'User.php' => file_get_contents(getcwd() . '/tests/Support/Models/WelcomeBonus.php'), | ||
| ]); | ||
|
|
||
| $this->assertExceptionThrew( | ||
| className: ClassNotExistsException::class, | ||
|
|
@@ -244,4 +246,26 @@ className: WarningEvent::class, | |
| message: 'Generation of model has been skipped cause the view incorrect_stub from the config entity-generator.stubs.relation is not exists. Please check that config has the correct view name value.', | ||
| ); | ||
| } | ||
|
|
||
| public function testAddPropertyAnnotationToRelatedModel() | ||
| { | ||
| $this->mockFilesystem([ | ||
| 'Post.php' => $this->getFixture('new_model_without_fields.php'), | ||
|
||
| ]); | ||
|
|
||
| app(ModelGenerator::class) | ||
| ->setModel('Category') | ||
| ->setFields([]) | ||
| ->setRelations(new RelationsDTO( | ||
| belongsToMany: ['Post'], | ||
| )) | ||
| ->generate(); | ||
|
|
||
| $this->assertGeneratedFileEquals('related_model_with_property.php', 'app/Models/Post.php'); | ||
|
|
||
| $this->assertEventPushed( | ||
| className: SuccessCreateMessage::class, | ||
| message: 'Created a new Model: Category', | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,27 +9,19 @@ trait ModelMockTrait | |||||
| { | ||||||
| use GeneratorMockTrait; | ||||||
|
|
||||||
|
|
||||||
| public function mockFileSystemWithoutCommentModel(): void | ||||||
| { | ||||||
| $fileSystemMock = new FileSystemMock(); | ||||||
|
|
||||||
| $fileSystemMock->models = [ | ||||||
| 'User.php' => file_get_contents(getcwd() . '/tests/Support/Models/WelcomeBonus.php'), | ||||||
| ]; | ||||||
|
|
||||||
| $fileSystemMock->setStructure(); | ||||||
| } | ||||||
|
|
||||||
| public function mockFilesystem(): void | ||||||
| public function mockFilesystem(array $models = []): void | ||||||
|
||||||
| { | ||||||
| $fileSystemMock = new FileSystemMock; | ||||||
|
||||||
| $fileSystemMock = new FileSystemMock; | |
| $fileSystemMock = new FileSystemMock(); |
ref: https://www.php-fig.org/psr/psr-12/#4-classes-properties-and-methods
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |||||
| use Illuminate\Database\Eloquent\Model; | ||||||
| use RonasIT\Support\Traits\ModelTrait; | ||||||
| use Carbon\Carbon; | ||||||
| use Illuminate\Database\Eloquent\Collection; | ||||||
|
|
||||||
| /** | ||||||
| * @property int|null $priority | ||||||
|
|
@@ -20,6 +21,8 @@ | |||||
| * @property Carbon|null $updated_at | ||||||
| * @property Carbon $published_at | ||||||
| * @property array $meta | ||||||
| * @property Comment|null $comment | ||||||
| * @property Collection<int, User> $users | ||||||
|
||||||
| * @property Collection<int, User> $users | |
| * @property Collection<User> $users |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,10 @@ | |||||
| use Illuminate\Database\Eloquent\Model; | ||||||
| use RonasIT\Support\Traits\ModelTrait; | ||||||
| use App\Models\User; | ||||||
| use Illuminate\Database\Eloquent\Collection; | ||||||
|
|
||||||
| //TODO: add @property annotation for each model's field | ||||||
| /** | ||||||
| * @property Collection<int, User> $users | ||||||
|
||||||
| * @property Collection<int, User> $users | |
| * @property Collection<User> $users |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,9 +5,11 @@ | |||||
| use Illuminate\Database\Eloquent\Model; | ||||||
| use RonasIT\Support\Traits\ModelTrait; | ||||||
| use App\Models\Forum\Author; | ||||||
| use Illuminate\Database\Eloquent\Collection; | ||||||
|
|
||||||
| /** | ||||||
| * @property string $title | ||||||
| * @property Collection<int, Author> $authors | ||||||
|
||||||
| * @property Collection<int, Author> $authors | |
| * @property Collection<Author> $authors |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||
| use App\Models\Comment; | ||||||
| use App\Models\User; | ||||||
| use Carbon\Carbon; | ||||||
| use Illuminate\Database\Eloquent\Collection; | ||||||
|
|
||||||
| /** | ||||||
| * @property int|null $priority | ||||||
|
|
@@ -22,6 +23,8 @@ | |||||
| * @property Carbon|null $updated_at | ||||||
| * @property Carbon $published_at | ||||||
| * @property array $meta | ||||||
| * @property Comment|null $comment | ||||||
| * @property Collection<int, User> $users | ||||||
|
||||||
| * @property Collection<int, User> $users | |
| * @property Collection<User> $users |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||
| <?php | ||||||
|
|
||||||
| namespace App\Models; | ||||||
|
|
||||||
| use Illuminate\Database\Eloquent\Collection; | ||||||
| use Illuminate\Database\Eloquent\Model; | ||||||
| use RonasIT\Support\Traits\ModelTrait; | ||||||
|
|
||||||
| //TODO: add @property annotation for each model's field | ||||||
| /** | ||||||
| * @property Collection<int, Category> $categories | ||||||
|
||||||
| * @property Collection<int, Category> $categories | |
| * @property Collection<Category> $categories |
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.