Skip to content

Instantly share code, notes, and snippets.

@cspray
Created April 17, 2021 23:12
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 cspray/976d0f57c659a1d7bf8fcde3197c7bca to your computer and use it in GitHub Desktop.
Save cspray/976d0f57c659a1d7bf8fcde3197c7bca to your computer and use it in GitHub Desktop.
<?php
class DatabaseTestSuite implements TestSuite {
#[BeforeAll]
public function setUpDatabase() {
$conn = yield pool()->extractConnection();
$this-set('db', $conn);
}
#[BeforeEach]
public function startTransaction() {
yield $this-get('db')->query('START TRANSACTION');
}
#[AfterEach]
public function rollback() {
yield $this->get('db')->query('ROLLBACK');
}
#[AfterAll]
public function closeLink() {
$this->get('db')->close();
}
}
#[TestSuite(DatabaseTestSuite)
class DatabaseTestCase extends TestCase {
#[BeforeEach]
public function loadFixture() {
yield $this-get('db')->query('...');
}
#[Test]
public function ensureStuff() {
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment