Env: php: No such file or directory —How to handle dynamic variables?

I’m building a workflow for the Alfred launcher. I’ve changed my tests to simulate a call to my php script from Alfred, but now my Travis builds fail. Alfred communicates by passing environment variables, so depending on what the next step in my workflow is, I pass environment variables around. The thing is, Travis doesn’t seem to allow this. I can’t put those env variables in the Travis config file or anywhere else as they are dynamic, changing according to the related tests. Is there anything I can do? Something I’m missing? Thanks!

The GitHub repository: https://github.com/godbout/alfred-time/tree/v2
The Travis builds: https://travis-ci.org/godbout/alfred-time/builds

I am sorry to hear about the problems you are having.

However, I am not quite sure what you are asking. In https://travis-ci.org/godbout/alfred-time/jobs/498592654, for example, you pass the environment variable the same way as a failing one (https://travis-ci.org/godbout/alfred-time/jobs/499183556) and runs fine.

I tend to think that your current problem is in the code. The first failure is https://travis-ci.org/godbout/alfred-time/builds/498811929, which, among other things, introduces https://github.com/godbout/alfred-time/compare/063b6603073d...9a4823c00f5a#diff-d4c8c6dc8769324fc27cfdac19f05caf. This seems like something that changes what php command your test executes.

1 Like

Thanks for take the time to answer and have a look!

The builds worked fine until #246 because the only environment variables needed at the time by Travis was for the creation of a folder. That variable was defined in my .travis.yml file. The rest of my feature tests used the classes directly to build the setup world. I had to change that to call directly the PHP script with shell_exec. This is due to the fact that those classes I use are singletons. This is perfect when using with Alfred (because for each call to the PHP script Alfred does, there will be only one instance of the class, then the script ends and Alfred calls it again) but this doesn’t work well with tests that need the singletons to be reseted. So, to be able to simulate/mock a call from Alfred, I need to call this line:

return shell_exec("env -i alfred_workflow_data=XXX php XXX");

This ruins the code coverage but that’s fine. But Travis can’t seem to find “env”. This is where the env: php: No such file or directory error comes from (I guess?).

I’m thinking it’s a variable issue because I struggle already before with passing variables through putenv and when reading the doc, I saw that this couldn’t work and I had to define the variables in the Travis config file (or repo). But then, how to define dynamic variables? Or is it something else I’m missing? Maybe it is the php executable that can’t be launched by Travis?

Test suite runs fine on my dev machine running PHP 7.2.

That’s not what the error message says. What it says is this:

That env tried hard to find the command php based on the $PATH environment variable, but did not find it.

Since you have set -i, env is starting with “an empty environment.” (env(1) - Linux manual page). I suspect this is your issue.

We use phpenv to manage PHP run times, and the php command is not in the standard place you might expect (e.g., /usr/bin, /usr/local/bin).

I don’t know enough about your code and its requirements, so I can’t advise you as to how to fix the problem at hand, but I hope my explanation above is enough to get you on your way to the solution.

1 Like

Yes! A thousand thanks. Your first answer actually pointed me into the right direction already. I pushed a build with a which php to see where php is located. Both of your explanations are fantastic and you are right, I think I get all the information now to handle the issue by myself. It was a lack of understanding from my part. Thank you Hiro!

1 Like