Skip to content

Commit

Permalink
Test credentials as string without password (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lloople authored Jul 29, 2020
1 parent cd1e0e5 commit 2625da9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ public function toString(): string
$this->dbName
);

if (strpos($asString, ':@') === 0) {
return rawurldecode(
substr($asString, 2)
);
}

return rawurldecode(
str_replace(':@', '', $asString)
str_replace(':@', '@', $asString)
);
}
}
55 changes: 55 additions & 0 deletions tests/CredentialsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of the DriftPHP Project
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author David Llop <[email protected]>
*/

declare(strict_types=1);

namespace Drift\DBAL\Tests;

use Drift\DBAL\Credentials;
use PHPUnit\Framework\TestCase;

/**
* Class ConnectionTest.
*/
class CredentialsTest extends TestCase
{
/**
* Test that credentials works as expected with all the fields filled.
*/
public function testCredentialsCanBeConvertedToString()
{
$credentials = new Credentials('127.0.0.1', '3306', 'user', 'password', 'database');

$this->assertEquals('user:[email protected]:3306/database', $credentials->toString());
}

/**
* Test that credentials works as expected without login information.
*/
public function testCredentialsCanBeConvertedToStringWithoutLogin()
{
$credentials = new Credentials('127.0.0.1', '3306', '', '', 'database');

$this->assertEquals('127.0.0.1:3306/database', $credentials->toString());
}

/**
* Test that credentials works as expected without password.
*/
public function testCredentialsCanBeConvertedToStringWithoutPassword()
{
$credentials = new Credentials('127.0.0.1', '3306', 'user', '', 'database');

$this->assertEquals('[email protected]:3306/database', $credentials->toString());
}
}

0 comments on commit 2625da9

Please sign in to comment.