UtilTest.php
1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Test\Phinx\Migration;
use Phinx\Migration\Util;
class UtilTest extends \PHPUnit_Framework_TestCase
{
public function testGetCurrentTimestamp()
{
$dt = new \DateTime('now', new \DateTimeZone('UTC'));
$expected = $dt->format(Util::DATE_FORMAT);
$current = Util::getCurrentTimestamp();
// Rather than using a strict equals, we use greater/lessthan checks to
// prevent false positives when the test hits the edge of a second.
$this->assertGreaterThanOrEqual($expected, $current);
// We limit the assertion time to 2 seconds, which should never fail.
$this->assertLessThanOrEqual($expected + 2, $current);
}
public function testMapClassNameToFileName()
{
$expectedResults = array(
'CamelCase87afterSomeBooze' => '/^\d{14}_camel_case87after_some_booze\.php$/',
'CreateUserTable' => '/^\d{14}_create_user_table\.php$/',
'LimitResourceNamesTo30Chars' => '/^\d{14}_limit_resource_names_to30_chars\.php$/',
);
foreach ($expectedResults as $input => $expectedResult) {
$this->assertRegExp($expectedResult, Util::mapClassNameToFileName($input));
}
}
public function testIsValidMigrationClassName()
{
$expectedResults = array(
'CAmelCase' => false,
'CreateUserTable' => true,
'Test' => true,
'test' => false
);
foreach ($expectedResults as $input => $expectedResult) {
$this->assertEquals($expectedResult, Util::isValidMigrationClassName($input));
}
}
}