Last active
April 5, 2023 19:19
-
-
Save cspray/7559eeedcc3de0e13ae518cf997170a8 to your computer and use it in GitHub Desktop.
PHPUnit DatabaseTest Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use PHPUnit\Framework\TestCase; | |
class DatabaseTest extends TestCase { | |
private static $dbConnection; | |
public static function setUpBeforeClass() : void { | |
self::$dbConnection = DbConnectionFactory::create(); | |
} | |
public function setUp() : void { | |
self::$dbConnection->query('START TRANSACTION'); | |
// load databse records here | |
} | |
public function tearDown() : void { | |
self::$dbConnection->query('ROLLBACK'); | |
} | |
public static function tearDownAfterClass() : void { | |
self::$dbConnection->close(); | |
} | |
public function testSomethingWithTheDatabase() : void { | |
$subject = new SystemUnderTest(self::$dbConnection); | |
$subject->doSomething(); | |
// assert database records expected | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment