18
18
* @copyright Copyright (c) 2018 Riikka Kalliomäki
19
19
* @license http://opensource.org/licenses/mit-license.php MIT License
20
20
*/
21
- abstract class IntegrationTestCase extends TestCase
21
+ abstract class IntegrationTestCase extends UnitTestCase
22
22
{
23
23
/** @var Connection */
24
24
protected $ connection ;
@@ -32,23 +32,60 @@ abstract class IntegrationTestCase extends TestCase
32
32
/** @var TestHouseSchema */
33
33
protected $ houseSchema ;
34
34
35
- abstract protected function createConnection (): Connection ;
36
- abstract protected function setUpDatabase (Connection $ connection ): void ;
35
+ abstract protected static function createConnection (): Connection ;
37
36
38
- protected function setUp ()
37
+ abstract protected static function createTables (
38
+ Connection $ connection ,
39
+ TestParentSchema $ parentSchema ,
40
+ TestPersonSchema $ personSchema ,
41
+ TestHouseSchema $ houseSchema
42
+ ): void ;
43
+
44
+ abstract protected static function dropTables (
45
+ Connection $ connection ,
46
+ TestParentSchema $ parentSchema ,
47
+ TestPersonSchema $ personSchema ,
48
+ TestHouseSchema $ houseSchema
49
+ ): void ;
50
+
51
+ abstract protected function truncateTables (Connection $ connection ): void ;
52
+
53
+ public static function setUpBeforeClass ()
54
+ {
55
+ $ container = static ::initializeContainer ();
56
+ $ connection = static ::createConnection ();
57
+
58
+ static ::createTables (
59
+ $ connection ,
60
+ $ container [TestParentSchema::class],
61
+ $ container [TestPersonSchema::class],
62
+ $ container [TestHouseSchema::class]
63
+ );
64
+ }
65
+
66
+ public static function tearDownAfterClass ()
39
67
{
40
- $ container = new Container ();
68
+ $ container = static ::initializeContainer ();
69
+ $ connection = static ::createConnection ();
70
+
71
+ static ::dropTables (
72
+ $ connection ,
73
+ $ container [TestParentSchema::class],
74
+ $ container [TestPersonSchema::class],
75
+ $ container [TestHouseSchema::class]
76
+ );
77
+ }
41
78
42
- $ this -> personSchema = new TestPersonSchema ( $ container );
43
- $ this -> parentSchema = new TestParentSchema ( $ container );
44
- $ this -> houseSchema = new TestHouseSchema ( $ container );
79
+ protected function setUp ()
80
+ {
81
+ $ container = static :: initializeContainer ( );
45
82
46
- $ container [TestPersonSchema::class] = $ this -> personSchema ;
47
- $ container [TestParentSchema::class] = $ this -> parentSchema ;
48
- $ container [TestHouseSchema::class] = $ this -> houseSchema ;
83
+ $ this -> personSchema = $ container [TestPersonSchema::class];
84
+ $ this -> parentSchema = $ container [TestParentSchema::class];
85
+ $ this -> houseSchema = $ container [TestHouseSchema::class];
49
86
50
- $ this ->connection = $ this -> createConnection ();
51
- $ this ->setUpDatabase ($ this ->connection );
87
+ $ this ->connection = static :: createConnection ();
88
+ $ this ->truncateTables ($ this ->connection );
52
89
}
53
90
54
91
private function getTestPersonRepository (): TestRepository
@@ -424,4 +461,4 @@ public function testDeletingDeletedRecord()
424
461
$ this ->expectException (MissingRecordException::class);
425
462
$ repository ->deletePerson ($ person );
426
463
}
427
- }
464
+ }
0 commit comments