/** * testParseUrl * * @dataProvider parseUrlProvider * @return void */ public function testParseUrl($url, $expected) { $dsn = new Dsn($url); $return = $dsn->toArray(); $this->assertSame($expected, $return, 'The url should parse as expected'); $return = $dsn->__toString(); $this->assertSame($url, $return, 'The dsn should parse back to the same url'); }
/** * Return the array representation of this dsn * * @return array */ public function toArray() { $raw = $this->dsn->toArray(); $allKeys = array_unique(array_merge(static::$mandatoryKeys, array_keys($raw))); $return = []; foreach ($allKeys as $key) { if (isset($this->keyMap[$key])) { $key = $this->keyMap[$key]; if (!$key) { continue; } } $val = $this->{$key}; if ($val !== null) { $return[$key] = $val; } } return $return; }