Skip to content

New subscription for phpunit #155

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

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

Conversation

hans-thomas
Copy link
Contributor

Hello, everyone. The FinishedSubscriber will be called after every test, but the ExecutionFinishedSubscriber will be called after all tests are executed.
Also, by adding this extension to the phpunit.xml file, this process can be done automatically, which would be great for devs who don't need to concern themselves with calling this command after every test run.

<phpunit>
    // ...
    <extensions>
        <bootstrap class="Tests\Extensions\Swagger\SwaggerExtension"/>
    </extensions>
</phpunit>

Also, I updated the README file to make more complete the information described.


$app->loadEnvironmentFrom('.env.testing');
$app->make(Kernel::class)->bootstrap();
shell_exec('php artisan swagger:push-documentation');
Copy link
Collaborator

Choose a reason for hiding this comment

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

the console command is just a way to save the new documentation content using driver. The core logic of documentation saving is provided by the SwaggerService.

The subscriber class is another way to trigger the documentation saving, no need to use console command here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed the swagger:push-documentation command contains all the necessary actions to save the documentation. Whenever we want to add more actions (besides the saveProductionData method of the SwaggerService class) to save documentation, we just need to add them in the push-documentation command because we call this command everywhere that we want to do the same functionality.

P.S.: I replaced it with app(SwaggerService::class)->saveProductionData(); line of code.


final class SwaggerSaveDocumentationSubscriber implements FinishedSubscriber
final class SwaggerSaveDocumentationSubscriber implements ExecutionFinishedSubscriber
Copy link
Collaborator

Choose a reason for hiding this comment

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

сould you please describe the difference between ExecutionFinishedSubscriber and FinishedSubscriber?

I supposed that ExecutionFinishedSubscriber should be called only once while using a parallel tests, but it seems it works the same as FinishedSubscriber

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, I couldn't find any documentation about these two events in the PHPUnit docs, but I guess there was a difference in performance or something.

@hans-thomas hans-thomas force-pushed the new-phpunit-extention branch 2 times, most recently from 63a9c45 to 9f6529e Compare April 18, 2025 17:22
@hans-thomas hans-thomas force-pushed the new-phpunit-extention branch from 1c0fdb9 to 69a7503 Compare April 18, 2025 19:31
@hans-thomas hans-thomas requested a review from DenTray April 18, 2025 19:33
@hans-thomas hans-thomas force-pushed the new-phpunit-extention branch from 5b0af06 to bb5248c Compare April 18, 2025 19:37
@hans-thomas hans-thomas force-pushed the new-phpunit-extention branch from daff349 to e926dc5 Compare April 18, 2025 19:48
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.

2 participants