Phpunit behaves differently on different machines - php

I wrote a few PHPUnit tests for my PHP application. I am working on two development machines that synchronize the entire development filesystem, and there is an automatic testing system that runs the tests on a clean svn checkout.
Now, something weird is going on. One of the development machines runs Ubuntu linux 10.10, PHP 5.3.3, phpunit 3.4.6 which I later upgraded to 3.4.14. When I run phpunit on each single test, all tests pass. When I run phpunit on my xml configuration file that just runs them all, using phpunit --configuration=phpunit.cfg, the last test case fails, and a Class myClass not found error is returned. This class is inside a file that is loaded using require_once. Upgrading phpunit made no difference.
edit: I have the feeling that the list of files PHP includes using require_once is not reset on my linux box, but the classes are actually lost, that is, it thinks it has
already included myclass.php while the class inside is not loaded.
Now, the other machine is running Mac OS X Snow Leopard 10.6.5, PHP 5.3.3 and phpunit 3.4.3. If I run the unit tests there individually, no errors occur, just as on the linux box, but when I run the tests using the xml configuration, no errors occur either. We also have an auto testing environment running linux 10.4 LTS, PHP 5.2.6 and phpunit 3.4.9. Also no errors.
All systems use exactly the same files, so there is no difference in the source code or tests. Also the phpunit.xml is the same.
I feel completely in the dark here. How can I figure out what the problem may be?
Both the linux development machine and the macbook are running PHP 5.3.3. The autotest machine is runing 5.2.6

Two things to watch out for:
The include path in the PHP config on both machines
That there isn't another copy of the class file sitting around in your homedir or the cwd of the script. Usually . will be in the include path for PHP and rogue copies of files can cause problems like this

Is it possible that it isn't PHPUnit that is acting up, but a local php configuration issue causing problems in your system under test? Diff your php.ini on the 2 machines and you will likely find some differences.

Related

Why does PHPUnit take so long to register my code changes?

I'm starting to study PHPUnit, and I've noticed that when I alter my code (eg. to fix an error) PHPUnit continues to complain about the error unless I stop and sit with my hands off the keyboard for 30 seconds or so. Why does this happen and what can I do to stop it? I'm using the default php.ini value of opcache.enable_cli=0, but as I'm new to both PHPUnit and command-line PHP I have no idea where else to look.
EDIT: I am using Bluefish to edit; the machine in question is running Ubuntu 18.04.5 with ext4 filesystem; the working directory is ext4 on a NAS NFS mount. I've been using this setup for several months with other languages and not noticed the problem until now.

Ubuntu 20.04 and PHP won't allow relative PHP includes

I have a LAMP/WAMP application that runs successfully on nine different machines. A windows PC and multiple centos5, centos6, and centos7 linux servers. They all share a common source tree.
I just installed ubuntu 20.04 on a new machine. When I try to run this application it fails because PHP won't allow relative include(), require(), etc. paths. This is PHP 7.3.24.
This function call and others like it work everywhere else but fail on ubuntu:
include("../include/app_fns.php");
When I recode this with full paths it seems to work, but there are 114 files and 129 instances of these kinds of relative paths I would have to edit. I can do that, but the full path isn't the same on all the machines where this app is installed, so the code would no longer be compatible will all machines. That's unacceptable.
There has to be some way to tell PHP to act like it does everywhere else. I've tried include_path() changes. The changes show up in phpinfo, but they seem to be ignored and the errors persist. Any suggestions? I really want this to work on ubuntu, but I'll have to install centos7 on this machine if I can't solve this problem.

Remote Symfony2 + Netbeans workflow (feat. git)

I'm hoping someone have encountered this problem before and will be able to help
So, the problem goes like this: There's 2 developers, each one of them needs 2 versions of a website (development + production). Due to very different operating systems, triple configuration difficulities and administration restrictions on them it's impossible to run projects locally. But there's a bunch of problems while running them remotely:
How to run Symfony2 CLI commands in Netbeans (since those commands need access to db)?
How to differentiate between production/development? I have allowed external access to db for 2 IP addresses, but theres only one parameters.ini file. And once it's used to connect to localhost (when run by http), and second it's used to connect via remote host (when CLI command is run in netbeans)
More info you may ask, so here it goes:
Dev #1: Kubuntu 12.04 x64 3.2.0-25-generic NB#7.1.2
Dev #2: Windows 7 x64 NB#7.1.2
Server: Ubuntu Server 12.04 x64
SQL: PostgreSQL
webserver: Apache2
Our workflow now looks (or at least should look) something like this:
Dev #1 does something locally, but on run changes are being moved to the server so he can check how it went on beta1.sitename.com.
Each change is commited to user branch in git when suitable.
After testing changes are baing merged to master, tested, pulled to a sitename.com, and then tested again.
After this the cycle repeats :)
PS. Valid answer would also be a hint how proper workflow in that kind of situation should be. I've tried already with post-* git handles, and it didn't work really well either...
First of all I would highly recommend trying to solve the development machine issue. There is vagrant which can be used together with chef or puppet (or a specialiced virtual base machine) to move the development environment into a virtual machine executed on the developers pc. This would also solve many issues regarding the remote server.
If this cannot be done, here are some thoughts:
Netbeans commands won't work remotly. Have your developers ssh into the machine and execute their commands their.
I don't get your development/production environment problem. Their should a at least on virtual host with different config/cache/logs for each developer so the configs can be set correctly. The parameters.ini should not be in your git repository (You can handle this by creating a parameters.ini.dist and ignoring the parameters.ini file) so you can have different parameters.
Another interesting thing (presented on the symfony live 2012 Paris) is that you can do SET_ENV SMFONY_PARAMETER_NAME inside your apache vhost and then use %parameter.name% inside your config files (mind the two underscorse). This could be usefull in your case.
There really is no workflow I know of which could handle multiple developers on one machine with different configs and the like. It's just a mess and you either solve your problems with complex scripts which are run everytime something happens or by finding a better solution like virtual machines or different vhosts with different directories on your servers.

Netbeans and CodeIgniter on Windows and Linux?

I installed a plugin for NB 7.0.1 which enabled CodeIgniter but when I went to create a project using it, I was told I need to specify a PHP interpreter for Netbeans. I tried to do this using the php.exe you get with Xampp but I get a Java null pointer error. I can't seem to fix this but I'm thinking, why do I need an interpreter on Windows when the Linux machine can do that? I have already set this up on the VM.
Any advice from here? Thanks a lot!
I am using NB 7.1.1 and had similar issue with CodeIgniter plugin when creating a new project. NetBeans would complain No PHP Interpreter was defined in Tools->Options->PHP General. It would not enable finish button so a New Project could not be setup.
I just created a dummy batch file called nb_cli.bat and pointed NB to that for the PHP interpreter. I don't plan on executing (or debugging) CodeIgniter CLI code on local machine so that file will likely never get executed.
If you want to debug or run php locally, make sure xammp works OK outside of NetBeans. But if not, this fix should get you by the NetBeans issues.
I have a separate linux server on my local network for development as I don't need apache/php locally when I use multiple machines for dev/testing/etc.
NetBeans should bugfix that by downing that PHP Interpreter message from an Alert preventing project setup to a warning that No PHP interpreter is defined (or found) so CLI testing may not function.
As an alternative, if you have a linux box with NB installed, you can create the New project there and copy the whole folder (including the nbproject folder) to your PC and you should be able to get by having No PHP Interpreter defined.
Hopefully that gets you going with NB and CodeIgniter. If you need additional details, just ask.

PHP define is not working sometimes on some servers

I am working on a PHP web app with another developer. We have 3 total different environments:
Configuration 1: Windows XAMPP, PHP 5.3.5
Configuration 2: Turnkey LAMP, PHP 5.3.X (turnkey-lamp-11.2-lucid-x86) - not sure which ver, running from virtualbox on a mac
Configuration 3: production server, hostgator shared running CentOS, php 5.3.9 fastcgi
Configuration 2 sometimes will not recognize the defines that are handled in our settings.php file which is require_once at the top of any page which uses it. The defines work fine on Configuration 1 and 3 always. There was nothing of interest in the apache logs, other than the errors generated as a result of the define being treated as a string.
I've searched for a while and cannot find anything that describes this issue. Configuration 2 is the other developer, and i do not have access to his machine right now. Looking for suggestions on how to track this issue down. I think we are going to try a new instance of the VM, using an upgraded turnkey-lamp, however i'd really like to root cause this.
Ok, so i figured out what was happening... and as expected, it wasn't PHP or defines. The errors reported were accurrate. We use Eclipse as the IDE, and Subclipse for SVN. Configuration 2 uses a VM running from a mac, and we added a command in eclipse to sync when files are saved. Apparently the syncing only was happening for the main public_html directory, and not our other same-level directory which has the include file with the defines in it. Ultimately, i needed to look at the actual VM to notice it was way out of date on that one file, and was missing the define statement, which results in the error, but Eclipse was showing the HEAD revision from SVN, which is why it was so confusing, but simple.
Lesson: Make sure you plugged in the TV before calling the repairman.

Categories