-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
no issue - fix filename and :memory: detection in dsn
- Loading branch information
Showing
3 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -25,6 +25,26 @@ public function testBasics(): void | |
self::assertNull($dsn->getOption('non_existing_option')); | ||
} | ||
|
||
public function testUserPassAreDecoded(): void | ||
{ | ||
$dsn = Dsn::fromString('pdo_mysql://some%20user:some%[email protected]:1234/some_database'); | ||
|
||
self::assertSame('some user', $dsn->getUser()); | ||
self::assertSame('some password', $dsn->getPassword()); | ||
} | ||
|
||
public function testNoSchemeRaiseException(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
Dsn::fromString('some%20user:some%[email protected]/bla'); | ||
} | ||
|
||
public function testNoHostRaiseException(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
Dsn::fromString('oauth://some%20user:some%20password@?foo=bar'); | ||
} | ||
|
||
public function testWithFilename(): void | ||
{ | ||
$dsn = Dsn::fromString('sqlite:///some/path.db?server=sqlite-3'); | ||
|
@@ -34,33 +54,86 @@ public function testWithFilename(): void | |
self::assertSame('any', $dsn->getDriver()); | ||
self::assertSame('sqlite-3', $dsn->getOption('server')); | ||
self::assertSame('/some/path.db', $dsn->getHost()); | ||
self::assertSame('/some/path.db', $dsn->getDatabase()); | ||
self::assertSame('/some/path.db', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
} | ||
|
||
public function testUserPassAreDecoded(): void | ||
public function testSQLiteEdgeCaseRelative(): void | ||
{ | ||
$dsn = Dsn::fromString('pdo_mysql://some%20user:some%[email protected]:1234/some_database'); | ||
$dsn = Dsn::fromString('pdo-sqlite://ignored:ignored@ignored:1234/somedb.sqlite'); | ||
|
||
self::assertSame('some user', $dsn->getUser()); | ||
self::assertSame('some password', $dsn->getPassword()); | ||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame('somedb.sqlite', $dsn->getFilename()); | ||
self::assertSame('somedb.sqlite', $dsn->getHost()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
} | ||
|
||
public function testNoDatabaseRaiseException(): void | ||
public function testSQLiteEdgeCaseAbsolute(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
Dsn::fromString('pdo_mysql://some%20user:some%[email protected]'); | ||
$dsn = Dsn::fromString('pdo-sqlite://ignored:ignored@ignored:1234//somedb.sqlite'); | ||
|
||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame('/somedb.sqlite', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
self::assertSame('/somedb.sqlite', $dsn->getHost()); | ||
} | ||
|
||
public function testNoSchemeRaiseException(): void | ||
public function testSQLiteEdgeCaseNoHostRelative(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
Dsn::fromString('some%20user:some%[email protected]/bla'); | ||
$dsn = Dsn::fromString('pdo-sqlite://ignored:[email protected]'); | ||
|
||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame('somedb.sqlite', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
|
||
self::assertSame('somedb.sqlite', $dsn->getHost()); | ||
} | ||
|
||
public function testNoHostRaiseException(): void | ||
public function testSQLiteEdgeCaseNoHostAbsolute(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
Dsn::fromString('oauth://some%20user:some%20password@?foo=bar'); | ||
self::markTestSkipped("We sure cannot handle every typo error from our users."); | ||
|
||
/* | ||
$dsn = Dsn::fromString('pdo-sqlite://ignored:ignored@/somedb.sqlite'); | ||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame('/somedb.sqlite', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
self::assertSame('/somedb.sqlite', $dsn->getHost()); | ||
*/ | ||
} | ||
|
||
public function testSQLiteEdgeCaseMemoryRelative(): void | ||
{ | ||
$dsn = Dsn::fromString('pdo-sqlite://:memory:'); | ||
|
||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame(':memory:', $dsn->getHost()); | ||
self::assertSame(':memory:', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
} | ||
|
||
public function testSQLiteEdgeCaseMemoryAbsolute(): void | ||
{ | ||
$dsn = Dsn::fromString('pdo-sqlite:///:memory:'); | ||
|
||
self::assertTrue($dsn->isFile()); | ||
self::assertSame('sqlite', $dsn->getVendor()); | ||
self::assertSame('pdo', $dsn->getDriver()); | ||
self::assertSame(':memory:', $dsn->getHost()); | ||
self::assertSame(':memory:', $dsn->getFilename()); | ||
self::assertSame('default', $dsn->getDatabase()); | ||
} | ||
|
||
public function testToUrl(): void | ||
|