WINCACHE test code committed to PECL, paves a way to test PHP CGI

Few days back I made some code commit (code check-in) to WINCACHE SVN depot on PECL. I committed the test infrastructure to test WINCACHE. The entire test code can be see inside the folder at http://svn.php.net/viewvc/pecl/wincache/trunk/tests/. Let me explain how it works. In order to make it work first of all the binaries has to be compiled. This is the binary which is responsible for driving the test suite, I call it as a kind of test driver. I have already committed the the Visual Studio solution file which is at location http://svn.php.net/viewvc/pecl/wincache/trunk/tests/driver/test_wincache.sln?view=log. However the solution file is meant for Visual Studio 2008 and may not be compatible with previous versions of Visual Studio. If you are using an old version of Visual Studio you may need to create a new solution/project file (simply chose ‘WIN32 Console Application’ while creating the solution/project file). After creating a new solution just add the C++ source/header files present at http://svn.php.net/viewvc/pecl/wincache/trunk/tests/driver/test_wincache/ to the solution/project. Compile it in Visual Studio and the binaries should be made. This builds one executable which is named ‘test_wincache.exe’. You can either compile Release/Debug build but I always prefer Release build. Here is how you can use the binaries to test WINCACHE.

  • In your document root (typically C:\inetpub\wwwroot on IIS) create a new folder named ‘testwincache’.
  • Copy the folder named ‘php_all’ and ‘php_5_3’ from http://svn.php.net/viewvc/pecl/wincache/trunk/tests/. Let me take some time explaining how the test cases are organized.
    • Inside the folder named ‘php_all’ there are PHP files which will run on both PHP 5.2 as well as PHP 5.3.
    • The folder ‘php_5_3’ contains test cases specific to PHP 5.3 and should not be run with PHP 5.2 as they will fail. They contain syntax/code specific to PHP 5.3.
  • Copy the folder named ‘php_all’ and ‘php_5_3’ inside the just created folder named ‘testwincache’.
  • In the folder named ‘testwincache’ create a folder named ‘temp’. Please ensure that this folder has sufficient right/ACL so that PHP application can write to it.
  • Also ensure that PHP application has proper read/write permission for folder named ‘php_all’ and ‘php_5_3’.
  • Open an elevated command prompt if you are on Vista+ OS.
  • Go to the folder where test_wincache.exe is present.
  • Type test_wincache.exe C:\inetpub\wwwroot\testwincache\php_all http://localhost/testwincache/php_all
  • This will run the WINCACHE test cases and dump a nice summary. The result can also be found in the file named result.txt inside temp folder.
  • If one wants to run php_5_3 test cases just replace php_all with php_5_3 in the above command.
  • One can also run test_wincache --detailed to get a detailed usage of the tool.

What the code does?

  • The code parses the directory which is supplied as first argument and finds all the file which has name wincache<test_case_number>.php
  • Opens Internet Explorer and executes the test file in the browser using the IWebBrowser2 interface.
  • Each test case has an associated file named wincache<test_case_number>.out.txt which contains the expected output of the test case.
  • The test case itself write a file named output.txt in the temporary folder named ‘temp’.
  • The above two files are compared to indicate pass/failure.
  • A file named ‘result.txt’ is created where the test case pass/failure is logged.

For people interested in knowing the details of commit please look at http://svn.php.net/viewvc?view=revision&revision=294232.

But didn’t the title of the blog says that this paves the way to test PHP CGI executable? Yes, it does. If you look at PHP regression suite, one thing which is missing there is the lack of way to test php-cgi.exe as it will involve running the test cases in the browser. Though the code is shared between CLI and CGI version of PHP, running under browser is an important aspect of testing PHP as the credential under which the CGI executable runs inside the browser is significantly different than when run through CLI. So if someone is eager in the community to take this forward I am more than willing to work with him to make this happen. If anyone happens to be interested in this work mail me back at DONRAMAN[at]microsoft[dot]com and we can work something out together. One obvious limitation of this solution is that it will work only on WINDOWS platform with Internet Explorer installed.

I will stop now. Thanks for patient reading and till we meet again ‘Good Bye’.

Thanks,

Don.

No Comments