Skip to content

Instantly share code, notes, and snippets.

@giorgiosironi
Created October 19, 2014 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giorgiosironi/7f5055c3fb3b7a4deeae to your computer and use it in GitHub Desktop.
Save giorgiosironi/7f5055c3fb3b7a4deeae to your computer and use it in GitHub Desktop.
Using a trait to share test code for multiple implementations
trait RepositoryContract
{
public function testAdd() { ... }
public function testRemove() { ... }
}
class MongoDBRepositoryTest {
use RepositoryContract;
public function setUp()
{
// create a connection, clean up the state...
$this->repository = new MongoDBRepository(/* ... */);
}
}
class InMemoryRepositoryTest {
use RepositoryContract;
public function setUp()
{
$this->repository = new InMemoryRepository();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment