Skip to content

[5.8] Replace only last occurrence to find class name from path on event discovery#28421

Merged
taylorotwell merged 3 commits into
laravel:5.8from
paul-thebaud:5.8
May 6, 2019
Merged

[5.8] Replace only last occurrence to find class name from path on event discovery#28421
taylorotwell merged 3 commits into
laravel:5.8from
paul-thebaud:5.8

Conversation

@paul-thebaud

Copy link
Copy Markdown
Contributor

This PR fix the event discovery. When having a Laravel project within /app path (it is the case with Heroku PHP apps), Laravel will replace /app twice because the str_replace is used.

My fix is to use Str::replaceLast as it will only replace the last occurrence.

@paul-thebaud paul-thebaud changed the title Replace only last occurrence to find class name from path on event discovery [5.8] Replace only last occurrence to find class name from path on event discovery May 6, 2019
@antonkomarev

Copy link
Copy Markdown
Contributor

It will be good to have tests for this case.

@paul-thebaud

Copy link
Copy Markdown
Contributor Author

It will be good to have tests for this case.

Since the DiscoverEvents has only static methods, and the Finder is not created using dependency injection, it is hard to test this case without Reflection for protected method.

But I don't know if it is a good idea. Any other thought?

@paul-thebaud

paul-thebaud commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

As @antonkomarev suggested, I added a test for the case mentioned in this PR.

This test use Reflection to only call DiscoverEvents::classFromFile method because the Finder instance cannot be mocked because there is no dependency injection.

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