You test that for a given input, there is an expected output.
If I understand correctly, your QueryBuilder is collecting query parts, so make sure the datastructure holding these parts actually contains them when you add them through the QueryBuilder's method. If it has a addWhereClause
method or something like that, check that the method actually does, what you wrote into the method body, e.g. write a test like
public function testWhereMethodAddsExpressionToPartsArray()
{
$expression = 'foo = "bar"';
$this->sut->where($expression);
$parts = $this->sut->getParts('where');
$this->assertContains($expression, $parts);
}
For the SqlConstructor do the same, test that the input it gets from the datastructure you filled with the QueryBuilder (you might wanna mock it for that) produces the expected output.
If you want to test for actual validity of the SQL, write a separate testcase for that. Keep in mind that it's not the purpose of a UnitTest to ensure the SQL is correct, but that your SQLGenerator generates the SQL in the way you told it to generate it.
The problem when validating the SQL is, SQL is complex. It has a formal grammar. How much of that grammar would your test cases cover? Writing a parser for SQL doesn't sound too feasible to me, let alone one that is complete.
Related: