PHP code example of giberti / phpunit-local-server
1. Go to this page and download the library: Download giberti/phpunit-local-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
giberti / phpunit-local-server example snippets
use Giberti\PHPUnitLocalServer\LocalServerTestCase;
class Test extends LocalServerTestCase
{
public function testFoo() {
static::createServerWithDocroot('./tests/localhost');
$url = $this->getLocalServerUrl() . '/foo';
$content = file_get_contents($url);
$this->assertEquals('...', $content, 'Content mismatch');
}
}
use Giberti\PHPUnitLocalServer\LocalServerTestCase;
class Test extends LocalServerTestCase
{
public static function setupBeforeClass() {
static::createServerWithDocroot('./tests/localhost');
}
public function testFoo() {
$url = $this->getLocalServer() . '/foo';
$content = file_get_contents($url);
$this->assertEquals('...', $content, 'Content mismatch');
}
public function testBar() {
$url = $this->getLocalServer() . '/bar';
$content = file_get_contents($url);
$this->assertEquals('...', $content, 'Content mismatch');
}
}
use Giberti\PHPUnitLocalServer\LocalServerTestCase;
class Test73 extends LocalServerTestCase
{
static $phpBinary = '/usr/local/bin/php73';
public function testFoo() {
static::createServerWithDocroot('./tests/localhost');
$url = $this->getLocalServer() . '/foo';
$content = file_get_contents($url);
$this->assertEquals('...', $content, 'Content mismatch');
}
}
class Test81 extends LocalServerTestCase
{
static $phpBinary = '/usr/local/bin/php81';
public function testFoo() {
static::createServerWithDocroot('./tests/localhost');
$url = $this->getLocalServer() . '/foo';
$content = file_get_contents($url);
$this->assertEquals('...', $content, 'Content mismatch');
}
}