Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Larose committed Aug 21, 2013
1 parent 0b56e62 commit a893702
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/ZendTest/Db/Sql/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,70 @@ public function testGetSqlString()
$this->assertEquals('DELETE FROM "sch"."foo" WHERE x = y', $this->delete->getSqlString());
}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$deleteIgnore = new DeleteIgnore();

$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));

$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE IGNORE FROM "foo" WHERE x = y'));

$deleteIgnore->from('foo')
->where('x = y');

$deleteIgnore->prepareStatement($mockAdapter, $mockStatement);



// with TableIdentifier
$deleteIgnore = new DeleteIgnore();

$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));

$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$mockStatement->expects($this->at(2))
->method('setSql')
->with($this->equalTo('DELETE IGNORE FROM "sch"."foo" WHERE x = y'));

$deleteIgnore->from(new TableIdentifier('foo', 'sch'))
->where('x = y');

$deleteIgnore->prepareStatement($mockAdapter, $mockStatement);
}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$deleteIgnore = new DeleteIgnore();

$deleteIgnore->from('foo')
->where('x = y');
$this->assertEquals('DELETE IGNORE FROM "foo" WHERE x = y', $deleteIgnore->getSqlString());

// with TableIdentifier
$deleteIgnore = new DeleteIgnore();
$deleteIgnore->from(new TableIdentifier('foo', 'sch'))
->where('x = y');
$this->assertEquals('DELETE IGNORE FROM "sch"."foo" WHERE x = y', $deleteIgnore->getSqlString());
}
}

class DeleteIgnore extends Delete
{
const SPECIFICATION_DELETE = 'deleteIgnore';

protected $specifications = array(
self::SPECIFICATION_DELETE => 'DELETE IGNORE FROM %1$s',
self::SPECIFICATION_WHERE => 'WHERE %1$s',
);
}
72 changes: 72 additions & 0 deletions tests/ZendTest/Db/Sql/InsertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,76 @@ public function testValuesMerge()

}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$replace = new Replace();

$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
$mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));

$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$pContainer = new \Zend\Db\Adapter\ParameterContainer(array());
$mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
$mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "foo" ("bar", "boo") VALUES (?, NOW())'));

$replace->into('foo')
->values(array('bar' => 'baz', 'boo' => new Expression('NOW()')));

$replace->prepareStatement($mockAdapter, $mockStatement);

// with TableIdentifier
$replace = new Replace();

$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
$mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));

$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$pContainer = new \Zend\Db\Adapter\ParameterContainer(array());
$mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));
$mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('REPLACE INTO "sch"."foo" ("bar", "boo") VALUES (?, NOW())'));

$replace->into(new TableIdentifier('foo', 'sch'))
->values(array('bar' => 'baz', 'boo' => new Expression('NOW()')));

$replace->prepareStatement($mockAdapter, $mockStatement);
}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$replace = new Replace();
$replace->into('foo')
->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));

$this->assertEquals('REPLACE INTO "foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', $replace->getSqlString(new TrustingSql92Platform()));

// with TableIdentifier
$replace = new Replace();
$replace->into(new TableIdentifier('foo', 'sch'))
->values(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null));

$this->assertEquals('REPLACE INTO "sch"."foo" ("bar", "boo", "bam") VALUES (\'baz\', NOW(), NULL)', $replace->getSqlString(new TrustingSql92Platform()));
}
}

class Replace extends Insert
{
const SPECIFICATION_INSERT = 'replace';

protected $specifications = array(
self::SPECIFICATION_INSERT => 'REPLACE INTO %1$s (%2$s) VALUES (%3$s)'
);
}
58 changes: 58 additions & 0 deletions tests/ZendTest/Db/Sql/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,62 @@ public function testCloneUpdate()
$this->assertEquals('UPDATE "foo" SET "bar" = \'baz\' WHERE id = \'1\'', $update2->getSqlString(new TrustingSql92Platform));
}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInPrepareStatement()
{
$updateIgnore = new UpdateIgnore();

$mockDriver = $this->getMock('Zend\Db\Adapter\Driver\DriverInterface');
$mockDriver->expects($this->any())->method('getPrepareType')->will($this->returnValue('positional'));
$mockDriver->expects($this->any())->method('formatParameterName')->will($this->returnValue('?'));
$mockAdapter = $this->getMock('Zend\Db\Adapter\Adapter', null, array($mockDriver));

$mockStatement = $this->getMock('Zend\Db\Adapter\Driver\StatementInterface');
$pContainer = new \Zend\Db\Adapter\ParameterContainer(array());
$mockStatement->expects($this->any())->method('getParameterContainer')->will($this->returnValue($pContainer));

$mockStatement->expects($this->at(1))
->method('setSql')
->with($this->equalTo('UPDATE IGNORE "foo" SET "bar" = ?, "boo" = NOW() WHERE x = y'));

$updateIgnore->table('foo')
->set(array('bar' => 'baz', 'boo' => new Expression('NOW()')))
->where('x = y');

$updateIgnore->prepareStatement($mockAdapter, $mockStatement);
}

/**
* @coversNothing
*/
public function testSpecificationconstantsCouldBeOverridedByExtensionInGetSqlString()
{
$this->update = new UpdateIgnore();

$this->update->table('foo')
->set(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null))
->where('x = y');

$this->assertEquals('UPDATE IGNORE "foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()));

// with TableIdentifier
$this->update = new UpdateIgnore();
$this->update->table(new TableIdentifier('foo', 'sch'))
->set(array('bar' => 'baz', 'boo' => new Expression('NOW()'), 'bam' => null))
->where('x = y');

$this->assertEquals('UPDATE IGNORE "sch"."foo" SET "bar" = \'baz\', "boo" = NOW(), "bam" = NULL WHERE x = y', $this->update->getSqlString(new TrustingSql92Platform()));
}
}

class UpdateIgnore extends Update
{
const SPECIFICATION_UPDATE = 'updateIgnore';

protected $specifications = array(
self::SPECIFICATION_UPDATE => 'UPDATE IGNORE %1$s SET %2$s',
self::SPECIFICATION_WHERE => 'WHERE %1$s'
);
}

0 comments on commit a893702

Please sign in to comment.