From 7f8f1bea0e8ca0499c8336ccab935e235b4dd8a3 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Tue, 17 May 2022 16:29:40 +0100 Subject: [PATCH 1/2] Ported laravel cache provider without implementing deferable --- src/Cache/CacheServiceProvider.php | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Cache/CacheServiceProvider.php diff --git a/src/Cache/CacheServiceProvider.php b/src/Cache/CacheServiceProvider.php new file mode 100644 index 000000000..96aad0052 --- /dev/null +++ b/src/Cache/CacheServiceProvider.php @@ -0,0 +1,52 @@ +app->singleton('cache', function ($app) { + return new CacheManager($app); + }); + + $this->app->singleton('cache.store', function ($app) { + return $app['cache']->driver(); + }); + + $this->app->singleton('cache.psr6', function ($app) { + return new Psr16Adapter($app['cache.store']); + }); + + $this->app->singleton('memcached.connector', function () { + return new MemcachedConnector; + }); + + $this->app->singleton(RateLimiter::class, function ($app) { + return new RateLimiter($app->make('cache')->driver( + $app['config']->get('cache.limiter') + )); + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return [ + 'cache', 'cache.store', 'cache.psr6', 'memcached.connector', RateLimiter::class, + ]; + } +} From b87d4b4013851ba0f30b244f30bc29b6657fcd58 Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Tue, 31 May 2022 17:44:38 +0100 Subject: [PATCH 2/2] Removed upsert tests ref: 04230d5ec44cf0b5f354e918f2c5a6079936339f --- tests/Database/QueryBuilderTest.php | 86 ----------------------------- 1 file changed, 86 deletions(-) diff --git a/tests/Database/QueryBuilderTest.php b/tests/Database/QueryBuilderTest.php index 56d67aedd..e8c23c85f 100644 --- a/tests/Database/QueryBuilderTest.php +++ b/tests/Database/QueryBuilderTest.php @@ -94,92 +94,6 @@ public function testSelectConcat() ); } - public function testUpsert() - { - // MySQL - $builder = $this->getMySqlBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into `users` (`email`, `name`) values (?, ?), (?, ?) on duplicate key update `email` = values(`email`), `name` = values(`name`)', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email'); - $this->assertEquals(2, $result); - - // PostgreSQL - $builder = $this->getPostgresBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "email" = "excluded"."email", "name" = "excluded"."name"', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email'); - $this->assertEquals(2, $result); - - // SQLite - $builder = $this->getSQLiteBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "email" = "excluded"."email", "name" = "excluded"."name"', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email'); - $this->assertEquals(2, $result); - - // SQL Server - $builder = $this->getSqlServerBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('merge [users] using (values (?, ?), (?, ?)) [laravel_source] ([email], [name]) on [laravel_source].[email] = [users].[email] when matched then update set [email] = [laravel_source].[email], [name] = [laravel_source].[name] when not matched then insert ([email], [name]) values ([email], [name]);', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email'); - $this->assertEquals(2, $result); - } - - public function testUpsertWithUpdateColumns() - { - // MySQL - $builder = $this->getMySqlBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into `users` (`email`, `name`) values (?, ?), (?, ?) on duplicate key update `name` = values(`name`)', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email', ['name']); - $this->assertEquals(2, $result); - - // PostgreSQL - $builder = $this->getPostgresBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "name" = "excluded"."name"', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email', ['name']); - $this->assertEquals(2, $result); - - // SQLite - $builder = $this->getSQLiteBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('insert into "users" ("email", "name") values (?, ?), (?, ?) on conflict ("email") do update set "name" = "excluded"."name"', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email', ['name']); - $this->assertEquals(2, $result); - - // SQL Server - $builder = $this->getSqlServerBuilder(); - $builder->getConnection() - ->expects($this->once()) - ->method('affectingStatement') - ->with('merge [users] using (values (?, ?), (?, ?)) [laravel_source] ([email], [name]) on [laravel_source].[email] = [users].[email] when matched then update set [name] = [laravel_source].[name] when not matched then insert ([email], [name]) values ([email], [name]);', ['foo', 'bar', 'foo2', 'bar2']) - ->willReturn(2); - $result = $builder->from('users')->upsert([['email' => 'foo', 'name' => 'bar'], ['name' => 'bar2', 'email' => 'foo2']], 'email', ['name']); - $this->assertEquals(2, $result); - } - protected function getConnection($connection = null) { if ($connection) {