Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose database mock implementation #313

Closed
kiesel opened this issue May 24, 2016 · 3 comments
Closed

Expose database mock implementation #313

kiesel opened this issue May 24, 2016 · 3 comments

Comments

@kiesel
Copy link
Member

kiesel commented May 24, 2016

Scope of Change

The available mock implementation for database access that currently lives in src/test in the package rdbms.unittest.mock will be exposed to third party use by moving it tinto src/main and thus including it in the publicly available API.

Rationale

Occurrances of usage have been observed; while it was possible to pick up the package, even though it was a test package, it is no longer possible since the introduction of Composer. Tests could benefit from being able to use mocks.

Functionality

The available classes would be:

  • rdbms.unittest.mock.MockConnection
  • rdbms.unittest.mock.MockResultSet
  • rdbms.unittest.mock.MockDialect
  • rdbms.unittest.mock.RegisterMockConnection (which is a unittest @action class)

The MockConnection class can be used to simulate rdbms sessions:

$conn= new MockConnection('...');
$conn->addResultSet(new MockResultSet(['id' => 1, 'value' => 'foo']);

This resultset will be delivered as the first row of a query.

Simulate server disconnects:

$conn= new MockConnection('...');
$conn->letServerDisconnect();

$conn->query('...'); // Oops!

Make server connect fail:

$conn= new MockConnection('...');
$conn->makeConnectFail();

$conn->query('...'); // Oh no!

... and some more.

Security considerations

n/a

Speed impact

n/a

Dependencies

Related documents

  • It should be noted that using this implementation represents a very low-level way to test something; if there are ways to mock / replace higher level objects in the respective test, that way should be preferred.
@thekid
Copy link
Member

thekid commented May 24, 2016

$conn->addResultSet(new MockResultSet(['id' => 1, 'value' => 'foo']);

Hrm, this is quite verbose. How about:

$conn->returnResult([['id' => 1, 'value' => 'foo']]);

@thekid
Copy link
Member

thekid commented May 24, 2016

$conn->letServerDisconnect();
$conn->makeConnectFail();

There should be a way to clear these again...

@thekid
Copy link
Member

thekid commented May 24, 2016

Maybe Mock is a too technical term. How about Testing (for both package and class)?

@thekid thekid closed this as completed Nov 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants