mpyw/mockery-pdo
最新稳定版本:v0.0.1-alpha9
Composer 安装命令:
composer require --dev mpyw/mockery-pdo
包简介
BDD-style PDO Mocking Library for Mockery
README 文档
README
Warning
Experimental
BDD-style PDO Mocking Library for mockery/mockery
Requirements
- PHP:
^8.2 - Mockery:
^1.6.12
Note
Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.
Installing
composer require mpyw/mockery-pdo:VERSION@alpha
Example
SELECT
Basic
$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() );
Bind values on execute() call
$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() );
Progressively fetch rows
$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());
INSERT
$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());
统计信息
- 总下载量: 8.79k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04