Skip to content
Luca Ubiali Web Developer

Watch Me Submit a Laravel Pull Request

August 8th, 2024
Continuous Learning

Episode link - https://laracasts.com/series/lukes-larabits/episodes/23


Up until now I never looked at how PRs are submitted to Laravel. This is a very interesting and quick introduction, but I think I’ll watch the full series https://laracasts.com/series/how-to-contribute-to-open-source by Luke Downing.

In the video Luke opens a real PR on the Laravel framework, so I had to go and look if it was merged. Of course turns out it was merge the day after its creation.

But was interesting also to see the automation set up on the repo to run test and code style checks. In fact Luke’s first commit didn’t pass all checks due to a style issue https://github.com/laravel/framework/pull/51932/commits

The code changes were straightforward, but I got a nice takeaway. In his test he instantiated an anonymous class from an interface on the fly like this:

1$extension = new class implements ExtensionInterface
2{
3 public bool $configured = false;
4 
5 public function register(EnvironmentBuilderInterface $environment): void
6 {
7 $this->configured = true;
8 }
9};

I didn’t know that was an option. In the past when I had to do something similar for an abstract class I did this:

1$publishStep = $this->getMockForAbstractClass(
2 PublishStep::class,
3 [$this->publishId]
4);

But now I can also do this:

1$publishStep = new class extends PublishStep {
2 protected function doSomeDataFetchingAndCaching()
3 {
4 // do something
5 }
6};

The nice thing is that PHPStorm takes care of creating the class snippet with all methods that need implementation.