1. Go to this page and download the library: Download mpyw/mockery-pdo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mpyw / mockery-pdo example snippets
$pdo = (new MockeryPDO())->mock();
$pdo->shouldPrepare('select * from users where email = :email and active = :active')
->shouldBind()
->value('email', 'John')
->boolValue('active', true)
->shouldExecute()
->shouldFetchAllReturns([['id' => 1, 'name' => 'John', 'active' => 1]]);
$this->assertInstanceOf(
PDOStatement::class,
$stmt = $pdo->prepare('select * from users where email = :email and active = :active')
);
$this->assertTrue($stmt->bindValue('email', 'John'));
$this->assertTrue($stmt->bindValue('active', 'John', PDO::PARAM_BOOL));
$this->assertTrue($stmt->execute());
$this->assertSame(
[['id' => 1, 'name' => 'John', 'active' => 1]],
$stmt->fetchAll()
);
$pdo = (new MockeryPDO())->mock();
$pdo->shouldPrepare('select * from users where email = ? and active = ?')
->shouldExecute(['John', '1'])
->shouldFetchAllReturns([['id' => 1, 'name' => 'John', 'active' => 1]]);
$this->assertInstanceOf(
PDOStatement::class,
$stmt = $pdo->prepare('select * from users where email = ? and active = ?')
);
$this->assertTrue($stmt->execute(['John', '1']));
$this->assertSame(
[['id' => 1, 'name' => 'John', 'active' => 1]],
$stmt->fetchAll()
);
$pdo = (new MockeryPDO())->mock();
$pdo->shouldPrepare('select * from users where email = :email and active = :active')
->shouldBind()
->value('email', 'John')
->boolValue('active', true)
->shouldExecute()
->shouldStartFetching()
->fetchReturns((object)['id' => 1, 'name' => 'John', 'active' => 1])
->with(PDO::FETCH_OBJ)
->fetchEnds();
$this->assertInstanceOf(
PDOStatement::class,
$stmt = $pdo->prepare('select * from users where email = :email and active = :active')
);
$this->assertTrue($stmt->bindValue('email', 'John'));
$this->assertTrue($stmt->bindValue('active', 'John', PDO::PARAM_BOOL));
$this->assertTrue($stmt->execute());
$this->assertEquals((object)['id' => 1, 'name' => 'John', 'active' => 1], $stmt->fetch(PDO::FETCH_OBJ));
$this->assertFalse($stmt->fetch());
$this->assertFalse($stmt->fetch());
$this->assertFalse($stmt->fetch());
$pdo = (new MockeryPDO())->mock();
$pdo->shouldPrepare('insert into users(email, active) values (?, ?)')
->shouldExecute(['John', '1'])
->shouldRowCountReturns(1);
$this->assertInstanceOf(
PDOStatement::class,
$stmt = $pdo->prepare('insert into users(email, active) values (?, ?)')
);
$this->assertTrue($stmt->execute(['John', '1']));
$this->assertSame(1, $stmt->rowCount());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.