Skip to content
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

Add model generator tests #70

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

KonstantinLapkovsky
Copy link

Issue #49

@KonstantinLapkovsky KonstantinLapkovsky self-assigned this Dec 20, 2023
@KonstantinLapkovsky KonstantinLapkovsky changed the base branch from master to 49-cover-entity-generator-with-tests December 20, 2023 19:15
@AZabolotnikov AZabolotnikov self-assigned this Nov 20, 2024
# Conflicts:
#	tests/ControllerGeneratorTest.php
#	tests/NovaResourceGeneratorTest.php
#	tests/NovaTestGeneratorTest.php
#	tests/Support/Controller/ControllerMockTrait.php
#	tests/Support/NovaResource/NovaResourceMockTrait.php
#	tests/Support/NovaTest/NovaTestMockTrait.php
#	tests/Support/Shared/GeneratorMockTrait.php
#	tests/TestCase.php
…erator-tests

# Conflicts:
#	tests/Support/Factory/FactoryMockTrait.php
Copy link
Collaborator

@DenTray DenTray left a comment

Choose a reason for hiding this comment

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

please change target branch and merge it with the current master

@pirs1337 pirs1337 assigned pirs1337 and unassigned AZabolotnikov Dec 9, 2024
@pirs1337 pirs1337 changed the base branch from 49-cover-entity-generator-with-tests to master December 19, 2024 11:20
@pirs1337 pirs1337 assigned DenTray and unassigned pirs1337 Dec 19, 2024
@@ -60,8 +60,8 @@ public function prepareRelatedModels(): void
if (!$this->classExists('models', $relation)) {
$this->throwFailureException(
ClassNotExistsException::class,
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add arg names for multiline style

]);
}

public function mockGeneratorForMissingRelationModel(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems this method is not using

{
return $this->hasMany(User::class);
}
protected $casts = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we change casts place after the hidden property

{
public function some_relation()
{

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@DenTray DenTray assigned pirs1337 and unassigned DenTray Dec 23, 2024
@pirs1337 pirs1337 assigned DenTray and unassigned pirs1337 Jan 10, 2025
@@ -0,0 +1,10 @@
<?php
Copy link
Collaborator

Choose a reason for hiding this comment

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

src/Generators/ModelGenerator.php Outdated Show resolved Hide resolved
@@ -28,6 +28,8 @@ public function setUp(): void

vfsStream::setup();

Event::fake();
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's good to move it to the base test case class, but please remove event fake from other tests classes


class ModelGeneratorTest extends TestCase
{
use ModelMockTrait, 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 we just use MockTrait into Generator MockTrait?

@DenTray DenTray assigned pirs1337 and unassigned DenTray Jan 13, 2025
@pirs1337 pirs1337 assigned DenTray and unassigned pirs1337 Jan 14, 2025
);
}

if ($this->isStubExists('model') && ($this->isStubExists('relation') || empty($this->relations))) {
if ($this->isStubExists('model') && (collect($this->relations)->every(fn ($relation) => empty($relation)) || $this->isStubExists('relation', 'model'))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if ($this->isStubExists('model') && (collect($this->relations)->every(fn ($relation) => empty($relation)) || $this->isStubExists('relation', 'model'))) {
if ($this->isStubExists('model') && (!$this->hasRelations() || $this->isStubExists('relation', 'model'))) {

@DenTray DenTray assigned pirs1337 and unassigned DenTray Jan 14, 2025
@pirs1337 pirs1337 assigned DenTray and unassigned pirs1337 Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants