2020
2121abstract class MakerTestCase extends TestCase
2222{
23- /**
24- * @var KernelInterface
25- */
26- private $ kernel ;
23+ private ?KernelInterface $ kernel = null ;
2724
2825 /**
2926 * @dataProvider getTestDetails
27+ *
28+ * @return void
3029 */
3130 public function testExecute (MakerTestDetails $ makerTestDetails )
3231 {
@@ -42,6 +41,9 @@ protected function createMakerTest(): MakerTestDetails
4241 return new MakerTestDetails ($ this ->getMakerInstance ($ this ->getMakerClass ()));
4342 }
4443
44+ /**
45+ * @return void
46+ */
4547 protected function executeMakerCommand (MakerTestDetails $ testDetails )
4648 {
4749 if (!class_exists (Process::class)) {
@@ -75,7 +77,7 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
7577 foreach ($ files as $ file ) {
7678 $ this ->assertTrue ($ testEnv ->fileExists ($ file ), sprintf ('The file "%s" does not exist after generation ' , $ file ));
7779
78- if (' .php ' === substr ($ file , - 4 )) {
80+ if (str_ends_with ($ file , ' .php ' )) {
7981 $ csProcess = $ testEnv ->runPhpCSFixer ($ file );
8082
8183 $ this ->assertTrue ($ csProcess ->isSuccessful (), sprintf (
@@ -85,14 +87,17 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
8587 ));
8688 }
8789
88- if (' .twig ' === substr ($ file , - 5 )) {
90+ if (str_ends_with ($ file , ' .twig ' )) {
8991 $ csProcess = $ testEnv ->runTwigCSLint ($ file );
9092
9193 $ this ->assertTrue ($ csProcess ->isSuccessful (), sprintf ('File "%s" has a twig-cs problem: %s ' , $ file , $ csProcess ->getErrorOutput ()."\n" .$ csProcess ->getOutput ()));
9294 }
9395 }
9496 }
9597
98+ /**
99+ * @return void
100+ */
96101 protected function assertContainsCount (string $ needle , string $ haystack , int $ count )
97102 {
98103 $ this ->assertEquals (1 , substr_count ($ haystack , $ needle ), sprintf ('Found more than %d occurrences of "%s" in "%s" ' , $ count , $ needle , $ haystack ));
@@ -122,8 +127,9 @@ private function hasRequiredDependencyVersions(MakerTestDetails $testDetails, Ma
122127 return true ;
123128 }
124129
125- $ installedPackages = json_decode ($ testEnv ->readFile ('vendor/composer/installed.json ' ), true );
130+ $ installedPackages = json_decode ($ testEnv ->readFile ('vendor/composer/installed.json ' ), true , 512 , \ JSON_THROW_ON_ERROR );
126131 $ packageVersions = [];
132+
127133 foreach ($ installedPackages ['packages ' ] ?? $ installedPackages as $ installedPackage ) {
128134 $ packageVersions [$ installedPackage ['name ' ]] = $ installedPackage ['version_normalized ' ];
129135 }
@@ -143,24 +149,4 @@ private function hasRequiredDependencyVersions(MakerTestDetails $testDetails, Ma
143149
144150 return true ;
145151 }
146-
147- public static function assertStringContainsString (string $ needle , string $ haystack , string $ message = '' ): void
148- {
149- if (method_exists (TestCase::class, 'assertStringContainsString ' )) {
150- parent ::assertStringContainsString ($ needle , $ haystack , $ message );
151- } else {
152- // legacy for older phpunit versions (e.g. older php version on CI)
153- self ::assertContains ($ needle , $ haystack , $ message );
154- }
155- }
156-
157- public static function assertStringNotContainsString (string $ needle , string $ haystack , string $ message = '' ): void
158- {
159- if (method_exists (TestCase::class, 'assertStringNotContainsString ' )) {
160- parent ::assertStringNotContainsString ($ needle , $ haystack , $ message );
161- } else {
162- // legacy for older phpunit versions (e.g. older php version on CI)
163- self ::assertNotContains ($ needle , $ haystack , $ message );
164- }
165- }
166152}
0 commit comments