From 9fafdbd082289e12d2f0d8dc0d2e49b3ca646c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Thu, 19 May 2022 18:12:50 -0300 Subject: [PATCH] Fixes `Tests\RoutingTest::testGetDispatcher` test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/phpmyadmin/phpmyadmin/issues/17532. Signed-off-by: MaurĂ­cio Meneghini Fauth --- test/classes/RoutingTest.php | 68 ++++++++++++++---------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/test/classes/RoutingTest.php b/test/classes/RoutingTest.php index ef8c412843..b7677e0a4a 100644 --- a/test/classes/RoutingTest.php +++ b/test/classes/RoutingTest.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Controllers\HomeController; use PhpMyAdmin\Routing; use function copy; +use function unlink; use const CACHE_DIR; use const ROOT_PATH; @@ -23,58 +24,41 @@ class RoutingTest extends AbstractTestCase */ public function testGetDispatcher(): void { - $dispatcher = Routing::getDispatcher(); - $this->assertInstanceOf(Dispatcher::class, $dispatcher); - $this->assertSame( - [Dispatcher::FOUND, HomeController::class, []], - $dispatcher->dispatch('GET', '/') - ); - } - - public function testGetDispatcherWithValidCacheFile(): void - { + $expected = [Dispatcher::FOUND, HomeController::class, []]; + $cacheFilename = CACHE_DIR . 'routes.cache.php'; + $validCacheFilename = ROOT_PATH . 'test/test_data/routes/routes-valid.cache.txt'; + $invalidCacheFilename = ROOT_PATH . 'test/test_data/routes/routes-invalid.cache.txt'; $GLOBALS['cfg']['environment'] = null; $this->assertDirectoryIsWritable(CACHE_DIR); - $this->assertTrue(copy( - ROOT_PATH . 'test/test_data/routes/routes-valid.cache.txt', - CACHE_DIR . 'routes.cache.php' - )); + // Valid cache file. + $this->assertTrue(copy($validCacheFilename, $cacheFilename)); $dispatcher = Routing::getDispatcher(); $this->assertInstanceOf(Dispatcher::class, $dispatcher); - $this->assertSame( - [Dispatcher::FOUND, HomeController::class, []], - $dispatcher->dispatch('GET', '/') - ); - - $this->assertFileEquals( - CACHE_DIR . 'routes.cache.php', - ROOT_PATH . 'test/test_data/routes/routes-valid.cache.txt' - ); - } - - public function testGetDispatcherWithInvalidCacheFile(): void - { - $GLOBALS['cfg']['environment'] = null; - - $this->assertDirectoryIsWritable(CACHE_DIR); - $this->assertTrue(copy( - ROOT_PATH . 'test/test_data/routes/routes-invalid.cache.txt', - CACHE_DIR . 'routes.cache.php' - )); + $this->assertSame($expected, $dispatcher->dispatch('GET', '/')); + $this->assertFileEquals($validCacheFilename, $cacheFilename); + // Invalid cache file. + $this->assertTrue(copy($invalidCacheFilename, $cacheFilename)); $dispatcher = Routing::getDispatcher(); $this->assertInstanceOf(Dispatcher::class, $dispatcher); - $this->assertSame( - [Dispatcher::FOUND, HomeController::class, []], - $dispatcher->dispatch('GET', '/') - ); + $this->assertSame($expected, $dispatcher->dispatch('GET', '/')); + $this->assertFileNotEquals($invalidCacheFilename, $cacheFilename); - $this->assertFileNotEquals( - CACHE_DIR . 'routes.cache.php', - ROOT_PATH . 'test/test_data/routes/routes-invalid.cache.txt' - ); + // Create new cache file. + $this->assertTrue(unlink($cacheFilename)); + $this->assertFileNotExists($cacheFilename); + $dispatcher = Routing::getDispatcher(); + $this->assertInstanceOf(Dispatcher::class, $dispatcher); + $this->assertSame($expected, $dispatcher->dispatch('GET', '/')); + $this->assertFileExists($cacheFilename); + + // Without a cache file. + $GLOBALS['cfg']['environment'] = 'development'; + $dispatcher = Routing::getDispatcher(); + $this->assertInstanceOf(Dispatcher::class, $dispatcher); + $this->assertSame($expected, $dispatcher->dispatch('GET', '/')); } /**