PHPackages                             jimbojsb/pseudo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jimbojsb/pseudo

ActiveLibrary[Testing &amp; Quality](/categories/testing)

jimbojsb/pseudo
===============

PDO/MySQL Connection Mocking

0.5(4y ago)6680.8k—9.4%25[2 issues](https://github.com/jimbojsb/pseudo/issues)[1 PRs](https://github.com/jimbojsb/pseudo/pulls)5MITPHPCI failing

Since May 6Pushed 4y ago5 watchersCompare

[ Source](https://github.com/jimbojsb/pseudo)[ Packagist](https://packagist.org/packages/jimbojsb/pseudo)[ RSS](/packages/jimbojsb-pseudo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (12)Used By (5)

Pseudo
======

[](#pseudo)

Pseudo is a system for mocking PHP's PDO database connections. When writing unit tests for PHP applications, one frequently has the need to test code that interacts with a database. However, in the true spirit of a unit test, the database should be abstracted, as we can assume with some degree of certainty that things like network links to the database server, the database connection drivers, and the database server and software itself are "going to work", and they are outside the scope of our unit tests.

Enter Pseudo. Pseudo allows you to have "fake" interactions with a database that produce predefined results every time. This has 2 main advantages over actually interacting with a database. First, it saves having to write data fixtures in another format, ensuring the data schema availability, loading the fixtures in, and then later cleaing and resetting them between tests. Second, and somewhat as a result of the first, tests can run *significantly* faster because they are essentially talking to an in-memory object structure rather than incurring all the overhead of connecting and interacting with an actual database.

Theory of Operation
-------------------

[](#theory-of-operation)

The general idea is that Pseudo implements all of the classes in the PDO system by inheriting from them and then overriding their methods. During your test, at the point where you would inject a PDO object into your data layer, you can now inject a Pseudo\\Pdo object transparently, giving yourself 100% flexibility to control what your application now *thinks* is the database. In your unit test, you can express the mocks for your test in terms of SQL statements and arrays of result data.

### Simple Example

[](#simple-example)

```
