1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Platform; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\SqlitePlatform; |
6
|
|
|
use Doctrine\DBAL\Statement; |
7
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
8
|
|
|
use function end; |
9
|
|
|
|
10
|
|
|
class GuidExpressionTest extends DbalFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
public function testGuidShouldMatchPattern() |
13
|
|
|
{ |
14
|
|
|
$value = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); |
15
|
|
|
|
16
|
|
|
self::assertRegExp( |
17
|
|
|
'/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i', |
18
|
|
|
$value |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This test does (of course) not proof that all generated GUIDs are |
24
|
|
|
* random, it should however provide some basic confidence. |
25
|
|
|
*/ |
26
|
|
|
public function testGuidShouldBeUniqueAndAscending() |
27
|
|
|
{ |
28
|
|
|
$platform = $this->_conn->getDatabasePlatform(); |
29
|
|
|
|
30
|
|
|
if ($platform instanceof SqlitePlatform) { |
31
|
|
|
$this->markTestSkipped('Currently incorrectly implemented in SQLite platform'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$statement = $this->_conn->prepare($this->getSelectGuidSql()); |
35
|
|
|
$values = [$this->generateGuid($statement)]; |
36
|
|
|
|
37
|
|
|
for ($i = 0; $i < 99; $i++) { |
38
|
|
|
$statement->execute(); |
39
|
|
|
$value = $statement->fetchColumn(); |
40
|
|
|
|
41
|
|
|
self::assertNotContains($value, $values, 'Duplicate value detected'); |
42
|
|
|
self::assertGreaterThan(end($values), $value); |
43
|
|
|
|
44
|
|
|
$values[] = $value; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$statement->closeCursor(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function generateGuid(Statement $statement) : string |
51
|
|
|
{ |
52
|
|
|
$statement->execute(); |
53
|
|
|
|
54
|
|
|
return $statement->fetchColumn(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function getSelectGuidSql() |
58
|
|
|
{ |
59
|
|
|
$platform = $this->_conn->getDatabasePlatform(); |
60
|
|
|
|
61
|
|
|
return $platform->getDummySelectSQL( |
62
|
|
|
$platform->getGuidExpression() |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|