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.
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:
Let’s assume your password-generator is a package inside the “yourname” vendor. So the package name will be:
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
Good. If you were installing this package inside your website project you will have the follow structure using Composer:
But you already have you code inside:
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:
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!
9 thoughts on “Testing your Packagist/Composer package locally”
Thank you for sharing this post JGrossi. You can also visit my page and it will give you some tips about creating and editing work packages.
You can also use this: https://getcomposer.org/doc…
Thanks @Edgar! 🙂
Nice ! This idea is very famous currently, you can even do it with a Composer plugin that someone posts on a Composer issue : https://github.com/Letudian…
Very nice @John! Thanks for sharing. Welcome to the blog! Cheers!
Can you please post a little example for windows user I was following everything but got stuck where you create symolic link.
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 😉