PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] How to pass arguments to custom composer script

 December 31, 2021     composer-php, laravel, php, phpunit     No comments   

Issue

In my Laravel project, I want to run phpunit for a single file, like this one:

$ composer run-script test tests/Unit/Services/OrderServiceTest.php

Here is my composer setup:

"scripts": {
    "test": [
        "@testenv",
        "@phpunit"
    ],
    "testenv": [
        "php artisan config:cache --env=testing",
        "php artisan config:clear"
    ],
    "phpunit": [
        "php ./vendor/phpunit/phpunit/phpunit --"
    ]
}

However, I'm running into this error:

www@287dd7480e22:/var/www$ composer run-script test tests/Unit/Services/OrderServiceTest.php

php artisan config:cache --env=testing 'tests/Unit/Services/OrderServiceTest.php'

Too many arguments, expected arguments "command".

Notice:

  • I've seen this post: How do you pass an argument to a composer script from the command line?. But either the solution (adding -- at the end of custom composer script) does not work for my case or I do not understand it properly.
  • If I do not pass an argument, the script runs without a problem. (i.e. run phpunit for all test files)

Solution

According to this comment in composer repository:

There is no way to pass arguments only to one of the sub-scripts if you do a script group and call multiple things..



Answered By - glinda93
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing