Newer
Older
<?php
namespace Breyta\Test;
use Mockery\Adapter\Phpunit\MockeryTestCase;
abstract class TestCase extends MockeryTestCase
{
protected $pdo;
protected function setUp()
{
$pdo = $this->pdo = m::mock(\PDO::class);
$pdo->shouldReceive('setAttribute')->with(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION)
->andReturn(true)->byDefault();
$pdo->shouldReceive('beginTransaction')->byDefault();
$pdo->shouldReceive('commit')->byDefault();
$pdo->shouldReceive('rollback')->byDefault();
$pdo->shouldReceive('query')->andReturn(false)->byDefault();
}
protected function mockPreparedStatement(string $pattern, $byDefault = false, $defaultResult = 1)
{
$statement = m::mock(\PDOStatement::class);
$statement->shouldReceive('execute')->byDefault()->andReturn($defaultResult);
$expectation = $this->pdo->shouldReceive('prepare')->with(m::pattern($pattern));
if ($byDefault) {
$expectation->byDefault()->andReturn($statement);
} else {
$expectation->once()->andReturn($statement);
}
return $statement;
}