Testing your Packagist/Composer package locally

Hello again! It’s my second post today! I’m electric!

I am developing a project that uses a package I’m developing too. So, it is a real time test project. I find a new way to do something and write it inside my package and uses that.

But sometimes this is a boring work. I am sharing my package in the Packagist website using Composer, and everything I change I have to commit, push to GitHub and update my project with Composer, to get the new code I’ve wrote. That’s a very very bad idea.

Yesterday I was talking with my friend @diegoholiveira about to test the package locally and we’ve found a easy solution. You can change the package you are developing and use that in the project that uses it. We were trying to find an easy way to do that using Composer, but the solution was easier than that. Just use symbolic links.

Structure

Ok. Let’s assume you are developing a website. This website have to generate passwords with some particularities. So you decide to develop a package to provide this password generation and use it inside the website project. So you have 2 distinct projects:

/home/me/projects/website
/home/me/projects/password-generator

Let’s assume your password-generator is a package inside the “yourname” vendor. So the package name will be:

yourname/password-generator

First you have to have installed at least a basic version of your package. You can submit a very basic package to Packagist, where you will install from. You add the package information inside your composer.json file and composer install or composer update.

Good. If you were installing this package inside your website project you will have the follow structure using Composer:

/home/me/projects/website/vendor/myname/password-generator/*.*

But you already have you code inside:

/home/me/projects/password-generator

So, create a symbolic link from your package to your website:

ln -s /home/me/projects/password-generator /home/me/projects/website/vendor/myname/password-generator

After that you must update the Composer autoload to find that new files. Inside your /website folder:

composer dump-autoload

Ready! Everything you change in the package password-generator you will can use inside your website project. If you created some new class, maybe you must run composer dump-autoload again to update files.

When you want, just commit, push your package to GitHub and share!

Published by

Junior Grossi

senior software engineer & stutterer conference speaker. happy husband & dad. maintains Corcel PHP, elePHPant.me and PHPMG. Engineering Manager @ Paddle

9 thoughts on “Testing your Packagist/Composer package locally”

  1. Can you please post a little example for windows user I was following everything but got stuck where you create symolic link.

    1. Hi @raheel! Thanks for the comment.

      I don’t know hot to test the packagist package with the use of `symbolic links`. I suggest you to read some posts about how to create these links on Windows, like this one http://goo.gl/MBEo.

      You can find more useful links looking in Google.

      Thanks for the comment ๐Ÿ˜‰

Leave a Reply to Raheel Khan Cancel reply

Your email address will not be published. Required fields are marked *