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
|
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
|
* 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);
|
$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;
|
return $this->pdo;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ use Slovocast\Domain\Repository\User\UserRepository;
|
|||||||
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
use Slovocast\Infrastructure\Api\Database\DatabaseHandlerInterface;
|
||||||
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
use Slovocast\Infrastructure\User\BasicUserAuthorization;
|
||||||
use Slovocast\Tests\TestCase;
|
use Slovocast\Tests\TestCase;
|
||||||
|
use Prophecy\Argument;
|
||||||
|
|
||||||
|
|
||||||
class UserRepositoryTest extends TestCase
|
class UserRepositoryTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -14,7 +16,10 @@ class UserRepositoryTest extends TestCase
|
|||||||
$user = $this->getUserFromArray();
|
$user = $this->getUserFromArray();
|
||||||
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
$databaseHandler = $this->prophesize(DatabaseHandlerInterface::class);
|
||||||
|
|
||||||
$databaseHandler->insert()->willReturn(true);
|
$databaseHandler->insert(
|
||||||
|
Argument::type('string'),
|
||||||
|
Argument::type('array')
|
||||||
|
)->willReturn(true);
|
||||||
$databaseHandler->getConnection()->willReturn(new class {
|
$databaseHandler->getConnection()->willReturn(new class {
|
||||||
public function lastInsertId(): int
|
public function lastInsertId(): int
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user