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

[Bug] Wrong model imports in tests when using a custom model namespace #254

Closed
kennyhorna opened this issue May 31, 2020 · 2 comments · Fixed by #256
Closed

[Bug] Wrong model imports in tests when using a custom model namespace #254

kennyhorna opened this issue May 31, 2020 · 2 comments · Fixed by #256
Labels
bug Something isn't working

Comments

@kennyhorna
Copy link

  • Laravel Version: 7.12.0
  • PHP Version: 7.3.5
  • Blueprint Version: 1.13.0
  • Platform: Windows

Description:

When using a custom model namespace, the generated test import models wrong.

Steps To Reproduce:

  1. Customize model namespace (config/blueprint.php L:30)
// ...
 'models_namespace' => 'Models',
// ...
  1. Generate the code

draft.yaml:

models:
  Category:
    name: string:30
    image: string
    parent_id: id:Category nullable
    active: boolean default:true
    relationships:
      hasMany: Category
    softDeletes

controllers:
  Category:
    resource: api

The above script will generate, between other things, this test:

namespace Tests\Feature\Http\Controllers;

use App\Category; // <----- this should be App\Models\Category;
// ...

/**
 * @see \App\Http\Controllers\CategoryController
 */
class CategoryControllerTest extends TestCase
{
    use AdditionalAssertions, RefreshDatabase, WithFaker;

    /**
     * @test
     */
    public function index_behaves_as_expected()
    {
        $categories = factory(Category::class, 3)->create();

        $response = $this->get(route('category.index'));
    }

    // ...
@kennyhorna kennyhorna added bug Something isn't working pending This issue is pending review labels May 31, 2020
@jasonmccreary
Copy link
Collaborator

Hmmm. I thought this was fixed at one point. But maybe not.

I need to make a central registry for models. It seems pretty much all aspects of Blueprint need it at this point.

@jasonmccreary jasonmccreary removed the pending This issue is pending review label May 31, 2020
@kennyhorna
Copy link
Author

@jasonmccreary I was just checking the generated test and, specially in the resource api controllers, there's some missing assertions in some methods.

Also, when using the softDeletes shorthand, the test assertion for the deleted method is:

$this->assertDeleted($model);

Instead of:

$this->assertSoftDeleted($model);

Using this same draft.yaml for both cases by the way.

I know that I should make separeted issues for each of this observations but I'm a little short on time on a project but probably gonna do it next week. Just want to make you notice this in case I forget to write the proper issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants