shouldReceive('escape')->with('foo', false)->andReturn("'foo'"); $grammar = new MySqlGrammar($connection); $query = $grammar->substituteBindingsIntoRawSql( 'select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = ?', ['foo'], ); $this->assertSame('select * from "users" where \'Hello\\\'World?\' IS NOT NULL AND "email" = \'foo\'', $query); } public function testTimeout() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->where('email', 'like', '%test%')->timeout(60); $this->assertSame( 'select /*+ MAX_EXECUTION_TIME(60000) */ * from `users` where `email` like ?', $builder->toSql() ); } public function testTimeoutWithDistinct() { $builder = $this->getBuilder(); $builder->distinct()->select('*')->from('users')->timeout(30); $this->assertSame( 'select /*+ MAX_EXECUTION_TIME(30000) */ distinct * from `users`', $builder->toSql() ); } public function testTimeoutWithAggregate() { $builder = $this->getBuilder(); $builder->from('users')->timeout(10); $builder->aggregate = ['function' => 'count', 'columns' => ['*']]; $this->assertSame( 'select /*+ MAX_EXECUTION_TIME(10000) */ count(*) as aggregate from `users`', $builder->toSql() ); } public function testTimeoutNullRemovesTimeout() { $builder = $this->getBuilder(); $builder->select('*')->from('users')->timeout(60)->timeout(null); $this->assertSame('select * from `users`', $builder->toSql()); } public function testTimeoutThrowsExceptionForNegativeValue() { $this->expectException(InvalidArgumentException::class); $builder = $this->getBuilder(); $builder->select('*')->from('users')->timeout(-1); } protected function getBuilder() { $connection = m::mock(Connection::class); $connection->shouldReceive('getDatabaseName')->andReturn('database'); $connection->shouldReceive('getTablePrefix')->andReturn(''); $grammar = new MySqlGrammar($connection); $processor = m::mock(Processor::class); return new Builder($connection, $grammar, $processor); } }