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!
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:
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.
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!