8
8
9
9
final class PDOFixtureLoader implements FixtureLoader
10
10
{
11
- const EXTENSION_SQL = 'sql ' ;
12
-
13
11
private $ fileSystem ;
14
12
private $ config ;
15
13
private $ connection ;
@@ -26,8 +24,8 @@ public function __construct(FileSystem $fileSystem, PDOFixtureConfig $config, PD
26
24
*/
27
25
public function executeBeforeFirstTest (): void
28
26
{
29
- $ path = $ this ->config ->getParam (PDOFixtureConfig:: BEFORE_FIRST_TEST_PDO_FIXTURES_PATH );
30
- $ this ->runFixturesUnderPath ( $ path );
27
+ $ params = $ this ->config ->getBeforeFirstTest ( );
28
+ $ this ->runFixturesUnderPathWithExtension ( $ params [ ' path ' ], $ params [ ' extension ' ] );
31
29
}
32
30
33
31
/**
@@ -36,18 +34,11 @@ public function executeBeforeFirstTest(): void
36
34
*/
37
35
public function executeBeforeTest (string $ test ): void
38
36
{
39
- $ stage = PDOFixtureConfig::BEFORE_TEST_PDO_FIXTURES_PATH ;
40
- $ path = $ this ->config ->getParam ($ stage );
41
- $ this ->runFixturesUnderPath ($ path );
37
+ $ params = $ this ->config ->getBeforeTest ();
38
+ $ this ->runFixturesUnderPathWithExtension ($ params ['path ' ], $ params ['extension ' ]);
42
39
$ className = '\\' . substr ($ test , 0 , strpos ($ test , ': ' ));
43
40
$ methodName = 'getBeforeTestFixtureName ' ;
44
- if (method_exists ($ className , $ methodName )) {
45
- $ fixtureNameFunc = "$ className:: $ methodName " ;
46
- $ path = $ this ->config ->getParam ($ stage )
47
- . DIRECTORY_SEPARATOR
48
- . $ fixtureNameFunc ();
49
- $ this ->runFixturesUnderPath ($ path );
50
- }
41
+ $ this ->runSpecificFixturesFromStatic ($ className , $ methodName , $ params );
51
42
}
52
43
53
44
/**
@@ -57,38 +48,34 @@ public function executeBeforeTest(string $test): void
57
48
*/
58
49
public function executeAfterTest (string $ test , float $ time ): void
59
50
{
60
- $ stage = PDOFixtureConfig::AFTER_TEST_PDO_FIXTURES_PATH ;
61
- $ path = $ this ->config ->getParam ($ stage );
62
- $ this ->runFixturesUnderPath ($ path );
51
+ $ params = $ this ->config ->getAfterTest ();
52
+ $ this ->runFixturesUnderPathWithExtension ($ params ['path ' ], $ params ['extension ' ]);
63
53
$ className = '\\' . substr ($ test , 0 , strpos ($ test , ': ' ));
64
54
$ methodName = 'getAfterTestFixtureName ' ;
65
- if (method_exists ($ className , $ methodName )) {
66
- $ fixtureNameFunc = "$ className:: $ methodName " ;
67
- $ path = $ this ->config ->getParam ($ stage ) . DIRECTORY_SEPARATOR . $ fixtureNameFunc ();
68
- $ this ->runFixturesUnderPath ($ path );
69
- }
55
+ $ this ->runSpecificFixturesFromStatic ($ className , $ methodName , $ params );
70
56
}
71
57
72
58
/**
73
59
* @throws TestingException
74
60
*/
75
61
public function executeAfterLastTest (): void
76
62
{
77
- $ path = $ this ->config ->getParam (PDOFixtureConfig:: AFTER_LAST_TEST_PDO_FIXTURES_PATH );
78
- $ this ->runFixturesUnderPath ( $ path );
63
+ $ params = $ this ->config ->getAfterLastTest ( );
64
+ $ this ->runFixturesUnderPathWithExtension ( $ params [ ' path ' ], $ params [ ' extension ' ] );
79
65
}
80
66
81
67
/**
82
68
* @param string $path
69
+ * @param string $extension
83
70
* @throws TestingException
84
71
*/
85
- public function runFixturesUnderPath (string $ path ): void
72
+ public function runFixturesUnderPathWithExtension (string $ path, string $ extension ): void
86
73
{
87
74
try {
88
75
$ this ->connection ->PDO ()->beginTransaction ();
89
76
$ iterator = $ this ->fileSystem ->getFileListIteratorFromPathByExtension (
90
77
$ path ,
91
- self :: EXTENSION_SQL
78
+ $ extension
92
79
);
93
80
$ this ->fileSystem ->runCallbackOnEachFileIteratorContents (
94
81
$ iterator ,
@@ -102,4 +89,21 @@ function (string $contents) {
102
89
throw $ exception ;
103
90
}
104
91
}
92
+
93
+ /**
94
+ * @param string $className
95
+ * @param string $methodName
96
+ * @param array $params
97
+ * @throws TestingException
98
+ */
99
+ public function runSpecificFixturesFromStatic (string $ className , string $ methodName , array $ params ): void
100
+ {
101
+ if (method_exists ($ className , $ methodName )) {
102
+ $ fixtureNameFunc = "$ className:: $ methodName " ;
103
+ $ this ->runFixturesUnderPathWithExtension (
104
+ $ params ['path ' ] . DIRECTORY_SEPARATOR . $ fixtureNameFunc (),
105
+ $ params ['extension ' ]
106
+ );
107
+ }
108
+ }
105
109
}
0 commit comments