{"id":16675812,"url":"https://github.com/mpyw/laravel-database-mock","last_synced_at":"2025-04-09T20:32:54.072Z","repository":{"id":45681438,"uuid":"290715695","full_name":"mpyw/laravel-database-mock","owner":"mpyw","description":"[Experimental] Database Mocking Library which mocks PDO underlying Laravel Connection classes","archived":false,"fork":false,"pushed_at":"2025-03-05T11:25:04.000Z","size":22,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-01T23:37:07.817Z","etag":null,"topics":["database","eloquent","laravel","mock","mockery","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-27T08:07:41.000Z","updated_at":"2025-03-05T11:24:41.000Z","dependencies_parsed_at":"2023-11-21T18:52:04.968Z","dependency_job_id":null,"html_url":"https://github.com/mpyw/laravel-database-mock","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.0714285714285714,"last_synced_commit":"3813d2342e7fd2992d1378c493fdc9573bc7d616"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Flaravel-database-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Flaravel-database-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Flaravel-database-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpyw%2Flaravel-database-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpyw","download_url":"https://codeload.github.com/mpyw/laravel-database-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107727,"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":["database","eloquent","laravel","mock","mockery","php"],"created_at":"2024-10-12T13:07:57.175Z","updated_at":"2025-04-09T20:32:54.064Z","avatar_url":"https://github.com/mpyw.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Database Mock [![Build Status](https://github.com/mpyw/laravel-database-mock/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/laravel-database-mock/actions) [![Coverage Status](https://coveralls.io/repos/github/mpyw/laravel-database-mock/badge.svg?branch=master)](https://coveralls.io/github/mpyw/laravel-database-mock?branch=master)\n\n\u003e [!WARNING]\n\u003e **Experimental**\n\nDatabase Mocking Library which mocks `PDO` underlying Laravel Connection classes.\n\n## Requirements\n\n- PHP: `^8.2`\n- Laravel: `^11.0 || ^12.0`\n- Mockery: `^1.6.12`\n- [mpyw/mockery-pdo](https://github.com/mpyw/mockery-pdo): `alpha`\n\n## Installing\n\n```bash\ncomposer require mpyw/laravel-database-mock:VERSION@alpha\n```\n\n## Example\n\n### SELECT\n\n```php\n$pdo = DBMock::mockPdo();\n$pdo-\u003eshouldSelect('select * from `users`')\n    -\u003eshouldFetchAllReturns([[\n        'id' =\u003e 1,\n        'name' =\u003e 'John',\n        'email' =\u003e 'john@example.com',\n        'created_at' =\u003e '2020-01-01 00:00:00',\n        'updated_at' =\u003e '2020-01-01 00:00:00',\n    ]]);\n\n$this-\u003eassertEquals([[\n    'id' =\u003e 1,\n    'name' =\u003e 'John',\n    'email' =\u003e 'john@example.com',\n    'created_at' =\u003e '2020-01-01T00:00:00.000000Z',\n    'updated_at' =\u003e '2020-01-01T00:00:00.000000Z',\n]], User::all()-\u003etoArray());\n```\n\n### INSERT\n\n```php\nCarbon::setTestNow('2020-01-01 00:00:00');\n\n$pdo = DBMock::mockPdo();\n$pdo-\u003eshouldInsert(\n    'insert into `users` (`name`, `email`, `updated_at`, `created_at`) values (?, ?, ?, ?)',\n    ['John', 'john@example.com', '2020-01-01 00:00:00', '2020-01-01 00:00:00']\n);\n$pdo-\u003eexpects('lastInsertId')-\u003eandReturn(2);\n\n$user = new User();\n$user-\u003eforceFill(['name' =\u003e 'John', 'email' =\u003e 'john@example.com'])-\u003esave();\n$this-\u003eassertEquals([\n    'id' =\u003e 2,\n    'name' =\u003e 'John',\n    'email' =\u003e 'john@example.com',\n    'created_at' =\u003e '2020-01-01T00:00:00.000000Z',\n    'updated_at' =\u003e '2020-01-01T00:00:00.000000Z',\n], $user-\u003etoArray());\n```\n\n### UPDATE\n\n#### Basic\n\n```php\nCarbon::setTestNow('2020-01-02 00:00:00');\n\n$pdo = DBMock::mockPdo();\n$pdo-\u003eshouldSelect('select * from `users` where `email` = ? limit 1', ['john@example.com'])\n    -\u003eshouldFetchAllReturns([[\n        'id' =\u003e 2,\n        'name' =\u003e 'John',\n        'email' =\u003e 'john@example.com',\n        'created_at' =\u003e '2020-01-01 00:00:00',\n        'updated_at' =\u003e '2020-01-01 00:00:00',\n    ]]);\n$pdo-\u003eshouldUpdateOne(\n    'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ?',\n    ['john-01@example.com', '2020-01-02 00:00:00', 2]\n);\n\n$user = User::query()-\u003ewhere('email', 'john@example.com')-\u003efirst();\n$user-\u003eforceFill(['email' =\u003e 'john-01@example.com'])-\u003esave();\n$this-\u003eassertEquals([\n    'id' =\u003e 2,\n    'name' =\u003e 'John',\n    'email' =\u003e 'john-01@example.com',\n    'created_at' =\u003e '2020-01-01T00:00:00.000000Z',\n    'updated_at' =\u003e '2020-01-02T00:00:00.000000Z',\n], $user-\u003etoArray());\n```\n\n#### Using Read Replica\n\n```php\nCarbon::setTestNow('2020-01-02 00:00:00');\n\n$pdos = DBMock::mockEachPdo();\n$pdos-\u003ereader()\n    -\u003eshouldSelect('select * from `users` where `email` = ? limit 1', ['john@example.com'])\n    -\u003eshouldFetchAllReturns([[\n        'id' =\u003e 2,\n        'name' =\u003e 'John',\n        'email' =\u003e 'john@example.com',\n        'created_at' =\u003e '2020-01-01 00:00:00',\n        'updated_at' =\u003e '2020-01-01 00:00:00',\n    ]]);\n$pdos-\u003ewriter()\n    -\u003eshouldUpdateOne(\n        'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ?',\n        ['john-01@example.com', '2020-01-02 00:00:00', 2]\n    );\n\n$user = User::query()-\u003ewhere('email', 'john@example.com')-\u003efirst();\n$user-\u003eforceFill(['email' =\u003e 'john-01@example.com'])-\u003esave();\n$this-\u003eassertEquals([\n    'id' =\u003e 2,\n    'name' =\u003e 'John',\n    'email' =\u003e 'john-01@example.com',\n    'created_at' =\u003e '2020-01-01T00:00:00.000000Z',\n    'updated_at' =\u003e '2020-01-02T00:00:00.000000Z',\n], $user-\u003etoArray());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Flaravel-database-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpyw%2Flaravel-database-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpyw%2Flaravel-database-mock/lists"}