2017 © Pedro Peláez
 

library fakeserverconf

Fill the $_SERVER array with various PHP server configuration for unit tests.

image

jelix/fakeserverconf

Fill the $_SERVER array with various PHP server configuration for unit tests.

  • Thursday, March 5, 2015
  • by laurentj
  • Repository
  • 3 Watchers
  • 10 Stars
  • 1,526 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 6 % Grown

The README.md

This PHP Library will allow you to simulate different PHP server configuration., (*1)

In a CLI environment (where you run PHPUnit for instance), you could have some difficulties to test a class that uses some $_SERVER values. This global variable does not contain the same thing as if the script is called in an Apache environment for example. Moreover the content of $_SERVER is not the same between a server configured with mod_php, and a server running PHP as a CGI, as FPM etc.., (*2)

FakeServerConf allow you to fill automatically $_SERVER with good values (and $_GET, $_POST...), only by given an URL to "virtual" PHP server., (*3)

You don't need anymore to setup several real PHP HTTP server to test your libraries in different environment. Just call FakeServerConf in your unit tests., (*4)

For example, in your test, you want to have a $_SERVER filled as if the URL "http://testapp.local/info.php/foo/bar?baz=2" was requested. In your PHPUnit/Atoum/Simpletest/whatever class, call this:, (*5)

    // let's says we are running an Apache server configured with mod_php.
    // Indicate to this server the script name (it can be hidden in the http request)
    $server = new \Jelix\FakeServerConf\ApacheMod(null, '/info.php');

    // now simulate an HTTP request
    $server->setHttpRequest('http://testapp.local/info.php/foo/bar?baz=2');

$_SERVER is now filled correctly, and you can test your classes (routers, url parser etc...), (*6)

You can also set the document root and other things..., (*7)

Supported servers

  • Apache + mod_php
  • Apache + php-cgi
  • Apache + mod_fastcgi + php-fpm

Adding servers

You don't find your server configuration in FakeServerConf? Help us to provide additionnal support., (*8)

  • First configure your server. It's better if it's a fresh installation in a virtual machine. You should install the curl extension for php.
  • Configure a virtual host named "testapp.local". It should accept multiviews queries (without .php)
  • The document root of the server should be /var/www/ and it should content files you can find in tests/www. You can also set the document root to tests/www.
  • In your browser, call http://testapp.local/generateserverdata.php. It generates some PHP code that you have to add into a test class in tests/. See existing test class.
  • Create a new class in src/jelix/FakeServerConf, that inherits from FakeServerConf
  • In your test class, you should instantiate this class
  • Run tests with phpunit, and fix in your new class the issues detected in your tests.
  • Don't touch the FakeServerConf class except if it makes sens for all server configuration.

installing

You can use Composer. Into your composer.json file, add, (*9)

"require": {
    "jelix/fakeserverconf": "1.0.0"
}

running test

Install phpunit (run composer install) and launch it into the tests/ directory, (*10)

cd tests
../vendor/bin/phpunit
# or if you installed phpunit globally:
phpunit

The Versions

05/03 2015

dev-master

9999999-dev

Fill the $_SERVER array with various PHP server configuration for unit tests.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

_server php configuration unit tests

05/03 2015

v1.0.0

1.0.0.0

Fill the $_SERVER array with various PHP server configuration for unit tests.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

_server php configuration unit tests

15/11 2012

v1.0.0-beta

1.0.0.0-beta

Fill the $_SERVER array with various PHP server configuration for unit tests.

  Sources   Download

MIT

The Requires

  • php >=5.3.0