for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Pagerfanta\Tests\Adapter;
use Pagerfanta\Adapter\MongoAdapter;
use PHPUnit\Framework\TestCase;
class MongoAdapterTest extends TestCase
{
protected $cursor;
/**
* @var MongoAdapter
*/
protected $adapter;
protected function setUp()
if ($this->isMongoNotAvailable()) {
$this->markTestSkipped('Mongo is not available.');
}
$this->cursor = $this->createCursorMock();
$this->adapter = new MongoAdapter($this->cursor);
$this->cursor
object<PHPUnit\Framework\MockObject\MockObject>
object<MongoCursor>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
private function isMongoNotAvailable()
return !extension_loaded('mongo');
private function createCursorMock()
return $this
->getMockBuilder('\MongoCursor')
->disableOriginalConstructor()
->getMock();
public function testGetCursor()
$this->assertSame($this->cursor, $this->adapter->getCursor());
public function testGetNbResultsShouldReturnTheCursorCount()
->expects($this->once())
->method('count')
->will($this->returnValue(100));
$this->assertSame(100, $this->adapter->getNbResults());
public function testGetSliceShouldPassTheOffsetAndLengthToTheCursor()
$offset = 12;
$length = 16;
->method('limit')
->with($length);
->method('skip')
->with($offset);
$this->adapter->getSlice($offset, $length);
public function testGetSliceShouldReturnTheCursor()
->expects($this->any())
->method('limit');
->method('skip');
$this->assertSame($this->cursor, $this->adapter->getSlice(1, 1));
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: