Skip to content

Commit

Permalink
refactor RouterTest and ResponseEmitterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
l0gicgate committed Feb 22, 2019
1 parent c64e9b0 commit af67840
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
14 changes: 7 additions & 7 deletions tests/ResponseEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
namespace Slim\Tests;

use Slim\HeaderStackTestAsset;
use Slim\ResponseEmitter;
use Slim\Tests\Assets\HeaderStack;
use Slim\Tests\Mocks\MockStream;
use Slim\Tests\Mocks\SmallChunksStream;

Expand All @@ -21,12 +21,12 @@ class ResponseEmitterTest extends TestCase
{
public function setUp()
{
HeaderStackTestAsset::reset();
HeaderStack::reset();
}

public function tearDown()
{
HeaderStackTestAsset::reset();
HeaderStack::reset();
}

public function testRespond()
Expand All @@ -47,8 +47,8 @@ public function testRespondNoContent()
$responseEmitter = new ResponseEmitter();
$responseEmitter->emit($response);

$this->assertEquals(false, HeaderStackTestAsset::has('Content-Type'));
$this->assertEquals(false, HeaderStackTestAsset::has('Content-Length'));
$this->assertEquals(false, HeaderStack::has('Content-Type'));
$this->assertEquals(false, HeaderStack::has('Content-Length'));
$this->expectOutputString('');
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function testResponseReplacesPreviouslySetHeaders()
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

$this->assertSame($expectedStack, HeaderStackTestAsset::stack());
$this->assertSame($expectedStack, HeaderStack::stack());
}

public function testResponseDoesNotReplacePreviouslySetSetCookieHeaders()
Expand All @@ -161,7 +161,7 @@ public function testResponseDoesNotReplacePreviouslySetSetCookieHeaders()
['header' => 'HTTP/1.1 200 OK', 'replace' => true, 'status_code' => 200],
];

$this->assertSame($expectedStack, HeaderStackTestAsset::stack());
$this->assertSame($expectedStack, HeaderStack::stack());
}

public function testIsResponseEmptyWithNonEmptyBodyAndTriggeringStatusCode()
Expand Down
41 changes: 34 additions & 7 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class RouterTest extends TestCase
/** @var Router */
protected $router;

/** @var string */
protected $cacheFile;

public function tearDown()
{
if (file_exists($this->cacheFile)) {
unlink($this->cacheFile);
}
}

public function setUp()
{
$callableResolver = new CallableResolver();
Expand Down Expand Up @@ -315,16 +325,33 @@ public function testPathForWithModifiedRoutePattern()
}

/**
* Test if cacheFile is not a writable directory
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Router cacheFile directory must be writable
* Test cache file exists but is not writable
*/
public function testSettingInvalidCacheFileNotExisting()
public function testCacheFileExistsAndIsNotReadable()
{
$this->router->setCacheFile(
dirname(__FILE__) . uniqid(microtime(true)) . '/' . uniqid(microtime(true))
$this->cacheFile = __DIR__ . '/non-readable.cache';
file_put_contents($this->cacheFile, '<?php return []; ?>');

$this->expectException(
'\RuntimeException',
sprintf('Router cache file `%s` is not readable', $this->cacheFile)
);

$this->router->setCacheFile($this->cacheFile);
}
/**
* Test cache file does not exist and directory is not writable
*/
public function testCacheFileDoesNotExistsAndDirectoryIsNotWritable()
{
$cacheFile = __DIR__ . '/non-writable-directory/router.cache';

$this->expectException(
'\RuntimeException',
sprintf('Router cache file directory `%s` is not writable', dirname($cacheFile))
);

$this->router->setCacheFile($cacheFile);
}

/**
Expand Down

0 comments on commit af67840

Please sign in to comment.