<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

/**
 * Generated by PHPUnit_SkeletonGenerator on 2018-07-10 at 08:07:04.
 */
class SelectQueryBuilderTest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var DBOperation
   */
  protected $object;

  /**
   * Sets up the fixture, for example, opens a network connection.
   * This method is called before a test is executed.
   */
  protected function setUp(): void
  {
    $this->object = new DBOperationMySQLi(array(), 1);
  }

  /**
   * @test
   * @covers SelectQueryBuilder::getCondition
   */
  public function getCondition_NoOperation_Empty()
  {
    $builder = new SelectQueryBuilder($this->object);
    $this->assertEquals('', $builder->getCondition());
  }

  /**
   * @test
   * @covers SelectQueryBuilder::addToWhere
   */
  public function addToWhere_AddSpaces_Empty()
  {
    $builder = new SelectQueryBuilder($this->object);
    $builder->addToWhere('');
    $this->assertEquals('', $builder->getCondition());
    $builder->addToWhere('    ');
    $this->assertEquals('', $builder->getCondition());
  }

  /**
   * @test
   * @covers SelectQueryBuilder::addToWhere
   */
  public function addToWhere_AddExpr_Expr()
  {
    $builder = new SelectQueryBuilder($this->object);
    $builder->addToWhere('(1=1)');
    $this->assertEquals('(1=1)', $builder->getCondition());
  }

  /**
   * @test
   * @covers SelectQueryBuilder::and
   */
  public function and_AddToNothing_Expr()
  {
    $builder = new SelectQueryBuilder($this->object);
    $builder->and('(1=1)');
    $this->assertEquals('(1=1)', $builder->getCondition());
  }

  /**
   * @test
   * @covers SelectQueryBuilder::and
   */
  public function and_AddToExpr_ExprAndExpr()
  {
    $builder = new SelectQueryBuilder($this->object);
    $builder->where('(1=1)');
    $builder->and('(1=1)');
    $this->assertEquals('(1=1) AND (1=1)', $builder->getCondition());
  }

  /**
   * @test
   * @covers SelectQueryBuilder::and
   */
  public function and_AddToExprWithOpeningBrace_BraceExpr()
  {
    $builder = new SelectQueryBuilder($this->object);
    $builder->where('(');
    $builder->and('(1=1)');
    $this->assertEquals('( (1=1)', $builder->getCondition());
  }
}
