Skip to content

Commit

Permalink
Add UT & fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mdumoulin committed Apr 12, 2021
1 parent d844ed5 commit 5663448
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/ForwardCompatibility/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function execute($params = null)
);

if ($this->stmt instanceof DriverStatement) {
return $this->stmt->execute();
return $this->stmt->execute($params);
}

throw Exception::notSupported('execute');
Expand Down
120 changes: 117 additions & 3 deletions tests/Doctrine/Tests/DBAL/ForwardCompatibility/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Doctrine\Tests\DBAL\ForwardCompatibility;

use Doctrine\DBAL\Cache\ArrayStatement;
use Doctrine\DBAL\Driver\ResultStatement as DriverResultStatement;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\ForwardCompatibility\Result;
use Doctrine\DBAL\ParameterType;
use PDO;
use PHPUnit\Framework\TestCase;
use Traversable;
Expand Down Expand Up @@ -335,15 +336,128 @@ public function testIterateColumn(): void
);
}

public function testRowCountIsSupportedByWrappedStatement(): void
public function testRowCountIsSupportedByWrappedArrayStatement(): void
{
$this->assertSame(3, $this->instance->rowCount());
}

public function testRowCountIsNotSupportedByWrappedStatement(): void
{
$this->expectExceptionObject(Exception::notSupported('rowCount'));
$instance = new Result($this->createMock(DriverResultStatement::class));
$instance = new Result($this->createMock(Driver\ResultStatement::class));
$instance->rowCount();
}

public function testBindValueIsSupportedByWrappedStatement(): void
{
$param = ':key';
$value = 'value';

$statement = $this->createMock(Driver\Statement::class);
$statement
->expects($this->once())
->method('bindValue')
->with($param, $value, ParameterType::STRING)
->willReturn(true);

$instance = new Result($statement);

$this->assertTrue($instance->bindValue($param, $value));
}

public function testBindValueIsNotSupportedByWrappedResultStatement(): void
{
$this->expectExceptionObject(Exception::notSupported('bindValue'));
$this->instance->bindValue(':key', 'value');
}

public function testBindParamIsSupportedByWrappedStatement(): void
{
$param = ':key';
$value = 'value';

$statement = $this->createMock(Driver\Statement::class);
$statement
->expects($this->once())
->method('bindParam')
->with($param, $value, ParameterType::STRING)
->willReturn(true);

$instance = new Result($statement);

$this->assertTrue($instance->bindParam($param, $value));
}

public function testBindParamIsNotSupportedByWrappedResultStatement(): void
{
$param = ':key';
$value = 'value';

$this->expectExceptionObject(Exception::notSupported('bindParam'));
$this->instance->bindParam($param, $value);
}

public function testErrorCodeIsSupportedByWrappedStatement(): void
{
$errorCode = 32;

$statement = $this->createMock(Driver\Statement::class);
$statement
->expects($this->once())
->method('errorCode')
->willReturn($errorCode);

$instance = new Result($statement);

$this->assertSame($errorCode, $instance->errorCode());
}

public function testErrorCodeIsNotSupportedByWrappedResultStatement(): void
{
$this->expectExceptionObject(Exception::notSupported('errorCode'));
$this->instance->errorCode();
}

public function testErrorInfoIsSupportedByWrappedStatement(): void
{
$errorInfo = ['Some info'];

$statement = $this->createMock(Driver\Statement::class);
$statement
->expects($this->once())
->method('errorInfo')
->willReturn($errorInfo);

$instance = new Result($statement);

$this->assertSame($errorInfo, $instance->errorInfo());
}

public function testErrorInfoIsNotSupportedByWrappedResultStatement(): void
{
$this->expectExceptionObject(Exception::notSupported('errorInfo'));
$this->instance->errorInfo();
}

public function testExecuteIsSupportedByWrappedStatement(): void
{
$params = [':key' => 'value'];

$statement = $this->createMock(Driver\Statement::class);
$statement
->expects($this->once())
->method('execute')
->with($params)
->willReturn(true);

$instance = new Result($statement);

$this->assertTrue($instance->execute($params));
}

public function testExecuteIsNotSupportedByWrappedResultStatement(): void
{
$this->expectExceptionObject(Exception::notSupported('execute'));
$this->instance->execute([':key' => 'value']);
}
}

0 comments on commit 5663448

Please sign in to comment.