Skip to content

Commit

Permalink
doctrine#6167 - code cleanup for 2.5.x version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Snigirev committed Nov 27, 2017
1 parent a857a61 commit a23e909
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Mocks/ConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function fetchColumn($statement, array $params = [], $colnum = 0, array $
/**
* {@inheritdoc}
*/
public function query() : Statement
public function query()
{
return $this->_queryResult;
}
Expand Down
65 changes: 65 additions & 0 deletions tests/Doctrine/Tests/Mocks/StatementArrayMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Doctrine\Tests\Mocks;


/**
* Simple statement mock that returns result based on array.
* Doesn't support fetch modes
*/
class StatementArrayMock extends StatementMock
{
/**
* @var array
*/
private $_result;

public function __construct($result)
{
$this->_result = $result;
}

public function getIterator()
{
return new \ArrayIterator($this->_result);
}

public function columnCount()
{
$row = reset($this->_result);
if ($row) {
return count($row);
} else {
return 0;
}
}

public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
return $this->_result;
}

public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
$current = current($this->_result);
next($this->_result);

return $current;
}

public function fetchColumn($columnIndex = 0)
{
$current = current($this->_result);
if ($current) {
next($this->_result);
return reset($current);
} else {
return false;
}
}

public function rowCount()
{
return count($this->_result);
}
}
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ class SequenceGeneratorTest extends OrmTestCase
*/
private $connection;

protected function setUp() : void
protected function setUp()
{
parent::setUp();

$this->entityManager = $this->_getTestEntityManager();
$this->sequenceGenerator = new SequenceGenerator('seq', 10);
$this->connection = $this->entityManager->getConnection();

self::assertInstanceOf(ConnectionMock::class, $this->connection);
self::assertInstanceOf('Doctrine\Tests\Mocks\ConnectionMock', $this->connection);
}

public function testGeneration() : void
public function testGeneration()
{
$this->connection->setFetchOneException(new \BadMethodCallException(
'Fetch* method used. Query method should be used instead, '
Expand Down

0 comments on commit a23e909

Please sign in to comment.