From ea6b02a1f5c2fd09f7ba9d3ef5d95e39cd3eed6d Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <hypolite@mrpetovan.com>
Date: Tue, 16 Jul 2019 00:19:04 -0400
Subject: [PATCH] Fix PConfiguration tests

- Replace uid = 0 (invalid uid) with 42
- Remove isConnected mocked calls for invalid uid test
---
 .../src/Core/Config/JitPConfigurationTest.php | 11 +-------
 tests/src/Core/Config/PConfigurationTest.php  | 26 ++++++++++---------
 .../Core/Config/PreloadPConfigurationTest.php | 12 +--------
 3 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/tests/src/Core/Config/JitPConfigurationTest.php b/tests/src/Core/Config/JitPConfigurationTest.php
index 4eafb43b3d..8ceea93ff4 100644
--- a/tests/src/Core/Config/JitPConfigurationTest.php
+++ b/tests/src/Core/Config/JitPConfigurationTest.php
@@ -116,15 +116,6 @@ class JitPConfigurationTest extends PConfigurationTest
 		parent::testGetWithRefresh($uid, $data);
 	}
 
-	public function testGetWrongWithoutDB()
-	{
-		$this->configModel->shouldReceive('isConnected')
-		                  ->andReturn(false)
-		                  ->times(3);
-
-		parent::testGetWrongWithoutDB();
-	}
-
 	/**
 	 * @dataProvider dataTests
 	 */
@@ -145,7 +136,7 @@ class JitPConfigurationTest extends PConfigurationTest
 
 		// mocking one get without result
 		$this->configModel->shouldReceive('get')
-		                  ->with(0, 'test', 'it')
+		                  ->with(42, 'test', 'it')
 		                  ->andReturn(null)
 		                  ->once();
 
diff --git a/tests/src/Core/Config/PConfigurationTest.php b/tests/src/Core/Config/PConfigurationTest.php
index 5554731bfd..40c6970a5c 100644
--- a/tests/src/Core/Config/PConfigurationTest.php
+++ b/tests/src/Core/Config/PConfigurationTest.php
@@ -365,22 +365,24 @@ abstract class PConfigurationTest extends MockedTest
 	 */
 	public function testDeleteWithDB()
 	{
-		$this->configCache->load(0, ['test' => ['it' => 'now', 'quarter' => 'true']]);
+		$uid = 42;
+
+		$this->configCache->load($uid, ['test' => ['it' => 'now', 'quarter' => 'true']]);
 
 		$this->configModel->shouldReceive('delete')
-		                  ->with(0, 'test', 'it')
+		                  ->with($uid, 'test', 'it')
 		                  ->andReturn(false)
 		                  ->once();
 		$this->configModel->shouldReceive('delete')
-		                  ->with(0, 'test', 'second')
+		                  ->with($uid, 'test', 'second')
 		                  ->andReturn(true)
 		                  ->once();
 		$this->configModel->shouldReceive('delete')
-		                  ->with(0, 'test', 'third')
+		                  ->with($uid, 'test', 'third')
 		                  ->andReturn(false)
 		                  ->once();
 		$this->configModel->shouldReceive('delete')
-		                  ->with(0, 'test', 'quarter')
+		                  ->with($uid, 'test', 'quarter')
 		                  ->andReturn(true)
 		                  ->once();
 
@@ -388,19 +390,19 @@ abstract class PConfigurationTest extends MockedTest
 		$this->assertInstanceOf(PConfigCache::class, $this->testedConfig->getCache());
 
 		// directly set the value to the cache
-		$this->testedConfig->getCache()->set(0, 'test', 'it', 'now');
+		$this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
 
-		$this->assertEquals('now', $this->testedConfig->get(0, 'test', 'it'));
-		$this->assertEquals('now', $this->testedConfig->getCache()->get(0, 'test', 'it'));
+		$this->assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
+		$this->assertEquals('now', $this->testedConfig->getCache()->get($uid, 'test', 'it'));
 
 		// delete from cache only
-		$this->assertTrue($this->testedConfig->delete(0, 'test', 'it'));
+		$this->assertTrue($this->testedConfig->delete($uid, 'test', 'it'));
 		// delete from db only
-		$this->assertTrue($this->testedConfig->delete(0, 'test', 'second'));
+		$this->assertTrue($this->testedConfig->delete($uid, 'test', 'second'));
 		// no delete
-		$this->assertFalse($this->testedConfig->delete(0, 'test', 'third'));
+		$this->assertFalse($this->testedConfig->delete($uid, 'test', 'third'));
 		// delete both
-		$this->assertTrue($this->testedConfig->delete(0, 'test', 'quarter'));
+		$this->assertTrue($this->testedConfig->delete($uid, 'test', 'quarter'));
 
 		$this->assertEmpty($this->testedConfig->getCache()->getAll());
 	}
diff --git a/tests/src/Core/Config/PreloadPConfigurationTest.php b/tests/src/Core/Config/PreloadPConfigurationTest.php
index ca916d4404..270a7a2e0b 100644
--- a/tests/src/Core/Config/PreloadPConfigurationTest.php
+++ b/tests/src/Core/Config/PreloadPConfigurationTest.php
@@ -108,16 +108,6 @@ class PreloadPConfigurationTest extends PConfigurationTest
 		parent::testGetWithRefresh($uid, $data);
 	}
 
-
-	public function testGetWrongWithoutDB()
-	{
-		$this->configModel->shouldReceive('isConnected')
-		                  ->andReturn(false)
-		                  ->times(3);
-
-		parent::testGetWrongWithoutDB();
-	}
-
 	/**
 	 * @dataProvider dataTests
 	 */
@@ -138,7 +128,7 @@ class PreloadPConfigurationTest extends PConfigurationTest
 
 		// constructor loading
 		$this->configModel->shouldReceive('load')
-		                  ->with(0)
+		                  ->with(42)
 		                  ->andReturn(['config' => []])
 		                  ->once();
 
-- 
2.39.5