Back to Blog
Sep 27th, 2024

Using a Symfony Reproducer

Written by kbond

Edit
Using a Symfony Reproducer

Tip

This is part 2 of a 2-part Reproducer series. If you haven't already, check out Part 1 first.

Ok, so you've created a reproducer app for a bug you've found in Symfony. For this article, we'll assume the reproducer you've created in part 1 is located at ~/my-reproducer.

Forking the Symfony Repository

Step 1 is to fork the symfony/symfony repository on GitHub. This will give us our own copy where we can work.

  1. Visit https://github.com/symfony/symfony and click the Fork button at the top of the page.
  2. Choose your personal GitHub account as the owner and keep the default name of symfony.
  3. Leave all the other options as is and click Create Fork.
  4. You should now be on https://github.com/your-username/symfony.
  5. Wait a few seconds for the fork to be created.
  6. Click the green Code dropdown and under the SSH tab, copy the URL to your clipboard.

Cloning your Fork

Let's get the repo down to your local workspace:

cd ~
git clone <your-fork-url-from-clipboard>
cd symfony

Now we're going to add the original Symfony repo as an upstream remote. Why? So we can easily pull in the latest Symfony updates and stay fresh!

git remote add upstream git@github.com:symfony/symfony.git

Let's grab the latest changes from Symfony (you'll want to run this command whenever Symfony gets an update, so it's good to get used to it).

git fetch upstream

Use your Reproducer to Fix the Bug

In Part 1, you picked the Symfony version for your reproducer. Now it's time to match that version in our forked Symfony repo. Let's check it out:

git checkout 7.1 # or any other version you picked for your reproducer

Boom! You've got the right version. Now, let's make sure we're up-to-date by merging in any new changes from the upstream repository:

git merge upstream/7.1

Great! Next, create a new branch for our bug fix:

git checkout -b my-fix

Tip

The branch name (my-fix) isn't important, but it should be descriptive and unique to your fork.

Linking your Reproducer to your Fork

Let's link that reproducer you created to your freshly forked Symfony repo. Head back to your reproducer directory:

cd ~/my-reproducer

Symfony comes with a handy PHP script to link itself to a project. This will symlink all your app's symfony/* packages to your local fork. Super neat, right?

php ../symfony/link .

Fixing the Bug

Open your reproducer in your favorite IDE. Normally, messing with files in the vendor/ directory is a no-no, but in this case, for files in vendor/symfony/*, you can! Changes you make to these files are actually being made in your forked Symfony repository because of the symlinks.

Once you've squashed that bug, jump back into your local Symfony fork and take a look at your changes:

cd ~/symfony
git status

If everything looks good, follow the Symfony documentation on Creating a Pull Request to submit your fix to the Symfony repository!

Verifying a Proposed Fix

But if you can't fix it yourself - don't worry! Someone from the awesome Symfony community may propose a fix. If this happens, you can help with the review and confirm with your reproducer if the fix works. PR authors love seeing "this fixes my issue" comments!

First, track down the Pull Request (PR) that has the fix. You'll see something like this at the top of the PR:

{user} wants to merge X commit(s) into symfony:{version} from {user}:{branch-name}

Click {user}:{branch-name} to jump to the {user}'s fork. Like we did with our own fork, click the green Code dropdown and copy the URL to your clipboard.

We're going to add their fork as a remote:

cd ~/symfony
git remote add {user} <fork-url-from-clipboard>
git fetch {user}

Now, checkout the branch from the user's fork:

git switch -c {branch-name} {user}/{branch-name}

Tip

I like to prefix the branch name with the user's GitHub handle so I don't get lost in branch-land!

git switch -c fabpot-fix-something fabpot/fix-something

Back to your reproducer! Let's link it to this new branch:

cd ~/my-reproducer
php ../symfony/link .

Now, use your reproducer to verify that fix and show some love by giving feedback on the PR!

Bonus Tools

If you want to make your life a little easier (and why wouldn't you?), check out GitHub Desktop or the GitHub CLI. They're awesome for forking, cloning, and submitting PRs without all the manual fuss.

And there you have it! Whether you're fixing a bug or helping the community to squash one, you're making Symfony even better. Got questions or feedback? Drop them in the comments below!

Happy coding!

Comments

Sort By
Login or Register to join the conversation

Delete comment?

Share this comment

astronaut with balloons in space

"Houston: no signs of life"
Start the conversation!