From b85fa69362d701818f22ee0fd995596981d7d710 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Thu, 11 Apr 2024 19:14:37 +1000 Subject: [PATCH] Fixed tests. --- scaffold/composer.json | 7 +- scaffold/phpcs.xml | 5 +- .../scripts/composer/ScaffoldGeneralizer.php | 8 +- .../composer/ScaffoldScriptHandler.php | 6 +- scaffold/scripts/composer/ScriptHandler.php | 6 +- scaffold/tests/phpunit/Dirs.php | 25 +-- .../phpunit/Functional/ComposerHookTest.php | 151 ------------------ .../Functional/ScaffoldCreateProjectTest.php | 14 +- ...{ScaffoldTest.php => ScaffoldTestCase.php} | 8 +- scaffold/tests/phpunit/Traits/CmdTrait.php | 5 +- .../tests/phpunit/Traits/ComposerTrait.php | 18 ++- scaffold/tests/phpunit/Traits/FileTrait.php | 9 +- .../tests/phpunit/Traits/JsonAssertTrait.php | 7 +- .../phpunit/Unit/ExampleScriptUnitTest.php | 48 ------ .../tests/phpunit/Unit/ScriptUnitTestCase.php | 64 -------- 15 files changed, 72 insertions(+), 309 deletions(-) delete mode 100644 scaffold/tests/phpunit/Functional/ComposerHookTest.php rename scaffold/tests/phpunit/Functional/{ScaffoldTest.php => ScaffoldTestCase.php} (89%) delete mode 100644 scaffold/tests/phpunit/Unit/ExampleScriptUnitTest.php delete mode 100644 scaffold/tests/phpunit/Unit/ScriptUnitTestCase.php diff --git a/scaffold/composer.json b/scaffold/composer.json index 641813e..b528da2 100644 --- a/scaffold/composer.json +++ b/scaffold/composer.json @@ -101,14 +101,13 @@ "DrevOps\\composer\\ScaffoldGeneralizer::generalizeAndRemoveItselfAfterProjectCreate" ], "lint": [ - "cp php-script php-script.php && phpcs && rm php-script.php", - "phpmd --exclude vendor,vendor-bin,node_modules . text phpmd.xml", + "phpcs", "phpstan", "rector --clear-cache --dry-run" ], "lint-fix": [ - "rector --clear-cache", - "cp php-script php-script.php && phpcbf && rm php-script.php" + "phpcbf", + "rector --clear-cache" ], "test": "if [ \"${XDEBUG_MODE}\" = 'coverage' ]; then phpunit; else phpunit --no-coverage; fi" } diff --git a/scaffold/phpcs.xml b/scaffold/phpcs.xml index 7e36e55..ef93aa3 100644 --- a/scaffold/phpcs.xml +++ b/scaffold/phpcs.xml @@ -3,7 +3,10 @@ Custom PHPCS standard. - + + + + diff --git a/scaffold/scripts/composer/ScaffoldGeneralizer.php b/scaffold/scripts/composer/ScaffoldGeneralizer.php index f06e8fb..dec152c 100644 --- a/scaffold/scripts/composer/ScaffoldGeneralizer.php +++ b/scaffold/scripts/composer/ScaffoldGeneralizer.php @@ -156,12 +156,12 @@ public static function generalizeAndRemoveItselfAfterProjectCreate(Event $event) // Remove references to this script. // Remove event script used to invoke this script during the project // creation. - unset($json['scripts']['post-root-package-install'][array_search(__METHOD__, $json['scripts']['post-root-package-install'])]); + unset($json['scripts']['post-root-package-install'][array_search(__METHOD__, $json['scripts']['post-root-package-install'], true)]); if (empty($json['scripts']['post-root-package-install'])) { unset($json['scripts']['post-root-package-install']); } // Remove the classmap for this script from the autoload section. - unset($json['autoload']['classmap'][array_search('scripts/composer/ScaffoldGeneralizer.php', $json['autoload']['classmap'])]); + unset($json['autoload']['classmap'][array_search('scripts/composer/ScaffoldGeneralizer.php', $json['autoload']['classmap'], true)]); $json['autoload']['classmap'] = array_values($json['autoload']['classmap']); // Remove the script file. if (!$is_install) { @@ -195,7 +195,7 @@ public static function postCreateProjectCmd(Event $event): void { $fs->unlink(getcwd() . '/scripts/composer/ScaffoldGeneralizer.php'); } - protected static function isInstall(Event $event) { + protected static function isInstall(Event $event): bool { $io = $event->getIO(); $reflectionIo = new \ReflectionObject($io); @@ -225,7 +225,7 @@ protected static function getVersion(): string { */ protected static function arrayUpsert(&$array, $after, $key, $value): void { if (array_key_exists($after, $array)) { - $position = array_search($after, array_keys($array)) + 1; + $position = array_search($after, array_keys($array), true) + 1; $array = array_slice($array, 0, $position, TRUE) + [$key => $value] + array_slice($array, $position, NULL, TRUE); diff --git a/scaffold/scripts/composer/ScaffoldScriptHandler.php b/scaffold/scripts/composer/ScaffoldScriptHandler.php index afc015c..cef540f 100644 --- a/scaffold/scripts/composer/ScaffoldScriptHandler.php +++ b/scaffold/scripts/composer/ScaffoldScriptHandler.php @@ -64,9 +64,9 @@ public static function preAutoloadDump(Event $event): void { foreach ($packages as $package) { if ($package->getName() === 'drevops/scaffold') { $autoload = $package->getAutoload(); - unset($autoload['classmap'][array_search('scripts/composer/ScaffoldScriptHandler.php', $autoload['classmap'])]); - unset($autoload['classmap'][array_search('scripts/composer/ScaffoldGeneralizer.php', $autoload['classmap'])]); - unset($autoload['classmap'][array_search('scripts/composer/ScriptHandler.php', $autoload['classmap'])]); + unset($autoload['classmap'][array_search('scripts/composer/ScaffoldScriptHandler.php', $autoload['classmap'], true)]); + unset($autoload['classmap'][array_search('scripts/composer/ScaffoldGeneralizer.php', $autoload['classmap'], true)]); + unset($autoload['classmap'][array_search('scripts/composer/ScriptHandler.php', $autoload['classmap'], true)]); $package->setAutoload($autoload); $event->getIO()->debug('Removed classmap for ' . $package->getName()); break; diff --git a/scaffold/scripts/composer/ScriptHandler.php b/scaffold/scripts/composer/ScriptHandler.php index 26c2866..267915f 100644 --- a/scaffold/scripts/composer/ScriptHandler.php +++ b/scaffold/scripts/composer/ScriptHandler.php @@ -20,7 +20,7 @@ class ScriptHandler { - public static function createRequiredFiles(Event $event) { + public static function createRequiredFiles(Event $event): void { // Noop } @@ -38,7 +38,7 @@ public static function createRequiredFiles(Event $event) { * * @see https://github.com/composer/composer/pull/5035 */ - public static function checkComposerVersion(Event $event) { + public static function checkComposerVersion(Event $event): void { $composer = $event->getComposer(); $io = $event->getIO(); @@ -46,7 +46,7 @@ public static function checkComposerVersion(Event $event) { // The dev-channel of composer uses the git revision as version number, // try to the branch alias instead. - if (preg_match('/^[0-9a-f]{40}$/i', $version)) { + if (preg_match('/^[0-9a-f]{40}$/i', (string) $version)) { $version = $composer::BRANCH_ALIAS_VERSION; } diff --git a/scaffold/tests/phpunit/Dirs.php b/scaffold/tests/phpunit/Dirs.php index dc096dd..7f98684 100644 --- a/scaffold/tests/phpunit/Dirs.php +++ b/scaffold/tests/phpunit/Dirs.php @@ -5,12 +5,15 @@ use DrevOps\Scaffold\Tests\Traits\FileTrait; use Symfony\Component\Filesystem\Filesystem; +/** + * + */ class Dirs { use FileTrait; /** - * Directory where a copy of the DrevOps Scaffold (this) repository is located. + * Directory where a copy of the DrevOps Scaffold repository is located. * * This allows to isolate the test from this repository files and prevent * their accidental removal. @@ -38,34 +41,32 @@ class Dirs { /** * The file system. - * - * @var \Symfony\Component\Filesystem\Filesystem */ - protected $fs; + protected Filesystem $fs; public function __construct() { $this->fs = new Filesystem(); } - public function initLocations() { + public function initLocations(): void { $this->build = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'drevops-scaffold-' . microtime(TRUE); - $this->sut = "$this->build/sut"; - $this->repo = "$this->build/local_repo"; + $this->sut = $this->build . '/sut'; + $this->repo = $this->build . '/local_repo'; $this->fs->mkdir($this->build); $this->prepareLocalRepo(); } - public function deleteLocations() { + public function deleteLocations(): void { $this->fs->remove($this->build); } - public function printInfo() { + public function printInfo(): void { $lines[] = '-- LOCATIONS --'; - $lines[] = "Build : {$this->build}"; - $lines[] = "SUT : {$this->sut}"; - $lines[] = "Local repo : {$this->repo}"; + $lines[] = 'Build : ' . $this->build; + $lines[] = 'SUT : ' . $this->sut; + $lines[] = 'Local repo : ' . $this->repo; fwrite(STDERR, PHP_EOL . implode(PHP_EOL, $lines) . PHP_EOL); } diff --git a/scaffold/tests/phpunit/Functional/ComposerHookTest.php b/scaffold/tests/phpunit/Functional/ComposerHookTest.php deleted file mode 100644 index 2b7dda9..0000000 --- a/scaffold/tests/phpunit/Functional/ComposerHookTest.php +++ /dev/null @@ -1,151 +0,0 @@ -fileSystem = new Filesystem(); - $this->fixtures = new Fixtures(); - $this->fixtures->createIsolatedComposerCacheDir(); - $this->fixturesDir = $this->fixtures->tmpDir($this->getName()); - $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()]; - $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements); - } - - /** - * {@inheritdoc} - */ - protected function tearDown(): void { - // Remove any temporary directories et. al. that were created. - $this->fixtures->tearDown(); - - parent::tearDown(); - } - - /** - * Tests to see if scaffold operation runs at the correct times. - */ - public function testComposerHooks() { - $topLevelProjectDir = 'composer-hooks-fixture'; - $sut = $this->fixturesDir . '/' . $topLevelProjectDir; - // First test: run composer install. This is the same as composer update - // since there is no lock file. Ensure that scaffold operation ran. - $this->mustExec("composer install --no-ansi", $sut); - $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'Test version of default.settings.php from drupal/core'); - // Run composer required to add in the scaffold-override-fixture. This - // project is "allowed" in our main fixture project, but not required. - // We expect that requiring this library should re-scaffold, resulting - // in a changed default.settings.php file. - $stdout = $this->mustExec("composer require --no-ansi --no-interaction fixtures/drupal-assets-fixture:dev-main fixtures/scaffold-override-fixture:dev-main", $sut); - $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture'); - // Make sure that the appropriate notice informing us that scaffolding - // is allowed was printed. - $this->assertStringContainsString('Package fixtures/scaffold-override-fixture has scaffold operations, and is already allowed in the root-level composer.json file.', $stdout); - // Delete one scaffold file, just for test purposes, then run - // 'composer update' and see if the scaffold file is replaced. - @unlink($sut . '/sites/default/default.settings.php'); - $this->assertFileDoesNotExist($sut . '/sites/default/default.settings.php'); - $this->mustExec("composer update --no-ansi", $sut); - $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture'); - // Delete the same test scaffold file again, then run - // 'composer drupal:scaffold' and see if the scaffold file is - // re-scaffolded. - @unlink($sut . '/sites/default/default.settings.php'); - $this->assertFileDoesNotExist($sut . '/sites/default/default.settings.php'); - $this->mustExec("composer install --no-ansi", $sut); - $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture'); - // Delete the same test scaffold file yet again, then run - // 'composer install' and see if the scaffold file is re-scaffolded. - @unlink($sut . '/sites/default/default.settings.php'); - $this->assertFileDoesNotExist($sut . '/sites/default/default.settings.php'); - $this->mustExec("composer drupal:scaffold --no-ansi", $sut); - $this->assertScaffoldedFile($sut . '/sites/default/default.settings.php', FALSE, 'scaffolded from the scaffold-override-fixture'); - // Run 'composer create-project' to create a new test project called - // 'create-project-test', which is a copy of 'fixtures/drupal-drupal'. - $sut = $this->fixturesDir . '/create-project-test'; - $filesystem = new Filesystem(); - $filesystem->remove($sut); - $stdout = $this->mustExec("composer create-project --repository=packages.json fixtures/drupal-drupal {$sut}", $this->fixturesDir, ['COMPOSER_MIRROR_PATH_REPOS' => 1]); - $this->assertDirectoryExists($sut); - $this->assertStringContainsString('Scaffolding files for fixtures/drupal-drupal', $stdout); - $this->assertScaffoldedFile($sut . '/index.php', FALSE, 'Test version of index.php from drupal/core'); - } - - /** - * Tests to see if scaffold messages are omitted when running scaffold twice. - */ - public function testScaffoldMessagesDoNotPrintTwice() { - $topLevelProjectDir = 'drupal-drupal'; - $sut = $this->fixturesDir . '/' . $topLevelProjectDir; - // First test: run composer install. This is the same as composer update - // since there is no lock file. Ensure that scaffold operation ran. - $stdout = $this->mustExec("composer install --no-ansi", $sut); - - $this->assertStringContainsString('- Copy [web-root]/index.php from assets/index.php', $stdout); - $this->assertStringContainsString('- Copy [web-root]/update.php from assets/update.php', $stdout); - - // Run scaffold operation again. It should not print anything. - $stdout = $this->mustExec("composer scaffold --no-ansi", $sut); - - $this->assertEquals('', $stdout); - - // Delete a file and run it again. It should re-scaffold the removed file. - unlink("$sut/index.php"); - $stdout = $this->mustExec("composer scaffold --no-ansi", $sut); - $this->assertStringContainsString('- Copy [web-root]/index.php from assets/index.php', $stdout); - $this->assertStringNotContainsString('- Copy [web-root]/update.php from assets/update.php', $stdout); - } - -} diff --git a/scaffold/tests/phpunit/Functional/ScaffoldCreateProjectTest.php b/scaffold/tests/phpunit/Functional/ScaffoldCreateProjectTest.php index 7a72028..641fcbf 100644 --- a/scaffold/tests/phpunit/Functional/ScaffoldCreateProjectTest.php +++ b/scaffold/tests/phpunit/Functional/ScaffoldCreateProjectTest.php @@ -3,10 +3,14 @@ namespace DrevOps\Scaffold\Tests\Functional; use DrevOps\composer\ScaffoldGeneralizer; +use DrevOps\composer\ScaffoldScriptHandler; -class ScaffoldCreateProjectTest extends ScaffoldTest { +/** + * + */ +class ScaffoldCreateProjectTest extends ScaffoldTestCase { - public function testCreateProjectNoInstall() { + public function testCreateProjectNoInstall(): void { $output = $this->composerRun($this->composerCreateProject('--no-install')); $this->assertStringContainsString('Initialised project from DrevOps Scaffold', $output); @@ -14,14 +18,14 @@ public function testCreateProjectNoInstall() { $this->assertJsonValueEquals($this->composerReadJson(), '$.name', ScaffoldGeneralizer::PROJECT_NAME); $this->assertJsonValueEquals($this->composerReadJson(), '$.require-dev."drevops/scaffold"', "@dev"); - $this->assertJsonValueEquals($this->composerReadJson(), '$.scripts."pre-update-cmd"[1]', 'DrevOps\\composer\\ScaffoldScriptHandler::preUpdateCmd'); + $this->assertJsonValueEquals($this->composerReadJson(), '$.scripts."pre-update-cmd"[1]', ScaffoldScriptHandler::class . '::preUpdateCmd'); $this->assertJsonHasNoKey($this->composerReadJson(), '$.scripts."post-root-package-install"[1]'); $this->assertJsonValueEquals($this->composerReadJson(), '$.extra."drupal-scaffold"."allowed-packages"[0]', ScaffoldGeneralizer::DREVOPS_SCAFFOLD_NAME); $this->assertJsonValueEquals($this->composerReadJson(), '$.autoload.classmap[0]', 'scripts/composer/ScaffoldScriptHandler.php'); $this->assertJsonValueEquals($this->composerReadJson(), '$.autoload.classmap[1]', 'scripts/composer/ScriptHandler.php'); } - public function testCreateProjectInstall() { + public function testCreateProjectInstall(): void { $output = $this->composerRun($this->composerCreateProject()); $this->assertStringContainsString('Initialised project from DrevOps Scaffold', $output); @@ -29,7 +33,7 @@ public function testCreateProjectInstall() { $this->assertJsonValueEquals($this->composerReadJson(), '$.name', ScaffoldGeneralizer::PROJECT_NAME); $this->assertJsonValueEquals($this->composerReadJson(), '$.require-dev."drevops/scaffold"', "@dev"); - $this->assertJsonValueEquals($this->composerReadJson(), '$.scripts."pre-update-cmd"[1]', 'DrevOps\\composer\\ScaffoldScriptHandler::preUpdateCmd'); + $this->assertJsonValueEquals($this->composerReadJson(), '$.scripts."pre-update-cmd"[1]', ScaffoldScriptHandler::class . '::preUpdateCmd'); $this->assertJsonHasNoKey($this->composerReadJson(), '$.scripts."post-root-package-install"[1]'); $this->assertJsonValueEquals($this->composerReadJson(), '$.extra."drupal-scaffold"."allowed-packages"[0]', ScaffoldGeneralizer::DREVOPS_SCAFFOLD_NAME); $this->assertJsonValueEquals($this->composerReadJson(), '$.autoload.classmap[0]', 'scripts/composer/ScaffoldScriptHandler.php'); diff --git a/scaffold/tests/phpunit/Functional/ScaffoldTest.php b/scaffold/tests/phpunit/Functional/ScaffoldTestCase.php similarity index 89% rename from scaffold/tests/phpunit/Functional/ScaffoldTest.php rename to scaffold/tests/phpunit/Functional/ScaffoldTestCase.php index a8f31c6..fe5eeb6 100644 --- a/scaffold/tests/phpunit/Functional/ScaffoldTest.php +++ b/scaffold/tests/phpunit/Functional/ScaffoldTestCase.php @@ -13,7 +13,10 @@ use PHPUnit\Framework\TestStatus\Failure; use Symfony\Component\Filesystem\Filesystem; -class ScaffoldTest extends TestCase { +/** + * + */ +class ScaffoldTestCase extends TestCase { use CmdTrait; use ComposerTrait; @@ -59,7 +62,8 @@ protected function tearDown(): void { protected function onNotSuccessfulTest(\Throwable $t): never { $this->dirs->printInfo(); - parent::onNotSuccessfulTest($t); // Rethrow the exception to allow the test to fail normally. + // Rethrow the exception to allow the test to fail normally. + parent::onNotSuccessfulTest($t); } public function hasFailed(): bool { diff --git a/scaffold/tests/phpunit/Traits/CmdTrait.php b/scaffold/tests/phpunit/Traits/CmdTrait.php index c77278e..ca235a1 100644 --- a/scaffold/tests/phpunit/Traits/CmdTrait.php +++ b/scaffold/tests/phpunit/Traits/CmdTrait.php @@ -6,6 +6,9 @@ use Symfony\Component\Process\Process; +/** + * + */ trait CmdTrait { /** @@ -21,7 +24,7 @@ trait CmdTrait { * @return string * Standard output from the command */ - protected function cmdRun($cmd, $cwd, array $env = []) { + protected function cmdRun($cmd, $cwd, array $env = []): string { $env += $env + ['PATH' => getenv('PATH'), 'HOME' => getenv('HOME')]; $process = Process::fromShellCommandline($cmd, $cwd, $env); diff --git a/scaffold/tests/phpunit/Traits/ComposerTrait.php b/scaffold/tests/phpunit/Traits/ComposerTrait.php index 7be5b95..dadc3e2 100644 --- a/scaffold/tests/phpunit/Traits/ComposerTrait.php +++ b/scaffold/tests/phpunit/Traits/ComposerTrait.php @@ -6,9 +6,12 @@ use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\BufferedOutput; +/** + * + */ trait ComposerTrait { - protected function composerCreateProject(array|string $args = NULL) { + protected function composerCreateProject(array|string $args = NULL): string { $args = $args ?? ''; $args = is_array($args) ? $args : [$args]; $args[] = $this->dirs->sut; @@ -22,13 +25,17 @@ protected function composerCreateProject(array|string $args = NULL) { * * @param string $cmd * The Composer command to execute (escaped as required) - * @param string $cwd + * @param null $cwd * The current working directory to run the command from. + * @param array $env + * Environment variables to define for the subprocess. * * @return string * Standard output and standard error from the command. + * + * @throws \Exception */ - public function composerRun($cmd, $cwd = NULL, $env = []) { + public function composerRun($cmd, $cwd = NULL, $env = []): string { $cwd = $cwd ?? $this->dirs->build; $env += [ @@ -41,8 +48,7 @@ public function composerRun($cmd, $cwd = NULL, $env = []) { $input = new StringInput($cmd); $output = new BufferedOutput(); - // $output->setVerbosity(ConsoleOutput::VERBOSITY_QUIET); - + // $output->setVerbosity(ConsoleOutput::VERBOSITY_QUIET); $application = new Application(); $application->setAutoExit(FALSE); @@ -52,7 +58,7 @@ public function composerRun($cmd, $cwd = NULL, $env = []) { $this->envReset(); if ($code != 0) { - throw new \Exception("Fixtures::composerRun failed to set up fixtures.\n\nCommand: '{$cmd}'\nExit code: {$code}\nOutput: \n\n$output"); + throw new \Exception("Fixtures::composerRun failed to set up fixtures.\n\nCommand: '{$cmd}'\nExit code: {$code}\nOutput: \n\n{$output}"); } return $output; diff --git a/scaffold/tests/phpunit/Traits/FileTrait.php b/scaffold/tests/phpunit/Traits/FileTrait.php index e396be6..c5cf776 100644 --- a/scaffold/tests/phpunit/Traits/FileTrait.php +++ b/scaffold/tests/phpunit/Traits/FileTrait.php @@ -4,9 +4,12 @@ use Symfony\Component\Filesystem\Filesystem; +/** + * + */ trait FileTrait { - public function fileFindDir($file, $start = NULL) { + public function fileFindDir(string $file, $start = NULL) { if (empty($start)) { $start = dirname(__FILE__); } @@ -20,10 +23,10 @@ public function fileFindDir($file, $start = NULL) { if ($fs->exists($path)) { return $current; } - $current = dirname($current); + $current = dirname((string) $current); } - throw new \RuntimeException("File not found: $file"); + throw new \RuntimeException('File not found: ' . $file); } } diff --git a/scaffold/tests/phpunit/Traits/JsonAssertTrait.php b/scaffold/tests/phpunit/Traits/JsonAssertTrait.php index 44da7cd..fbaea24 100644 --- a/scaffold/tests/phpunit/Traits/JsonAssertTrait.php +++ b/scaffold/tests/phpunit/Traits/JsonAssertTrait.php @@ -5,15 +5,18 @@ use Flow\JSONPath\JSONPath; use Helmich\JsonAssert\JsonAssertions; +/** + * + */ trait JsonAssertTrait { use JsonAssertions; - public function assertJsonHasNoKey($jsonDocument, string $jsonPath, $message = NULL) { + public function assertJsonHasNoKey($jsonDocument, string $jsonPath, $message = NULL): void { $result = (new JSONPath($jsonDocument))->find($jsonPath); if (isset($result[0])) { - $this->fail($message ?: "The JSON path '$jsonPath' exists, but it was expected not to."); + $this->fail($message ?: sprintf("The JSON path '%s' exists, but it was expected not to.", $jsonPath)); } $this->addToAssertionCount(1); diff --git a/scaffold/tests/phpunit/Unit/ExampleScriptUnitTest.php b/scaffold/tests/phpunit/Unit/ExampleScriptUnitTest.php deleted file mode 100644 index ccd0e24..0000000 --- a/scaffold/tests/phpunit/Unit/ExampleScriptUnitTest.php +++ /dev/null @@ -1,48 +0,0 @@ -expectException(\Exception::class); - $this->expectExceptionMessage($expected_exception_message); - } - - $output = $this->runMain($args); - - $expected_output = is_array($expected_output) ? $expected_output : [$expected_output]; - foreach ($expected_output as $expected_output_string) { - $this->assertArrayContainsString($expected_output_string, $output); - } - } - - public static function dataProviderMain(): array { - return [ - ['help', 'PHP CLI script template.'], - ['--help', 'PHP CLI script template.'], - ['-h', 'PHP CLI script template.'], - ['-?', 'PHP CLI script template.'], - ['-help', 'Would execute script business logic with argument -help.'], - ['', [], 'Please provide a value of the first argument.'], - ['testarg1', 'Would execute script business logic with argument testarg1.'], - [['testarg1', 'testarg2'], [], 'Please provide a value of the first argument.'], - ]; - } - -} diff --git a/scaffold/tests/phpunit/Unit/ScriptUnitTestCase.php b/scaffold/tests/phpunit/Unit/ScriptUnitTestCase.php deleted file mode 100644 index 37b7973..0000000 --- a/scaffold/tests/phpunit/Unit/ScriptUnitTestCase.php +++ /dev/null @@ -1,64 +0,0 @@ - $args - * Optional array of arguments to pass to the script. - * - * @return array - * Array of output lines. - */ - protected function runMain(string|array $args = []): array { - $args = is_array($args) ? $args : [$args]; - - $function = new \ReflectionFunction('main'); - array_unshift($args, $function->getFileName()); - $args = array_filter($args); - - main($args, count($args)); - - return verbose(''); - } - -}