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

[make:entity] Fix error when API-Platform is installed. #881

Merged
merged 1 commit into from
Jun 30, 2021
Merged

[make:entity] Fix error when API-Platform is installed. #881

merged 1 commit into from
Jun 30, 2021

Conversation

MichaelBrauner
Copy link
Contributor

I'll try to get the testsuite running. Then I will also write a test for that.

@jrushlow jrushlow changed the title Fix - error on make:entity when API-Platform is installed. Fixes #878 [make:entity] Fix error when API-Platform is installed. May 18, 2021
@weaverryan
Copy link
Member

It'd be great to have a test to "cover" the error. However, the fact that the tests DO pass with this change (the @dev tests are currently broken unrelate to this PR, I believe) and that the change is a good one, I would give this a +1

@MichaelBrauner
Copy link
Contributor Author

Thank you Ryan.

I tried the last days to get the tests running. Marbulk helped me a lot - because I never wrote tests before. Actually thats something I want to watch next on symfonycasts ;) .

But I can't get the MakeEntityTest running.
The symfony applications in tmp/cache created for every dataset do not have a DATABASE_URL inside the .env files.
So I get an error, when it should be replaced with the TEST_DATABASE_DSN inside the phpunit.xml.

Hm. Are this the tests wich are currently broken - as u said before?

Because when I run all tests of maker-bundle I can see that there are test succeeding.

@ghost
Copy link

ghost commented Jun 12, 2021

@weaverryan Any help for the new contributor from the maintainer? I think Symfony is all about contributors.

@MichaelBrauner
Copy link
Contributor Author

Hm, I don't really see me as a contributer yet. I just found a bug and wrote a few lines to fix that.

I also tried 3 days long to make those tests work. But I am completly new to testing.

I also have a fulltime-job and for these 3 days of trying to make the tests work, I stopped working on my side projects.
And also in case these tests are failing because of something else (not related to my system) - I don't want to fix also this :D.

@mpiot
Copy link

mpiot commented Jun 28, 2021

Tests fail seem unrelated to the PR. To trigger the actual bug, you should update or create a duplicate of it:

File: https://github.com/symfony/maker-bundle/blob/main/tests/Maker/MakeEntityTest.php

        yield 'entity_new' => [MakerTestDetails::createTest(
            $this->getMakerInstance(MakeEntity::class),
            [
                // entity class name
                'User',
                // add not additional fields
                '',
            ])
            ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity')
            ->configureDatabase()
            ->updateSchemaAfterCommand(),
        ];

This test simulate the creation of a basic new Entity, without any fields. The wizard do not ask about Broadcasting or APiPlatform (because not simulated as installed).

In this test:

        yield 'entity_new_api_resource' => [MakerTestDetails::createTest(
            $this->getMakerInstance(MakeEntity::class),
            [
                // entity class name
                'User',
                // Mark the entity as an API Platform resource
                'y',
                // add not additional fields
                '',
            ])
            ->addExtraDependencies('api')
            ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity')
            ->configureDatabase()
            ->updateSchemaAfterCommand()
            ->assert(function (string $output, string $directory) {
                $this->assertFileExists($directory.'/src/Entity/User.php');

                $content = file_get_contents($directory.'/src/Entity/User.php');
                $this->assertStringContainsString('use ApiPlatform\Core\Annotation\ApiResource;', $content);
                $this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[ApiResource]' : '@ApiResource', $content);
            }),
        ];

You have the same has before but with api platform, then in :

        yield 'entity_new_broadcast' => [MakerTestDetails::createTest(
            $this->getMakerInstance(MakeEntity::class),
            [
                // entity class name
                'User',
                // Mark the entity as broadcasted
                'y',
                // add not additional fields
                '',
            ])
            ->setRequiredPhpVersion(70200)
            ->addExtraDependencies('ux-turbo-mercure')
            ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity')
            ->configureDatabase()
            ->addReplacement(
                '.env',
                'https://127.0.0.1:8000/.well-known/mercure',
                'http://127.0.0.1:1337/.well-known/mercure'
            )
            ->updateSchemaAfterCommand()
            ->assert(function (string $output, string $directory) {
                $this->assertFileExists($directory.'/src/Entity/User.php');

                $content = file_get_contents($directory.'/src/Entity/User.php');
                $this->assertStringContainsString('use Symfony\UX\Turbo\Attribute\Broadcast;', $content);
                $this->assertStringContainsString(\PHP_VERSION_ID >= 80000 ? '#[Broadcast]' : '@Broadcast', $content);
            }),
        ];

You create a basic one with a broadcast.

In your case you want to create one new, simulating APiPlatform and Broadcat installed, but say "n" to their usage, it give something like:

        yield 'entity_new_with_api_and_broadcast_dependencies' => [MakerTestDetails::createTest(
            $this->getMakerInstance(MakeEntity::class),
            [
                // entity class name
                'User',
                // Mark the entity as not an API Platform resource
                'n',
                // Mark the entity as not broadcasted
                'n',
                // add not additional fields
                '',
            ])
            ->setRequiredPhpVersion(70200)
            ->addExtraDependencies('api')
            ->addExtraDependencies('ux-turbo-mercure')
            ->setFixtureFilesPath(__DIR__.'/../fixtures/MakeEntity')
            ->configureDatabase()
            ->updateSchemaAfterCommand(),
        ];

@weaverryan
Copy link
Member

@mpiot if you’re willing and able, you could create another PR with the failing test. Then I could merge in both PR’s (your pr with the failing test and this fix). I’m just trying to see what we can do to move this forward given that we have several people trying to help!

cheers!

@mpiot
Copy link

mpiot commented Jun 29, 2021

@weaverryan @MichaelBrauner just implement the missing test. I prefer help him to finish his PR (more interesting, I think). But if needed, I'll do that :)

@MichaelBrauner
Copy link
Contributor Author

I did implement the test. I also tried it on my lokal project. It definetly works and fixes the bug.

When the failing tests are not related to my PR, how can I then finish this PR?

@mpiot
Copy link

mpiot commented Jun 30, 2021

@MichaelBrauner Just need to wait a maintener approve the workflow running and approve your change (if not problems in code / tests)

@weaverryan
Copy link
Member

Awesome! Thanks to both @MichaelBrauner and @mpiot for getting this done :)

@weaverryan weaverryan merged commit 936db0f into symfony:main Jun 30, 2021
@jrushlow jrushlow mentioned this pull request Jun 30, 2021
weaverryan added a commit that referenced this pull request Jul 1, 2021
This PR was merged into the 1.0-dev branch.

Discussion
----------

[release] v1.33.0

Hi Makers!

Insert clever words here

## [v1.33.0](https://github.com/symfony/maker-bundle/releases/tag/v1.33.0)

*June 30th, 2021*

### Feature

- [#895](#895) - [make:crud] send the proper HTTP status codes and use renderForm() when available - *`@dunglas`*
- [#889](#889) - [make:user] Use password_hashers instead of encoders - *`@wouterj`*

### Bug Fix

- [#913](#913) - [make:registration] conditionally generate verify email flash in template - *`@jrushlow`*
- [#881](#881) - [make:entity] Fix error when API-Platform is installed. - *`@MichaelBrauner`*

Diff: v1.32.0...v1.33.0

Happy making!

Commits
-------

aa1b721 [release] v1.33.0
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.

3 participants