From 869012f3286f00997fc788162432a4a946c9ac32 Mon Sep 17 00:00:00 2001 From: shatterproof <4100078+shatterproof@users.noreply.github.com> Date: Sun, 10 Jul 2022 23:33:35 -0700 Subject: [PATCH 1/4] Add colon to database cache driver prefix --- src/Illuminate/Cache/DatabaseStore.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/DatabaseStore.php b/src/Illuminate/Cache/DatabaseStore.php index b43761b1e39c..b6c14f9b07ec 100755 --- a/src/Illuminate/Cache/DatabaseStore.php +++ b/src/Illuminate/Cache/DatabaseStore.php @@ -75,7 +75,7 @@ public function __construct(ConnectionInterface $connection, $lockLottery = [2, 100]) { $this->table = $table; - $this->prefix = $prefix; + $this->setPrefix($prefix); $this->connection = $connection; $this->lockTable = $lockTable; $this->lockLottery = $lockLottery; @@ -360,6 +360,17 @@ public function getPrefix() { return $this->prefix; } + + /** + * Set the cache key prefix. + * + * @param string $prefix + * @return void + */ + public function setPrefix($prefix) + { + $this->prefix = ! empty($prefix) ? $prefix.':' : ''; + } /** * Serialize the given value. From 9bd7250330dd52aed184672e7bf75a5bcae907e7 Mon Sep 17 00:00:00 2001 From: shatterproof <4100078+shatterproof@users.noreply.github.com> Date: Mon, 11 Jul 2022 00:53:09 -0700 Subject: [PATCH 2/4] Fix tests --- tests/Cache/CacheDatabaseStoreTest.php | 34 +++++++++++++------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/Cache/CacheDatabaseStoreTest.php b/tests/Cache/CacheDatabaseStoreTest.php index ac98021eb87c..4a27493bb87b 100755 --- a/tests/Cache/CacheDatabaseStoreTest.php +++ b/tests/Cache/CacheDatabaseStoreTest.php @@ -23,7 +23,7 @@ public function testNullIsReturnedWhenItemNotFound() $store = $this->getStore(); $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', '=', 'prefix:foo')->andReturn($table); $table->shouldReceive('first')->once()->andReturn(null); $this->assertNull($store->get('foo')); @@ -34,7 +34,7 @@ public function testNullIsReturnedAndItemDeletedWhenItemIsExpired() $store = $this->getMockBuilder(DatabaseStore::class)->onlyMethods(['forget'])->setConstructorArgs($this->getMocks())->getMock(); $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', '=', 'prefix:foo')->andReturn($table); $table->shouldReceive('first')->once()->andReturn((object) ['expiration' => 1]); $store->expects($this->once())->method('forget')->with($this->equalTo('foo'))->willReturn(null); @@ -46,7 +46,7 @@ public function testDecryptedValueIsReturnedWhenItemIsValid() $store = $this->getStore(); $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', '=', 'prefix:foo')->andReturn($table); $table->shouldReceive('first')->once()->andReturn((object) ['value' => serialize('bar'), 'expiration' => 999999999999999]); $this->assertSame('bar', $store->get('foo')); @@ -57,7 +57,7 @@ public function testValueIsReturnedOnPostgres() $store = $this->getPostgresStore(); $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', '=', 'prefix:foo')->andReturn($table); $table->shouldReceive('first')->once()->andReturn((object) ['value' => base64_encode(serialize('bar')), 'expiration' => 999999999999999]); $this->assertSame('bar', $store->get('foo')); @@ -69,7 +69,7 @@ public function testValueIsInsertedWhenNoExceptionsAreThrown() $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); $store->expects($this->once())->method('getTime')->willReturn(1); - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnTrue(); + $table->shouldReceive('insert')->once()->with(['key' => 'prefix:foo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnTrue(); $result = $store->put('foo', 'bar', 60); $this->assertTrue($result); @@ -81,10 +81,10 @@ public function testValueIsUpdatedWhenInsertThrowsException() $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->with('table')->andReturn($table); $store->expects($this->once())->method('getTime')->willReturn(1); - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnUsing(function () { + $table->shouldReceive('insert')->once()->with(['key' => 'prefix:foo', 'value' => serialize('bar'), 'expiration' => 61])->andReturnUsing(function () { throw new Exception; }); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('update')->once()->with(['value' => serialize('bar'), 'expiration' => 61])->andReturnTrue(); $result = $store->put('foo', 'bar', 60); @@ -97,7 +97,7 @@ public function testValueIsInsertedOnPostgres() $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); $store->expects($this->once())->method('getTime')->willReturn(1); - $table->shouldReceive('insert')->once()->with(['key' => 'prefixfoo', 'value' => base64_encode(serialize("\0")), 'expiration' => 61])->andReturnTrue(); + $table->shouldReceive('insert')->once()->with(['key' => 'prefix:foo', 'value' => base64_encode(serialize("\0")), 'expiration' => 61])->andReturnTrue(); $result = $store->put('foo', "\0", 60); $this->assertTrue($result); @@ -116,7 +116,7 @@ public function testItemsMayBeRemovedFromCache() $store = $this->getStore(); $table = m::mock(stdClass::class); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', '=', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', '=', 'prefix:foo')->andReturn($table); $table->shouldReceive('delete')->once(); $store->forget('foo'); @@ -143,7 +143,7 @@ public function testIncrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn(null); $this->assertFalse($store->increment('foo')); @@ -153,7 +153,7 @@ public function testIncrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn($cache); $this->assertFalse($store->increment('foo')); @@ -163,11 +163,11 @@ public function testIncrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn($cache); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('update')->once()->with(['value' => serialize(3)]); $this->assertEquals(3, $store->increment('foo')); } @@ -182,7 +182,7 @@ public function testDecrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn(null); $this->assertFalse($store->decrement('foo')); @@ -192,7 +192,7 @@ public function testDecrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixfoo')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:foo')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn($cache); $this->assertFalse($store->decrement('foo')); @@ -202,11 +202,11 @@ public function testDecrementReturnsCorrectValues() return $closure(); }); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixbar')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:bar')->andReturn($table); $table->shouldReceive('lockForUpdate')->once()->andReturn($table); $table->shouldReceive('first')->once()->andReturn($cache); $store->getConnection()->shouldReceive('table')->once()->with('table')->andReturn($table); - $table->shouldReceive('where')->once()->with('key', 'prefixbar')->andReturn($table); + $table->shouldReceive('where')->once()->with('key', 'prefix:bar')->andReturn($table); $table->shouldReceive('update')->once()->with(['value' => serialize(2)]); $this->assertEquals(2, $store->decrement('bar')); } From 5e6aae7011dd18c40dafa0f1d5e0e069cef27b14 Mon Sep 17 00:00:00 2001 From: shatterproof <4100078+shatterproof@users.noreply.github.com> Date: Mon, 11 Jul 2022 00:59:47 -0700 Subject: [PATCH 3/4] Remove trailing whitespace --- phpunit.xml.dist | 2 +- src/Illuminate/Cache/DatabaseStore.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cc45c172e33c..f6f1ee4613c8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ convertWarningsToExceptions="true" printerClass="Illuminate\Tests\IgnoreSkippedPrinter" processIsolation="false" - stopOnError="false" + stopOnError="true" stopOnFailure="false" verbose="true" > diff --git a/src/Illuminate/Cache/DatabaseStore.php b/src/Illuminate/Cache/DatabaseStore.php index b6c14f9b07ec..ed04b5601411 100755 --- a/src/Illuminate/Cache/DatabaseStore.php +++ b/src/Illuminate/Cache/DatabaseStore.php @@ -360,7 +360,7 @@ public function getPrefix() { return $this->prefix; } - + /** * Set the cache key prefix. * From 9ec7790d265dd2e3455d00a5120c6d560ac31643 Mon Sep 17 00:00:00 2001 From: shatterproof <4100078+shatterproof@users.noreply.github.com> Date: Mon, 11 Jul 2022 01:12:36 -0700 Subject: [PATCH 4/4] Reset phpunit stopOnError --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f6f1ee4613c8..cc45c172e33c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ convertWarningsToExceptions="true" printerClass="Illuminate\Tests\IgnoreSkippedPrinter" processIsolation="false" - stopOnError="true" + stopOnError="false" stopOnFailure="false" verbose="true" >