3131
3232class WordPressCoreInstallerTest extends TestCase {
3333
34- protected function setUp () {
35- $ this ->resetInstallPaths ();
36- }
37-
38- protected function tearDown () {
39- $ this ->resetInstallPaths ();
40- }
41-
4234 public function testSupports () {
4335 $ installer = new WordPressCoreInstaller ( new NullIO (), $ this ->createComposer () );
4436
@@ -123,11 +115,11 @@ public function testCorePackageDefaultDoesNotOverrideRootDirectoryDefinition() {
123115 $ this ->assertEquals ( 'wp ' , $ installer ->getInstallPath ( $ package ) );
124116 }
125117
126- /**
127- * @expectedException \InvalidArgumentException
128- * @expectedExceptionMessage Two packages (test/bazbat and test/foobar) cannot share the same directory!
129- */
130118 public function testTwoPackagesCannotShareDirectory () {
119+ $ this ->jpbExpectException (
120+ '\InvalidArgumentException ' ,
121+ 'Two packages (test/bazbat and test/foobar) cannot share the same directory! '
122+ );
131123 $ composer = $ this ->createComposer ();
132124 $ installer = new WordPressCoreInstaller ( new NullIO (), $ composer );
133125 $ package1 = new Package ( 'test/foobar ' , '1.1.1.1 ' , '1.1.1.1 ' );
@@ -138,11 +130,14 @@ public function testTwoPackagesCannotShareDirectory() {
138130 }
139131
140132 /**
141- * @dataProvider dataProviderSensitiveDirectories
142- * @expectedException \InvalidArgumentException
143- * @expectedExceptionMessageRegExp /Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/
133+ * @dataProvider dataProviderSensitiveDirectories
144134 */
145135 public function testSensitiveInstallDirectoriesNotAllowed ( $ directory ) {
136+ $ this ->jpbExpectException (
137+ '\InvalidArgumentException ' ,
138+ '/Warning! .+? is an invalid WordPress install directory \(from test\/package\)!/ ' ,
139+ true
140+ );
146141 $ composer = $ this ->createComposer ();
147142 $ installer = new WordPressCoreInstaller ( new NullIO (), $ composer );
148143 $ package = new Package ( 'test/package ' , '1.1.0.0 ' , '1.1 ' );
@@ -157,7 +152,11 @@ public function dataProviderSensitiveDirectories() {
157152 );
158153 }
159154
160- private function resetInstallPaths () {
155+ /**
156+ * @before
157+ * @afterClass
158+ */
159+ public static function resetInstallPaths () {
161160 $ prop = new \ReflectionProperty ( '\johnpbloch\Composer\WordPressCoreInstaller ' , '_installedPaths ' );
162161 $ prop ->setAccessible ( true );
163162 $ prop ->setValue ( array () );
@@ -173,4 +172,17 @@ private function createComposer() {
173172 return $ composer ;
174173 }
175174
175+ private function jpbExpectException ( $ class , $ message = '' , $ isRegExp = false ) {
176+ if ( method_exists ( $ this , 'expectException ' ) ) {
177+ $ this ->expectException ($ class );
178+ if ( $ message ) {
179+ $ isRegExp || $ this ->expectExceptionMessage ( $ message );
180+ $ isRegExp && $ this ->expectExceptionMessageRegExp ( $ message );
181+ }
182+ } else {
183+ $ isRegExp || $ this ->setExpectedException ( $ class , $ message );
184+ $ isRegExp && $ this ->setExpectedExceptionRegExp ( $ class , $ message );
185+ }
186+ }
187+
176188}
0 commit comments