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.
Advertisement
Answer
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.