-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for SQLite GUID implementation
- Loading branch information
Jan Kramer
committed
Jan 24, 2013
1 parent
315be84
commit 1bba751
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Functional\Ticket; | ||
|
||
/** | ||
* @group DBAL-421 | ||
*/ | ||
class DBAL421Test extends \Doctrine\Tests\DbalFunctionalTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$platform = $this->_conn->getDatabasePlatform()->getName(); | ||
if (!in_array($platform, array('mysql', 'sqlite'))) { | ||
$this->markTestSkipped('Currently restricted to MySQL and SQLite.'); | ||
} | ||
} | ||
|
||
public function testGuidShouldMatchPattern() | ||
{ | ||
$guid = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); | ||
$pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; | ||
$this->assertEquals(1, preg_match($pattern, $guid), "GUID does not match pattern"); | ||
} | ||
|
||
/** | ||
* This test does (of course) not proof that all generated GUIDs are | ||
* random, it should however provide some basic confidence. | ||
*/ | ||
public function testGuidShouldBeRandom() | ||
{ | ||
$statement = $this->_conn->prepare($this->getSelectGuidSql()); | ||
$guids = array(); | ||
for ($i = 0; $i < 99; $i++) | ||
{ | ||
$statement->execute(); | ||
$guid = $statement->fetchColumn(); | ||
$this->assertNotContains($guid, $guids, "Duplicate GUID detected"); | ||
$guids[] = $guid; | ||
} | ||
} | ||
|
||
private function getSelectGuidSql() | ||
{ | ||
return "SELECT " . $this->_conn->getDatabasePlatform()->getGuidExpression(); | ||
} | ||
} |