/** * When called will return the credential contents as an associative array. */ public function testWhenCalledWillReturnTheCredentialContentsAsAnAssociativeArray() { $object = MySQLCredentials::build(StringLiteral::fromNative($this->username), StringLiteral::fromNative($this->password), StringLiteral::fromNative($this->hostnameLiteral), StringLiteral::fromNative($this->database)); $response = $object->toArray(); $expected = ['username' => 'Alphanum_123', 'password' => 'Alphanum1234567890-=~!#$%^&*()[]_+?<>', 'host' => 'localhost', 'database' => 'employees_2016']; static::assertEquals($expected, $response); }
/** * @param string $credentialsInline * * @return CredentialsInterface * @throws \Exception */ public function buildCredentialsFromInlineFormat($credentialsInline) { preg_match(self::REGEX_CREDENTIALS_INLINE, $credentialsInline, $match); if (count($match) === 5) { array_shift($match); } else { throw new \Exception('Invalid credentials format.'); } $username = StringLiteral::fromNative($match[0]); $password = StringLiteral::fromNative($match[1]); $host = StringLiteral::fromNative($match[2]); $database = StringLiteral::fromNative($match[3]); $credentials = MySQLCredentials::build($username, $password, $host, $database); return $credentials; }