Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Test fixed for cacheFile
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Dec 20, 2018
1 parent 7848962 commit 22ec50b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions test/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function setUp() : void
$basedir = dirname(__DIR__) . '/app';
$this->config['base_dir'] = $basedir;
$this->config['app_dir'] = $basedir;
$this->config['cache_file'] = tempnam(sys_get_temp_dir(), 'FRT');
$this->config['cache_file'] = sys_get_temp_dir() .'/fsrt.cache';
$_SERVER = [];
$_FILES = [];
$_GET = [];
Expand Down Expand Up @@ -52,9 +52,9 @@ public function shouldExtractRouteFromURLSuccessfully($requestedPath, $folder, $
$router = new Router(
$this->config['default_return_type'],
$this->request->getMethod(),
$this->request->getUri()->getPath(),
$this->config['folder']
$this->request->getUri()->getPath()
);
$router= $router->withSubFolder($this->config['folder']);
$router->add(Router::GET, '/', 'app/main', null, 'home');
$router->add(Router::GET, '/json', 'app/json', Router::JSON);
$router->add(Router::POST, '/json', 'app/redirect', Router::REDIRECT);
Expand Down Expand Up @@ -90,14 +90,23 @@ public function shouldCacheRoutesSuccessfully() : void
$this->request->getUri()->getPath()
);
$router = $router->withSubFolder($this->config['folder'])
->withSubFolder($this->config['cache_file']);
->withCacheFile($this->config['cache_file']);

$router->add(Router::GET, '/', 'app/main', Router::HTML, 'home');
$router->getRoute();
$this->assertFileExists(
$this->config['cache_file'],
'Couldn\'t cache the file'
);
// Rest of the test should run without throwing exception
$router = new Router(
$this->config['default_return_type'],
$this->request->getMethod(),
$this->request->getUri()->getPath()
);
$router = $router->withSubFolder($this->config['folder'])
->withSubFolder($this->config['cache_file']);
$router->getRoute();
}
/**
* @test
Expand Down Expand Up @@ -132,13 +141,11 @@ public function shouldReadCacheRoutesSuccessfully($requestedPath, $folder, $expe
$router = new Router(
$this->config['default_return_type'],
$this->request->getMethod(),
$this->request->getUri()->getPath(),
$this->config['folder'],
$this->config['cache_file']
$this->request->getUri()->getPath()
);
$router = $router->withCacheFile($this->config['cache_file'])
->withSubFolder($this->config['folder']);
$router->add(Router::GET, '/', 'app/main', Router::HTML, 'home');
$r = $router->getRoute();

$router->add(Router::GET, '/', 'app/main', null, 'home');
$router->add(Router::GET, '/json', 'app/json', Router::JSON);
$router->add(Router::GET, '/json', 'app/json', Router::JSON);
Expand Down Expand Up @@ -322,8 +329,8 @@ public function shouldCorrectlyReturnNotFound() : void

public static function tearDownAfterClass() : void
{
if (file_exists('/tmp/fastroute.cache')) {
unlink('/tmp/fastroute.cache');
if (file_exists(sys_get_temp_dir() .'/fsrt.cache')) {
unlink(sys_get_temp_dir() .'/fsrt.cache');
}
if (file_exists('/tmp/failed.cache')) {
unlink('/tmp/failed.cache');
Expand Down

0 comments on commit 22ec50b

Please sign in to comment.