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

Sunday, January 16, 2022

[FIXED] "Bad variable name" when trying to run phpunit tests via a Makefile without deprecation warnings

 January 16, 2022     makefile, php, phpunit, symfony, unit-testing     No comments   

Issue

I have a Make target called test. It looks like this:

test:
    /var/www//vendor/bin/phpunit

I want to set up a git hook that runs all tests before commits. In order to do this without getting stalled on deprecation warnings, I want to have my hook run a different Make target. It looks like this:

test-automated:
    export SYMFONY_DEPRECATIONS_HELPER = disabled
    /var/www//vendor/bin/phpunit

However, when I try to run this target, I get this error message:

export SYMFONY_DEPRECATIONS_HELPER = "disabled" /bin/sh: export: line 1: : bad variable name make: *** [Makefile:14: test-automated] Error 2

What can I do to make Make and PHPUnit run without deprecation warnings?

Addendum: I also tried export SYMFONY_DEPRECATIONS_HELPER=disabled and export SYMFONY_DEPRECATIONS_HELPER="disabled". In both of those cases, the Make target ran, but deprecation warnings were displayed, and Make exited with code 1, which is not the desired outcome.


Solution

Your answer is the right way to do it.

A makefile recipe is a shell script, and the content of the recipe must be valid shell syntax; it can't be makefile syntax. In the shell, variable assignment must not have whitespace around the equal sign; if you type this into your shell prompt:

$ export foo = bar

that is not assigning a variable foo to the value bar and exporting it; that is trying to export the 3 variables named foo, =, and bar, and = is not a valid shell variable name so you get this error.

Your change to make this export SYMFONY_DEPRECATIONS_HELPER=disabled is right.

The reason it doesn't work is that each logical line in a recipe is run in a separate shell. So assigning the variable on one logical line then running the program in another logical line is not going to work: the assignment on the first line is lost as soon as that shell exits.

You can use either one of:

test-automated:
        SYMFONY_DEPRECATIONS_HELPER=disabled /var/www//vendor/bin/phpunit

as you did or (less good IMO but will work):

test-automated:
        export SYMFONY_DEPRECATIONS_HELPER=disabled; \
          /var/www//vendor/bin/phpunit

by adding the ; \ at the end you've combined these two physical lines into one logical line.



Answered By - MadScientist
  • 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