Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running tests of a composer package in vendor directory

I have a project I created with composer create-project command, but before running composer install, I added one more package to project composer.json file. After installing the packages, I correctly have all the dependencies including the one newly added in the vendor directory. What I want now is to run the tests of the package that I manually added to composer.json. I tried the below, but doesn't seem to run the tests of the said package

./vendor/bin/phpunit 
like image 317
Cholthi Paul Ttiopic Avatar asked Nov 28 '17 06:11

Cholthi Paul Ttiopic


People also ask

How do I check my composer package?

You can run composer show -i (short for --installed ). In the latest version just use composer show .

How do I run a composer project from a package folder?

Create a folder to run this from ideally in the parent folder so both the project folder and the package folder are on the same level. Next create a composer.json file, add the vendor/package name to require and autoload it, to make it work add a repositories array and pass in the local path to the package.

How to reference a local repository from a composer package?

By setting the "type": "path" composer knows that you would like to reference a local repository and the url defines the package location (the path can be relative or absolute). With this two settings you are good to go, but composer will copy the package code into the vendor folder and you need to call composer update on every package change.

How to prevent composer from copying the package code?

With this two settings you are good to go, but composer will copy the package code into the vendor folder and you need to call composer update on every package change. To prevent composer from doing so you need to specify the symlink option and composer will create a symlink to the package folder.

What does vendor/BIN DO in composer?

It instructs Composer to install the package's binaries to vendor/bin for any project that depends on that project. This is a convenient way to expose useful scripts that would otherwise be hidden deep in the vendor/ directory. What happens when Composer is run on a composer.json that defines vendor binaries? #


Video Answer


1 Answers

I was having a similar problem, we have separate private packages in vendor folder that needed to be tested. By default composer autoload-dev includes only root package as mentioned here https://getcomposer.org/doc/04-schema.md#root-package

To include your forked package just add an entry in your root composer.json file under autoload-dev

"autoload-dev": {
        "psr-4": {
            "Company\\Package\\Tests\\": "vendor/package/tests/"
        }
    },
like image 195
Aftab Naveed Avatar answered Oct 20 '22 01:10

Aftab Naveed