{"id":16675832,"url":"https://github.com/mpyw/mockery-pdo","last_synced_at":"2025-04-09T20:32:54.021Z","repository":{"id":49153568,"uuid":"290329709","full_name":"mpyw/mockery-pdo","owner":"mpyw","description":"[Experimental] BDD-style PDO Mocking Library for Mockery","archived":false,"fork":false,"pushed_at":"2025-03-05T11:12:40.000Z","size":30,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T23:37:07.854Z","etag":null,"topics":["mockery","pdo","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpyw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-25T21:41:46.000Z","updated_at":"2025-03-05T11:12:43.000Z","dependencies_parsed_at":"2025-03-05T12:32:05.180Z","dependency_job_id":null,"html_url":"https://github.com/mpyw/mockery-pdo","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Fmockery-pdo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Fmockery-pdo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Fmockery-pdo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Fmockery-pdo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpyw","download_url":"https://codeload.github.com/mpyw/mockery-pdo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107726,"owners_count":21048988,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mockery","pdo","php"],"created_at":"2024-10-12T13:08:05.731Z","updated_at":"2025-04-09T20:32:54.013Z","avatar_url":"https://github.com/mpyw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mockery PDO [![Build Status](https://github.com/mpyw/mockery-pdo/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/mockery-pdo/actions) [![Coverage Status](https://coveralls.io/repos/github/mpyw/mockery-pdo/badge.svg?branch=master)](https://coveralls.io/github/mpyw/mockery-pdo?branch=master)\n\n\u003e [!WARNING]\n\u003e **Experimental**\n\nBDD-style PDO Mocking Library for [`mockery/mockery`](https://github.com/mockery/mockery)\n\n## Requirements\n\n- PHP: `^8.2`\n- Mockery: `^1.6.12`\n\n\u003e [!NOTE]\n\u003e Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.\n\n## Installing\n\n```bash\ncomposer require mpyw/mockery-pdo:VERSION@alpha\n```\n\n## Example\n\n### SELECT\n\n#### Basic\n\n```php\n$pdo = (new MockeryPDO())-\u003emock();\n\n$pdo-\u003eshouldPrepare('select * from users where email = :email and active = :active')\n    -\u003eshouldBind()\n        -\u003evalue('email', 'John')\n        -\u003eboolValue('active', true)\n    -\u003eshouldExecute()\n    -\u003eshouldFetchAllReturns([['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1]]);\n\n$this-\u003eassertInstanceOf(\n    PDOStatement::class,\n    $stmt = $pdo-\u003eprepare('select * from users where email = :email and active = :active')\n);\n\n$this-\u003eassertTrue($stmt-\u003ebindValue('email', 'John'));\n$this-\u003eassertTrue($stmt-\u003ebindValue('active', 'John', PDO::PARAM_BOOL));\n$this-\u003eassertTrue($stmt-\u003eexecute());\n\n$this-\u003eassertSame(\n    [['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1]],\n    $stmt-\u003efetchAll()\n);\n```\n\n#### Bind values on `execute()` call\n\n```php\n$pdo = (new MockeryPDO())-\u003emock();\n\n$pdo-\u003eshouldPrepare('select * from users where email = ? and active = ?')\n    -\u003eshouldExecute(['John', '1'])\n    -\u003eshouldFetchAllReturns([['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1]]);\n\n$this-\u003eassertInstanceOf(\n    PDOStatement::class,\n    $stmt = $pdo-\u003eprepare('select * from users where email = ? and active = ?')\n);\n$this-\u003eassertTrue($stmt-\u003eexecute(['John', '1']));\n\n$this-\u003eassertSame(\n    [['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1]],\n    $stmt-\u003efetchAll()\n);\n```\n\n#### Progressively fetch rows\n\n```php\n$pdo = (new MockeryPDO())-\u003emock();\n\n$pdo-\u003eshouldPrepare('select * from users where email = :email and active = :active')\n    -\u003eshouldBind()\n        -\u003evalue('email', 'John')\n        -\u003eboolValue('active', true)\n    -\u003eshouldExecute()\n    -\u003eshouldStartFetching()\n        -\u003efetchReturns((object)['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1])\n            -\u003ewith(PDO::FETCH_OBJ)\n        -\u003efetchEnds();\n\n$this-\u003eassertInstanceOf(\n    PDOStatement::class,\n    $stmt = $pdo-\u003eprepare('select * from users where email = :email and active = :active')\n);\n\n$this-\u003eassertTrue($stmt-\u003ebindValue('email', 'John'));\n$this-\u003eassertTrue($stmt-\u003ebindValue('active', 'John', PDO::PARAM_BOOL));\n$this-\u003eassertTrue($stmt-\u003eexecute());\n\n$this-\u003eassertEquals((object)['id' =\u003e 1, 'name' =\u003e 'John', 'active' =\u003e 1], $stmt-\u003efetch(PDO::FETCH_OBJ));\n$this-\u003eassertFalse($stmt-\u003efetch());\n$this-\u003eassertFalse($stmt-\u003efetch());\n$this-\u003eassertFalse($stmt-\u003efetch());\n```\n\n### INSERT\n\n```php\n$pdo = (new MockeryPDO())-\u003emock();\n\n$pdo-\u003eshouldPrepare('insert into users(email, active) values (?, ?)')\n    -\u003eshouldExecute(['John', '1'])\n    -\u003eshouldRowCountReturns(1);\n\n$this-\u003eassertInstanceOf(\n    PDOStatement::class,\n    $stmt = $pdo-\u003eprepare('insert into users(email, active) values (?, ?)')\n);\n$this-\u003eassertTrue($stmt-\u003eexecute(['John', '1']));\n$this-\u003eassertSame(1, $stmt-\u003erowCount());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Fmockery-pdo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpyw%2Fmockery-pdo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Fmockery-pdo/lists"}