Skip to content

Commit

Permalink
Merge 4234d77 into e88c825
Browse files Browse the repository at this point in the history
  • Loading branch information
geggleto committed Dec 17, 2015
2 parents e88c825 + 4234d77 commit 854c1b3
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,80 +12,95 @@

class ContainerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Container
*/
protected $container;

public function setUp ()
{
$this->container = new Container;
}

/**
* Test `get()` returns existing item
*/
public function testGet()
{
$c = new Container;
$this->assertInstanceOf('\Slim\Http\Environment', $c->get('environment'));
$this->assertInstanceOf('\Slim\Http\Environment', $this->container->get('environment'));
}



/**
* Test `get()` throws error if item does not exist
*
* @expectedException \Slim\Exception\ContainerValueNotFoundException
*/
public function testGetWithError()
{
$c = new Container;
$c->get('foo');
$this->container->get('foo');
}

/**
* Test container has request
*/
public function testGetRequest()
{
$c = new Container;
$this->assertInstanceOf('\Psr\Http\Message\RequestInterface', $c['request']);
$this->assertInstanceOf('\Psr\Http\Message\RequestInterface', $this->container['request']);
}

/**
* Test container has response
*/
public function testGetResponse()
{
$c = new Container;
$this->assertInstanceOf('\Psr\Http\Message\ResponseInterface', $c['response']);
$this->assertInstanceOf('\Psr\Http\Message\ResponseInterface', $this->container['response']);
}

/**
* Test container has router
*/
public function testGetRouter()
{
$c = new Container;
$this->assertInstanceOf('\Slim\Router', $c['router']);
$this->assertInstanceOf('\Slim\Router', $this->container['router']);
}

/**
* Test container has error handler
*/
public function testGetErrorHandler()
{
$c = new Container;
$this->assertInstanceOf('\Slim\Handlers\Error', $c['errorHandler']);
$this->assertInstanceOf('\Slim\Handlers\Error', $this->container['errorHandler']);
}

/**
* Test container has error handler
*/
public function testGetNotAllowedHandler()
{
$c = new Container;
$this->assertInstanceOf('\Slim\Handlers\NotAllowed', $c['notAllowedHandler']);
$this->assertInstanceOf('\Slim\Handlers\NotAllowed', $this->container['notAllowedHandler']);
}

/**
* Test settings can be edited
*/
public function testSettingsCanBeEdited()
{
$c = new Container;
$this->assertSame('1.1', $c->get('settings')['httpVersion']);
$this->assertSame('1.1', $this->container->get('settings')['httpVersion']);

$this->container->get('settings')['httpVersion'] = '1.2';
$this->assertSame('1.2', $this->container->get('settings')['httpVersion']);
}

//Test __isset
public function testMagicIssetMethod() {
$this->assertEquals(true, $this->container->__isset('settings'));
}

$c->get('settings')['httpVersion'] = '1.2';
$this->assertSame('1.2', $c->get('settings')['httpVersion']);
//test __get
public function testMagicGetMethod() {
$this->container->get('settings')['httpVersion'] = '1.2';
$this->assertSame('1.2', $this->container->__get('settings')['httpVersion']);
}
}

0 comments on commit 854c1b3

Please sign in to comment.