diff --git a/Tests/Unit/Delete/DeleteQueryBuilderTest.php b/Tests/Unit/Delete/DeleteQueryBuilderTest.php index a52929feca0507f97949d13ac406e28750697fc9..be97ae6b07ca0bbd18fae57020419388d7f95721 100644 --- a/Tests/Unit/Delete/DeleteQueryBuilderTest.php +++ b/Tests/Unit/Delete/DeleteQueryBuilderTest.php @@ -96,4 +96,18 @@ class DeleteQueryBuilderTest extends TestCase ->getName() ); } + + /** + * Test reset of builder + * + * @covers DeleteQueryBuilder::resetBuilder() + * @covers DeleteQueryBuilder::$deleteQuery + */ + public function testResetOfBuilder() + { + $entryGenerator = $this->entryDeleteGeneratorFactory(); + $newBuilder = new MySqlBuilder(); + $entryGenerator->resetBuilder( $newBuilder ); + $this->assertSame( $newBuilder, $entryGenerator->getBuilder( ) ); + } } diff --git a/Tests/Unit/Select/SelectQueryBuilderTest.php b/Tests/Unit/Select/SelectQueryBuilderTest.php index 2c3c8f191944db5e83977ac030e97db54570e370..f3a1555eacb3abdf823e2503e5e0592458786beb 100644 --- a/Tests/Unit/Select/SelectQueryBuilderTest.php +++ b/Tests/Unit/Select/SelectQueryBuilderTest.php @@ -109,4 +109,17 @@ class SelectQueryBuilderTest extends TestCase $this->assertEquals(Entry::DESC, 'DESC'); $this->assertEquals(EntryValues::DESC, 'DESC'); } + + /** + * Test reset of builder + * + * @covers SelectQueryBuilder::resetBuilder() + */ + public function testResetOfBuilder() + { + $entryGenerator = $this->entryGeneratorFactory(); + $newBuilder = new MySqlBuilder(); + $entryGenerator->resetBuilder( $newBuilder ); + $this->assertSame( $newBuilder, $entryGenerator->getBuilder( ) ); + } } diff --git a/src/CreatesSqlQueries.php b/src/CreatesSqlQueries.php index 546475ddffdfb8a05da757029ba5fe4165ef0030..dde46005eba8754232d13dde7b3885df87488baa 100644 --- a/src/CreatesSqlQueries.php +++ b/src/CreatesSqlQueries.php @@ -31,4 +31,12 @@ interface CreatesSqlQueries * @return MySqlBuilder */ public function getBuilder(); + + /** + * Reset the query builder + * + * @param MySqlBuilder|null $builder New builder or null to use default empty + * @return $this + */ + public function resetBuilder( MySqlBuilder $builder = null ); } diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 67ef15c6a313e1d7ea3e6f9b965247e548357f51..22b17f394ca7b842b4ea9654519d2346f291f800 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -44,6 +44,18 @@ abstract class QueryBuilder implements CreatesSqlQueries $this->tableName = $tableName; } + /** @inheritdoc */ + public function resetBuilder(MySqlBuilder $builder = null) + { + if( ! $builder ){ + $builder = new MySqlBuilder(); + } + + $this->builder = $builder; + return $this; + + } + /** * @return AbstractBaseQuery */ diff --git a/src/Select/SelectQueryBuilder.php b/src/Select/SelectQueryBuilder.php index 16f8fbf92d94ca36849ef7e0cccdfae6f867242b..57891b5984bc8d73ce220e6e4c0de5073a09e368 100644 --- a/src/Select/SelectQueryBuilder.php +++ b/src/Select/SelectQueryBuilder.php @@ -47,4 +47,6 @@ abstract class SelectQueryBuilder extends QueryBuilder implements DoesSelectQuer $this->getCurrentQuery()->orderBy($column, $order); return $this; } + + }