Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

[feature request] Allow Hooks to Be Configured For Database Transactions #257

Closed
ddelnano opened this issue Jul 29, 2015 · 6 comments
Closed

Comments

@ddelnano
Copy link
Contributor

As it currently stands, I need to configure a beforeEach and afterEach hook in order to run everything in a transaction and roll it back so I have a clean database for each run. I think it would be useful to have the Hooks be able to accept a database connection that implements an interface for running or rolling back a migration (That is how it would work in PHP anyway).

So essentially you would set the Hooks::$databaseConnection property in the hooksfile like so:

<?php

use Dredd\Hooks;

$db = new DatabaseConnection(.....);
Hooks::setDatabaseConnection($db);

// Hook declarations come after

And the Hooks.php

public static function setDatabaseConnection(DatabaseInterface $db)
{
   // set property
}

This DatabaseConnection class would implement an interface that would expose a startTransaction and rollback method and from the Dredd\Runner side of things make a check on the beforeEach and afterEach hook to see if it is configured and if so start and rollback the transactions as necessary.

This way for each project I am on I don't need to configure this beforeEach and afterEach hook boiler plate.

I have done very little Python and Ruby programming, however, I do know that they don't have interfaces but from the PHP side thats a basic overview. Not exactly sure what the Ruby or Python way of dealing with this is, but if people like this idea I would like to give the implementation a try in the Python or Ruby as well as the PHP side of things.

@ddelnano
Copy link
Contributor Author

Ah forgot about the nodejs hooks but same holds true.

@netmilk
Copy link
Contributor

netmilk commented Sep 14, 2015

Hi @ddelnano,

may I know why did you close this? Is it not valid anymore?

@ddelnano
Copy link
Contributor Author

I was assuming when I opened this that there was going to be some discussion about the request. The reason I say that is cause I didn't want to incorporate something into the PHP hooks unless the others all had the same feature set.

@ddelnano
Copy link
Contributor Author

Do you agree with my thinking on that the hooks should have the same feature set??? I also closed it because to allow transactions would be hard cause it would require the user to provide the same database connection that their application is using and so it causes potential issues where users would be seeding the database in one connection and the web app would be accessing the database in another. Allowing an interface to run migrations before and after tests would be a much better option since it wouldn't require the same connection and still allow the database to be clean between tests.

@luizs81
Copy link

luizs81 commented Oct 30, 2016

I'm facing the same situation in Python side.
Yeah, it's 2016 now but still waiting for this feature.

@honzajavorek
Copy link
Contributor

honzajavorek commented Nov 3, 2016

@ddelnano

the hooks should have the same feature set

My opinion would be that all hooks implementations should conform to the same base feature set and it's up to their authors to try out innovations. If those innovations prove to be useful, they can get incorporated back as a standard feature in Dredd (one thing which pops in my head would be * operator in transaction names to pattern-match them in hooks, which I think is a great idea and should be part of the transition to #227).

Of course, when introducing innovations, authors of hooks risk future need for backwards-incompatible changes when the common implementation would be slightly different or behave slightly differently than what was originally introduced. But that's life. Without innovations and risk, there's no progress! 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants