Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
Add tests for EncolseNames feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalaka committed Jun 26, 2015
1 parent 364fba3 commit 5ec2c6e
Showing 1 changed file with 188 additions and 0 deletions.
188 changes: 188 additions & 0 deletions Test/Unit/Query/EncloseNames.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

/**
* Hoa
*
*
* @license
*
* New BSD License
*
* Copyright © 2007-2015, Hoa community. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Hoa nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

namespace Hoa\Database\Test\Unit\Query;

use Hoa\Database\Query as CUT;
use Hoa\Test;

/**
* Class \Hoa\Database\Test\Unit\Query\EncloseNames.
*
* Test suite of EncloseNames feature.
*
* @copyright Copyright © 2007-2015 Hoa community
* @license New BSD License
*/
class EncloseNames extends Test\Unit\Suite
{
public function case_enabled()
{
$this
->given($q = new CUT())
->when(
$s = $q->select(),
$s->enableEncloseNames(),
$result = (string) $s->select('a')
->select('b')
->from('foo')
)
->then
->string($result)
->isEqualTo(
'SELECT "a", "b" FROM "foo"'
);
}

public function case_disabled()
{
$this
->given($q = new CUT())
->when(
$s = $q->select(),
$s->enableEncloseNames(false),
$result = (string) $s->select('a')
->select('b')
->from('foo')
)
->then
->string($result)
->isEqualTo(
'SELECT a, b FROM foo'
);
}

public function case_set_symbol()
{
$this
->given($q = new CUT())
->when(
$s = $q->select(),
$s->setEncloseSymbol('[', ']')
->enableEncloseNames(),
$result = (string) $s->select('a')
->select('b')
->from('foo')
)
->then
->string($result)
->isEqualTo(
'SELECT [a], [b] FROM [foo]'
);
}

public function case_select()
{
$this
->given($q = new CUT())
->when(
$s = $q->select(),
$s->enableEncloseNames(),
$result = (string) $s->select('a')
->select('b')
->from('foo')
->where('"b" > 10') // manual enclose
->groupBy('a')
->having('"a" > 42') // manual enclose
->orderBy('a')
->limit('2')
->offset('1')
)
->then
->string($result)
->isEqualTo(
'SELECT "a", "b" FROM "foo" ' .
'WHERE "b" > 10 ' .
'GROUP BY "a" ' .
'HAVING "a" > 42 ' .
'ORDER BY "a" LIMIT 2 OFFSET 1'
);
}

public function case_insert()
{
$this
->given($q = new CUT())
->when(
$i = $q->insert(),
$i->enableEncloseNames(),
$result = (string) $i->into('foo')
->on('a', 'b')
->values(1, 'bar')
)
->then
->string($result)
->isEqualTo(
'INSERT INTO "foo" ("a", "b") VALUES (1, bar)'
);
}

public function case_update()
{
$this
->given($q = new CUT())
->when(
$u = $q->update(),
$u->enableEncloseNames(),
$result = (string) $u->table('foo')
->set('a', 13)
->set('b', 'bar')
->where('"b" = 0') // manual enclose
)
->then
->string($result)
->isEqualTo(
'UPDATE "foo" SET "a" = 13, "b" = bar WHERE "b" = 0'
);
}

public function case_delete()
{
$this
->given($q = new CUT())
->when(
$d = $q->delete(),
$d->enableEncloseNames(),
$result = (string) $d->from('foo')
->where('"b" = 0') // manual enclose
)
->then
->string($result)
->isEqualTo(
'DELETE FROM "foo" WHERE "b" = 0'
);
}
}

0 comments on commit 5ec2c6e

Please sign in to comment.