Skip to content

Commit

Permalink
AppTest: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jabernardo committed Feb 12, 2018
1 parent afee211 commit 86ab2c7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/AppTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

if (file_exists('PHPUnit/Autoload.php'))
require_once('PHPUnit/Autoload.php');

// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') &&
class_exists('\PHPUnit_Framework_TestCase')) {
class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}

class AppTest extends \PHPUnit\Framework\TestCase
{
public function testApp() {
$container = new \Calf\Saddle();
$container->message = 'Hello World!';

$this->assertEquals($container->message, 'Hello World!');

$app = new \Calf\App($container);

$this->assertTrue($app instanceof \Calf\App);

$c = $app->getContainer();

$this->assertTrue($c instanceof \Calf\Saddle);

$r = $app->getRouter();

$this->assertTrue($r instanceof \Calf\HTTP\Router);

$_SERVER = [];
$_SERVER['REQUEST_URI'] = '/';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER["SCRIPT_NAME"] = '/index.php';

$home = new \Calf\HTTP\Route('/', function($req, $res) {
return $res->write('Hello World!');
});

$app->add($home);

$res = $app->run(true);

ob_start();
$app->run();
$output = ob_get_contents();
ob_end_clean();

$this->assertEquals($output, 'Hello World!');
$this->assertEquals($res->get(), 'Hello World!');
$this->assertTrue($res instanceof \Calf\HTTP\Response);
}
}

0 comments on commit 86ab2c7

Please # to comment.