Use some type hinting in the comments to implement a more generic connection method for the DB handler.
This commit is contained in:
parent
1b14f1523b
commit
730777a5ca
@ -6,7 +6,10 @@ use PDO;
|
||||
|
||||
interface DatabaseHandlerInterface
|
||||
{
|
||||
public function getConnection(): PDO;
|
||||
/**
|
||||
* @return mixed The return must be an active connection to a database.
|
||||
*/
|
||||
public function getConnection();
|
||||
|
||||
/**
|
||||
* Get the connection string required for establishing connections to the
|
||||
|
@ -19,7 +19,10 @@ class DatabaseHandler implements DatabaseHandlerInterface
|
||||
$this->pdo = new PDO($this->getDsn(), $username, $password);
|
||||
}
|
||||
|
||||
public function getConnection(): PDO
|
||||
/**
|
||||
* @return PDO For this particular Handler we will return the PDO objectg
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->pdo;
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ use Slovocast\Domain\Repository\User\UserRepository;
|
||||
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
||||
use Slovocast\Tests\TestCase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
|
||||
class UserRepositoryTest extends TestCase
|
||||
{
|
||||
@ -14,7 +16,10 @@ class UserRepositoryTest extends TestCase
|
||||
$user = $this->getUserFromArray();
|
||||
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
||||
|
||||
$databaseHandler->insert()->willReturn(true);
|
||||
$databaseHandler->insert(
|
||||
Argument::type('string'),
|
||||
Argument::type('array')
|
||||
)->willReturn(true);
|
||||
$databaseHandler->getConnection()->willReturn(new class {
|
||||
public function lastInsertId(): int
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user