blob: ede3d3a5c00b0f4b7a0b9ba4b3eaa354d6a514be (
plain)
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
|
<?php
use PicoDb\UrlParser;
require_once __DIR__.'/../../../vendor/autoload.php';
class UrlParserTest extends PHPUnit_Framework_TestCase
{
public function testParseUrl()
{
$urlParser = UrlParser::getInstance();
$this->assertFalse($urlParser->isEnvironmentVariableDefined());
$settings = $urlParser->getSettings('postgres://user:pass@hostname:6212/db');
$this->assertEquals('postgres', $settings['driver']);
$this->assertEquals('user', $settings['username']);
$this->assertEquals('pass', $settings['password']);
$this->assertEquals('hostname', $settings['hostname']);
$this->assertEquals('6212', $settings['port']);
$this->assertEquals('db', $settings['database']);
}
public function testParseWrongUrl()
{
$urlParser = new UrlParser();
$settings = $urlParser->getSettings('/');
$this->assertEmpty($settings['driver']);
$this->assertFalse($urlParser->isEnvironmentVariableDefined());
}
public function testGetUrlFromEnvironment()
{
putenv('DATABASE_URL=postgres://user:pass@hostname:6212/db');
$urlParser = new UrlParser();
$this->assertTrue($urlParser->isEnvironmentVariableDefined());
$settings = $urlParser->getSettings();
$this->assertEquals('postgres', $settings['driver']);
$this->assertEquals('user', $settings['username']);
$this->assertEquals('pass', $settings['password']);
$this->assertEquals('hostname', $settings['hostname']);
$this->assertEquals('6212', $settings['port']);
$this->assertEquals('db', $settings['database']);
}
}
|