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, + ]; + } +} 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) {