diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index bb4b0a2..31c7b19 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -46,6 +46,9 @@ 'spacing' => 'one', ], 'single_line_throw' => false, + 'php_unit_test_case_static_method_calls' => [ + 'call_type' => 'self', + ], ]) ->setRiskyAllowed(true) ->setFinder( diff --git a/UPGRADE.md b/UPGRADE.md index 81515c3..0b7ade7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,19 @@ +# Upgrading from v3.2 to v3.3 + +## Pass only string parameters to `\Crunz\Schedule::run` + +Convert this: +```php +$schedule = new Schedule(); +$schedule->run('php', ['-v' => true, 2]); +``` + +into this: +```php +$schedule = new Schedule(); +$schedule->run('php', ['-v' => '1', '2']); +``` + # Upgrading from v1.12 to v2.0 ## Stop using `mail` transport for mailer diff --git a/bootstrap.php b/bootstrap.php index 14af291..75bfa0b 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -2,6 +2,10 @@ require_once __DIR__ . '/vendor/autoload.php'; +if (!\defined('IS_WINDOWS')) { + \define('IS_WINDOWS', PHP_OS_FAMILY === "Windows"); +} + // Disable deprecation helper $envFlags = new \Crunz\EnvFlags\EnvFlags(); $envFlags->disableDeprecationHandler(); diff --git a/composer-install.php b/composer-install.php index 8e5c9df..6bc9041 100755 --- a/composer-install.php +++ b/composer-install.php @@ -9,7 +9,7 @@ $dependenciesEnv = $_SERVER['argv'][2] ?? ''; $defaultComposerFlags = $_SERVER['argv'][3] ?? ''; $composerFilePath = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json'; -$ignoredPackages = ['symfony/error-handler']; +$ignoredPackages = ['symfony/error-handler', 'symfony/phpunit-bridge']; $changeVersion = static function ( array $packages ) use ( diff --git a/composer.json b/composer.json index 0e94428..f3f9d2b 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "phpstan/phpstan-strict-rules": "^1.2", "phpunit/phpunit": "^9.5.5", "symfony/error-handler": "^4.4.30 || ^5.4 || ^6.0", - "symfony/phpunit-bridge": "^4.4.30 || ^5.4.0 || ^6.0" + "symfony/phpunit-bridge": "^5.4.0 || ^6.0" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 78b47a7..2df0b64 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -405,131 +405,11 @@ parameters: count: 1 path: src/UserInterface/Cli/ClosureRunCommand.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 3 - path: tests/EndToEnd/ClosureRunTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/ConfigProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/ConfigProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/ConfigProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 2 - path: tests/EndToEnd/ConfigRecognitionTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringNotContainsString\\(\\)\\.$#" - count: 2 - path: tests/EndToEnd/ConfigRecognitionTest.php - - - - message: "#^Dynamic call to static method Crunz\\\\Tests\\\\TestCase\\\\EndToEndTestCase\\:\\:assertMatchesRegularExpression\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/DebugTaskTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\)\\.$#" - count: 3 - path: tests/EndToEnd/DebugTaskTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 2 - path: tests/EndToEnd/DebugTaskTest.php - - - - message: "#^Dynamic call to static method Crunz\\\\Tests\\\\TestCase\\\\EndToEndTestCase\\:\\:assertFileDoesNotExist\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/LoggerTest.php - - - - message: "#^Dynamic call to static method Crunz\\\\Tests\\\\TestCase\\\\EndToEndTestCase\\:\\:assertMatchesRegularExpression\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/LoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/LoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/LoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/LoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 2 - path: tests/EndToEnd/TasksSourceRecognitionTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringNotContainsString\\(\\)\\.$#" - count: 2 - path: tests/EndToEnd/TasksSourceRecognitionTest.php - - - - message: "#^Dynamic call to static method Crunz\\\\Tests\\\\TestCase\\\\EndToEndTestCase\\:\\:assertMatchesRegularExpression\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/WrongTaskTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" - count: 1 - path: tests/EndToEnd/WrongTaskTest.php - - message: "#^Method Crunz\\\\Tests\\\\EndToEnd\\\\WrongTaskTest\\:\\:scheduleInstanceProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/EndToEnd/WrongTaskTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Functional/ConfigProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 1 - path: tests/Functional/ConfigProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Functional/ScheduleListTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 1 - path: tests/Functional/ScheduleListTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Functional/ScheduleRunTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 1 - path: tests/Functional/ScheduleRunTest.php - - message: "#^Call to function method_exists\\(\\) with Symfony\\\\Component\\\\Console\\\\Tester\\\\CommandTester and 'setInputs' will always evaluate to true\\.$#" count: 1 @@ -540,16 +420,6 @@ parameters: count: 1 path: tests/Functional/TaskGeneratorTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" - count: 1 - path: tests/Functional/TaskGeneratorTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Functional/TaskGeneratorTest.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 @@ -605,81 +475,21 @@ parameters: count: 1 path: tests/TestCase/TemporaryFile.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 1 - path: tests/Unit/Application/Cron/AbstractCronExpressionTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Application\\\\Cron\\\\AbstractCronExpressionTest\\:\\:multipleRunDatesProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Application/Cron/AbstractCronExpressionTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 1 - path: tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 5 - path: tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Application\\\\Query\\\\TaskInformation\\\\TaskInformationHandlerTest\\:\\:taskInformationProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\)\\.$#" - count: 1 - path: tests/Unit/Configuration/ConfigurationTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\)\\.$#" - count: 1 - path: tests/Unit/Configuration/ConfigurationTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNull\\(\\)\\.$#" - count: 1 - path: tests/Unit/Configuration/ConfigurationTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 6 - path: tests/Unit/Configuration/ConfigurationTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Configuration\\\\ConfigurationTest\\:\\:createConfiguration\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Configuration/ConfigurationTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Unit/Configuration/FileParserTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" - count: 1 - path: tests/Unit/Configuration/FileParserTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:callback\\(\\)\\.$#" - count: 1 - path: tests/Unit/Console/Command/ScheduleRunCommandTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:once\\(\\)\\.$#" - count: 2 - path: tests/Unit/Console/Command/ScheduleRunCommandTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 3 - path: tests/Unit/EnvFlags/EnvFlagsTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\EnvFlags\\\\EnvFlagsTest\\:\\:containerDebugProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -695,41 +505,6 @@ parameters: count: 1 path: tests/Unit/EventRunnerTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:once\\(\\)\\.$#" - count: 3 - path: tests/Unit/EventRunnerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 21 - path: tests/Unit/EventTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" - count: 6 - path: tests/Unit/EventTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 9 - path: tests/Unit/EventTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 2 - path: tests/Unit/EventTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" - count: 6 - path: tests/Unit/EventTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" - count: 6 - path: tests/Unit/EventTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\EventTest\\:\\:deprecatedEveryProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -745,71 +520,16 @@ parameters: count: 1 path: tests/Unit/EventTest.php - - - message: "#^Dynamic call to static method Crunz\\\\Tests\\\\TestCase\\\\UnitTestCase\\:\\:assertDirectoryDoesNotExist\\(\\)\\.$#" - count: 1 - path: tests/Unit/Filesystem/FilesystemTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertDirectoryExists\\(\\)\\.$#" - count: 1 - path: tests/Unit/Filesystem/FilesystemTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" - count: 1 - path: tests/Unit/Filesystem/FilesystemTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 4 - path: tests/Unit/Filesystem/FilesystemTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\)\\.$#" - count: 1 - path: tests/Unit/Filesystem/FilesystemTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringEqualsFile\\(\\)\\.$#" - count: 2 - path: tests/Unit/Filesystem/FilesystemTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Filesystem\\\\FilesystemTest\\:\\:fileExistsProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Filesystem/FilesystemTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\)\\.$#" - count: 2 - path: tests/Unit/Finder/FinderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertContainsOnlyInstancesOf\\(\\)\\.$#" - count: 1 - path: tests/Unit/Finder/FinderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\)\\.$#" - count: 2 - path: tests/Unit/Finder/FinderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" - count: 1 - path: tests/Unit/Finder/FinderTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Finder\\\\FinderTest\\:\\:tasksProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Finder/FinderTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertCount\\(\\)\\.$#" - count: 2 - path: tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Infrastructure\\\\Psr\\\\Logger\\\\EnabledLoggerDecoratorTest\\:\\:disabledChannelProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -820,51 +540,16 @@ parameters: count: 1 path: tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)\\.$#" - count: 1 - path: tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerFactoryTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\)\\.$#" - count: 1 - path: tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 5 - path: tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 4 - path: tests/Unit/InvokerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:exactly\\(\\)\\.$#" - count: 4 - path: tests/Unit/Logger/ConsoleLoggerTest.php - - message: "#^Parameter \\#1 \\$config of class Crunz\\\\Tests\\\\TestCase\\\\FakeConfiguration constructor expects array\\, array\\ given\\.$#" count: 1 path: tests/Unit/Logger/LoggerFactoryTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Unit/Output/OutputFactoryTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Output\\\\OutputFactoryTest\\:\\:inputProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Unit/Output/OutputFactoryTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 3 - path: tests/Unit/Path/PathTest.php - - message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#" count: 1 @@ -885,26 +570,6 @@ parameters: count: 1 path: tests/Unit/Pinger/PingableTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 2 - path: tests/Unit/Schedule/ScheduleFactoryTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 6 - path: tests/Unit/ScheduleTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Unit/Service/AbstractClosureSerializerTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 2 - path: tests/Unit/Task/TaskNumberTest.php - - message: "#^Method Crunz\\\\Tests\\\\Unit\\\\Task\\\\TaskNumberTest\\:\\:nonNumericProvider\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -924,18 +589,3 @@ parameters: message: "#^Parameter \\#1 \\$value of static method Crunz\\\\Task\\\\TaskNumber\\:\\:fromString\\(\\) expects string, mixed given\\.$#" count: 1 path: tests/Unit/Task/TaskNumberTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Unit/Timezone/ProviderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 1 - path: tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" - count: 1 - path: tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php diff --git a/src/Process/Process.php b/src/Process/Process.php index 5732a65..e639c61 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -25,6 +25,14 @@ public static function fromStringCommand(string $command, ?string $cwd = null): return new self($process); } + /** @param string[] $command */ + public static function fromArrayCommand(array $command): self + { + $process = new SymfonyProcess($command); + + return new self($process); + } + /** @param callable|null $callback */ public function start($callback = null): void { @@ -82,4 +90,11 @@ public function errorOutput(): string return $this->process ->getErrorOutput(); } + + public function commandLine(): string + { + return $this->process + ->getCommandLine() + ; + } } diff --git a/src/ProcessUtils.php b/src/ProcessUtils.php deleted file mode 100644 index a0fb707..0000000 --- a/src/ProcessUtils.php +++ /dev/null @@ -1,129 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Crunz; - -use Symfony\Component\Process\Exception\InvalidArgumentException; -use Symfony\Component\Process\Process; - -/** - * ProcessUtils is a bunch of utility methods. - * - * This class contains static methods only and is not meant to be instantiated. - * - * @author Martin HasoĊˆ - * - * @todo Remove this class as it is deprecated in Symfony 3.3 - */ -class ProcessUtils -{ - /** - * This class should not be instantiated. - */ - private function __construct() - { - } - - /** - * Escapes a string to be used as a shell argument. - * - * @param string $argument The argument that will be escaped - * - * @return string The escaped argument - */ - public static function escapeArgument($argument) - { - // Fix for PHP bug #43784 escapeshellarg removes % from given string - // Fix for PHP bug #49446 escapeshellarg doesn't work on Windows - // @see https://bugs.php.net/bug.php?id=43784 - // @see https://bugs.php.net/bug.php?id=49446 - if ('\\' === DIRECTORY_SEPARATOR) { - if ('' === $argument) { - return \escapeshellarg($argument); - } - - $escapedArgument = ''; - $quote = false; - /** @var string[] $parts */ - $parts = \preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); - - foreach ($parts as $part) { - if ('"' === $part) { - $escapedArgument .= '\\"'; - } elseif (self::isSurroundedBy($part, '%')) { - // Avoid environment variable expansion - $escapedArgument .= '^%"' . \mb_substr($part, 1, -1) . '"^%'; - } else { - // escape trailing backslash - if ('\\' === \mb_substr($part, -1)) { - $part .= '\\'; - } - $quote = true; - $escapedArgument .= $part; - } - } - if ($quote) { - $escapedArgument = '"' . $escapedArgument . '"'; - } - - return $escapedArgument; - } - - return "'" . \str_replace("'", "'\\''", $argument) . "'"; - } - - /** - * Validates and normalizes a Process input. - * - * @param string $caller The name of method call that validates the input - * @param mixed $input The input to validate - * - * @return mixed The validated input - * - * @throws InvalidArgumentException In case the input is not valid - */ - public static function validateInput($caller, $input) - { - if (null !== $input) { - if (\is_resource($input)) { - return $input; - } - if (\is_string($input)) { - return $input; - } - if (\is_scalar($input)) { - return (string) $input; - } - if ($input instanceof Process) { - return $input->getIterator($input::ITER_SKIP_ERR); - } - if ($input instanceof \Iterator) { - return $input; - } - if ($input instanceof \Traversable) { - return new \IteratorIterator($input); - } - - throw new InvalidArgumentException(\sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller)); - } - - return $input; - } - - private static function isSurroundedBy(string $arg, string $char): bool - { - return 2 < \mb_strlen($arg) && $char === $arg[0] && $char === $arg[\mb_strlen($arg) - 1]; - } -} diff --git a/src/Schedule.php b/src/Schedule.php index 5776dc4..a4c711f 100644 --- a/src/Schedule.php +++ b/src/Schedule.php @@ -6,6 +6,7 @@ use Crunz\Pinger\PingableInterface; use Crunz\Pinger\PingableTrait; +use Crunz\Process\Process; class Schedule implements PingableInterface { @@ -194,24 +195,45 @@ protected function id() } } - /** - * Compile parameters for a command. - * - * @param string[] $parameters - * - * @return string - */ - protected function compileParameters(array $parameters) + /** @param array $parameters */ + protected function compileParameters(array $parameters): string { - return \implode( - ' ', - \array_map( - function ($value, $key) { - return \is_numeric($key) ? $value : "{$key}=" . (\is_numeric($value) ? $value : ProcessUtils::escapeArgument($value)); + $isStrings = \array_reduce( + $parameters, + static fn (bool $carry, $item): bool => $carry && true === \is_string($item), + true, + ); + if (false === $isStrings) { + @\trigger_error( + 'Passing non-string parameters is deprecated since v3.3, convert all parameters to string.', + \E_USER_DEPRECATED + ); + + $parameters = \array_map( + static function ($value): string { + if (true === \is_bool($value)) { + return true === $value + ? '1' + : '0' + ; + } + + return (string) $value; }, $parameters, - \array_keys($parameters) - ) - ); + ); + } + + $flatParameters = []; + /** @var string[] $parameters */ + foreach ($parameters as $key => $value) { + if (false === \is_numeric($key)) { + $flatParameters[] = $key; + } + + $flatParameters[] = $value; + } + + return Process::fromArrayCommand($flatParameters)->commandLine(); } } diff --git a/tests/EndToEnd/ClosureRunTest.php b/tests/EndToEnd/ClosureRunTest.php index e076f54..d5dc3b0 100644 --- a/tests/EndToEnd/ClosureRunTest.php +++ b/tests/EndToEnd/ClosureRunTest.php @@ -21,7 +21,7 @@ public function closure_tasks(): void $process = $environment->runCrunzCommand('schedule:run'); - $this->assertStringContainsString( + self::assertStringContainsString( 'Closure output Var: 153', \str_replace( PHP_EOL, @@ -53,7 +53,7 @@ public function test_prevent_overlapping_works_on_closures(): void $secondCall = $environment->runCrunzCommand('schedule:run'); $firstCall->wait(); - $this->assertStringContainsString('Done', $firstCall->getOutput()); - $this->assertStringContainsString('No event is due!', $secondCall->getOutput()); + self::assertStringContainsString('Done', $firstCall->getOutput()); + self::assertStringContainsString('No event is due!', $secondCall->getOutput()); } } diff --git a/tests/EndToEnd/ConfigProviderTest.php b/tests/EndToEnd/ConfigProviderTest.php index 34812e2..bcfddcf 100644 --- a/tests/EndToEnd/ConfigProviderTest.php +++ b/tests/EndToEnd/ConfigProviderTest.php @@ -22,9 +22,9 @@ public function test_config_can_be_published(): void $configPath = Path::fromStrings($environment->rootDirectory(), ConfigGeneratorCommand::CONFIG_FILE_NAME); $filesystem = new Filesystem(); - $this->assertTrue($process->isSuccessful(), "Process output: {$process->getOutput()}{$process->errorOutput()}"); - $this->assertFileExists($configPath->toString()); - $this->assertIsArray( + self::assertTrue($process->isSuccessful(), "Process output: {$process->getOutput()}{$process->errorOutput()}"); + self::assertFileExists($configPath->toString()); + self::assertIsArray( Yaml::parse( $filesystem->readContent( $configPath->toString() diff --git a/tests/EndToEnd/ConfigRecognitionTest.php b/tests/EndToEnd/ConfigRecognitionTest.php index 55757a7..656a596 100644 --- a/tests/EndToEnd/ConfigRecognitionTest.php +++ b/tests/EndToEnd/ConfigRecognitionTest.php @@ -30,11 +30,11 @@ public function search_config_in_cwd(): void $process = $environment->runCrunzCommand('schedule:list'); $normalizedOutput = $this->normalizeProcessOutput($process); - $this->assertStringNotContainsString( + self::assertStringNotContainsString( '[Deprecation] Probably you are relying on legacy config file recognition which is deprecated.', $normalizedOutput ); - $this->assertStringNotContainsString( + self::assertStringNotContainsString( '[Deprecation] Probably you are relying on legacy tasks source recognition which is deprecated.', $normalizedOutput ); @@ -43,7 +43,7 @@ public function search_config_in_cwd(): void private function assertHasTask(string $output): void { - $this->assertStringContainsString('PHP version', $output); - $this->assertStringContainsString('php -v', $output); + self::assertStringContainsString('PHP version', $output); + self::assertStringContainsString('php -v', $output); } } diff --git a/tests/EndToEnd/DebugTaskTest.php b/tests/EndToEnd/DebugTaskTest.php index e4b5027..1a1ceff 100644 --- a/tests/EndToEnd/DebugTaskTest.php +++ b/tests/EndToEnd/DebugTaskTest.php @@ -34,14 +34,14 @@ public function test_task_debug(): void $this->assertHeader('example_run_dates', $contentLines); foreach ($expectedValues as $expectedKey => $expectedValue) { - $this->assertArrayHasKey($expectedKey, $contentLines); - $this->assertSame($expectedValue, $contentLines[$expectedKey]); + self::assertArrayHasKey($expectedKey, $contentLines); + self::assertSame($expectedValue, $contentLines[$expectedKey]); } for ($i = 1; $i <= 5; ++$i) { $key = "_{$i}"; - $this->assertArrayHasKey($key, $contentLines); - $this->assertMatchesRegularExpression( + self::assertArrayHasKey($key, $contentLines); + self::assertMatchesRegularExpression( '/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:00 UTC$/', $contentLines[$key] ); @@ -90,7 +90,7 @@ private function extractContentLines(string $output): array /** @param array $lines */ private function assertHeader(string $header, array $lines): void { - $this->assertArrayHasKey($header, $lines); - $this->assertSame('', $lines[$header]); + self::assertArrayHasKey($header, $lines); + self::assertSame('', $lines[$header]); } } diff --git a/tests/EndToEnd/LoggerTest.php b/tests/EndToEnd/LoggerTest.php index 8fa58f4..2b6230a 100644 --- a/tests/EndToEnd/LoggerTest.php +++ b/tests/EndToEnd/LoggerTest.php @@ -55,12 +55,12 @@ public function test_event_logging_override(): void $process = $environment->runCrunzCommand('schedule:run'); - $this->assertEmpty($process->getOutput()); + self::assertEmpty($process->getOutput()); - $this->assertFileDoesNotExist("{$logPath}/main.log"); + self::assertFileDoesNotExist("{$logPath}/main.log"); - $this->assertFileExists("{$logPath}/custom.log"); - $this->assertStringContainsString( + self::assertFileExists("{$logPath}/custom.log"); + self::assertStringContainsString( 'Usage: php', (string) \file_get_contents("{$logPath}/custom.log") ); @@ -73,7 +73,7 @@ private function assertLogRecord( ): void { $levelFormatted = \mb_strtoupper($level); - $this->assertMatchesRegularExpression( + self::assertMatchesRegularExpression( "/^\[[0-9]{4}(-[0-9]{2}){2} [0-9]{2}(:[0-9]{2}){2}\] crunz\.{$levelFormatted}:.+?({$message})/", $logRecord ); diff --git a/tests/EndToEnd/TasksSourceRecognitionTest.php b/tests/EndToEnd/TasksSourceRecognitionTest.php index d4c01e1..806b480 100644 --- a/tests/EndToEnd/TasksSourceRecognitionTest.php +++ b/tests/EndToEnd/TasksSourceRecognitionTest.php @@ -19,7 +19,7 @@ public function search_tasks_in_cwd(): void $process = $environment->runCrunzCommand('schedule:list'); - $this->assertStringNotContainsString( + self::assertStringNotContainsString( '[Deprecation] Probably you are relying on legacy tasks source recognition which', $process->getOutput() ); @@ -41,7 +41,7 @@ public function search_tasks_in_cwd_with_config(): void $process = $environment->runCrunzCommand('schedule:list'); - $this->assertStringNotContainsString( + self::assertStringNotContainsString( '[Deprecation] Probably you are relying on legacy tasks source recognition which', $process->getOutput() ); @@ -50,7 +50,7 @@ public function search_tasks_in_cwd_with_config(): void private function assertHasTask(string $output): void { - $this->assertStringContainsString('PHP version', $output); - $this->assertStringContainsString('php -v', $output); + self::assertStringContainsString('PHP version', $output); + self::assertStringContainsString('php -v', $output); } } diff --git a/tests/EndToEnd/WrongTaskTest.php b/tests/EndToEnd/WrongTaskTest.php index fa09284..6433da8 100644 --- a/tests/EndToEnd/WrongTaskTest.php +++ b/tests/EndToEnd/WrongTaskTest.php @@ -25,8 +25,8 @@ public function every_task_must_return_crunz_schedule_instance(string $crunzComm $process = $environment->runCrunzCommand($crunzCommand); $normalizedOutput = $this->normalizeProcessErrorOutput($process); - $this->assertFalse($process->isSuccessful()); - $this->assertMatchesRegularExpression( + self::assertFalse($process->isSuccessful()); + self::assertMatchesRegularExpression( "@Task at path '.*WrongTasks\\.php' returned 'array', but 'C( ?)runz\\\\Schedule' instance is required\.@", $normalizedOutput ); diff --git a/tests/Functional/ConfigProviderTest.php b/tests/Functional/ConfigProviderTest.php index 71ff719..69f0acd 100644 --- a/tests/Functional/ConfigProviderTest.php +++ b/tests/Functional/ConfigProviderTest.php @@ -19,7 +19,7 @@ public function config_already_exists(): void $commandTester = new CommandTester($command); $returnCode = $commandTester->execute([]); - $this->assertSame(0, $returnCode); - $this->assertStringContainsString('The configuration file already exists at', $commandTester->getDisplay()); + self::assertSame(0, $returnCode); + self::assertStringContainsString('The configuration file already exists at', $commandTester->getDisplay()); } } diff --git a/tests/Functional/ScheduleListTest.php b/tests/Functional/ScheduleListTest.php index 5f2339e..17152dc 100644 --- a/tests/Functional/ScheduleListTest.php +++ b/tests/Functional/ScheduleListTest.php @@ -19,7 +19,7 @@ public function show_list(): void $commandTester = new CommandTester($command); $returnCode = $commandTester->execute([]); - $this->assertSame(0, $returnCode); - $this->assertStringContainsString('Show PHP version', $commandTester->getDisplay()); + self::assertSame(0, $returnCode); + self::assertStringContainsString('Show PHP version', $commandTester->getDisplay()); } } diff --git a/tests/Functional/ScheduleRunTest.php b/tests/Functional/ScheduleRunTest.php index eb7c62a..5609b7f 100644 --- a/tests/Functional/ScheduleRunTest.php +++ b/tests/Functional/ScheduleRunTest.php @@ -19,7 +19,7 @@ public function show_list(): void $commandTester = new CommandTester($command); $returnCode = $commandTester->execute([]); - $this->assertSame(0, $returnCode); - $this->assertStringContainsString(PHP_VERSION, $commandTester->getDisplay()); + self::assertSame(0, $returnCode); + self::assertStringContainsString(PHP_VERSION, $commandTester->getDisplay()); } } diff --git a/tests/Functional/TaskGeneratorTest.php b/tests/Functional/TaskGeneratorTest.php index 5d00cd1..ad2f10a 100644 --- a/tests/Functional/TaskGeneratorTest.php +++ b/tests/Functional/TaskGeneratorTest.php @@ -56,8 +56,8 @@ public function generate_task_file(): void ] ); - $this->assertSame(0, $returnCode); - $this->assertFileExists($this->taskFilePath); + self::assertSame(0, $returnCode); + self::assertFileExists($this->taskFilePath); } /** @return resource */ diff --git a/tests/Unit/Application/Cron/AbstractCronExpressionTest.php b/tests/Unit/Application/Cron/AbstractCronExpressionTest.php index 00f6eb7..e5dc915 100644 --- a/tests/Unit/Application/Cron/AbstractCronExpressionTest.php +++ b/tests/Unit/Application/Cron/AbstractCronExpressionTest.php @@ -29,7 +29,7 @@ public function multiple_run_dates( $timeZone ); - $this->assertEquals($expectedRunDates, $runDates); + self::assertEquals($expectedRunDates, $runDates); } /** @return iterable */ diff --git a/tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php b/tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php index 90693c7..e72c39c 100644 --- a/tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php +++ b/tests/Unit/Application/Query/TaskInformation/TaskInformationHandlerTest.php @@ -38,12 +38,12 @@ public function handle_returns_task_information( ) ); - $this->assertSame($expectedCommand, $taskInformation->command()); - $this->assertSame($expectedDescription, $taskInformation->description()); - $this->assertSame($expectedPreventOverlapping, $taskInformation->preventOverlapping()); - $this->assertSame($expectedCronExpression, $taskInformation->cronExpression()); - $this->assertSame($comparisonsTimeZone, $taskInformation->configTimeZone()); - $this->assertEquals($expectedEventTimeZone, $taskInformation->timeZone()); + self::assertSame($expectedCommand, $taskInformation->command()); + self::assertSame($expectedDescription, $taskInformation->description()); + self::assertSame($expectedPreventOverlapping, $taskInformation->preventOverlapping()); + self::assertSame($expectedCronExpression, $taskInformation->cronExpression()); + self::assertSame($comparisonsTimeZone, $taskInformation->configTimeZone()); + self::assertEquals($expectedEventTimeZone, $taskInformation->timeZone()); } /** @return iterable */ diff --git a/tests/Unit/Configuration/ConfigurationTest.php b/tests/Unit/Configuration/ConfigurationTest.php index d868bd8..ffb2253 100644 --- a/tests/Unit/Configuration/ConfigurationTest.php +++ b/tests/Unit/Configuration/ConfigurationTest.php @@ -23,7 +23,7 @@ public function get_can_return_path_split_by_dot(): void ] ); - $this->assertSame(1234, $configuration->get('smtp.port')); + self::assertSame(1234, $configuration->get('smtp.port')); } /** @test */ @@ -31,8 +31,8 @@ public function get_return_default_value_if_path_not_exists(): void { $configuration = $this->createConfiguration(); - $this->assertNull($configuration->get('wrong')); - $this->assertSame('anon', $configuration->get('notExist', 'anon')); + self::assertNull($configuration->get('wrong')); + self::assertSame('anon', $configuration->get('notExist', 'anon')); } /** @test */ @@ -43,7 +43,7 @@ public function source_path_is_relative_to_cwd(): void $expectedPath = Path::fromStrings($cwd, $sourcePath->toString()); $configuration = $this->createConfiguration(['source' => $sourcePath->toString()], $cwd); - $this->assertSame($expectedPath->toString(), $configuration->getSourcePath()); + self::assertSame($expectedPath->toString(), $configuration->getSourcePath()); } /** @test */ @@ -53,7 +53,7 @@ public function source_path_fallback_to_tasks_directory(): void $expectedPath = Path::fromStrings($cwd, 'tasks'); $configuration = $this->createConfiguration([], $cwd); - $this->assertSame($expectedPath->toString(), $configuration->getSourcePath()); + self::assertSame($expectedPath->toString(), $configuration->getSourcePath()); } /** @test */ @@ -68,7 +68,7 @@ public function set_configuration_key_value(): void $newConfiguration = $configuration->withNewEntry($keyName, $expectedValue); - $this->assertSame($newConfiguration->get($keyName), $expectedValue); + self::assertSame($newConfiguration->get($keyName), $expectedValue); } /** @test */ @@ -85,9 +85,9 @@ public function set_configuration_key_array(): void $newConfiguration = $configuration->withNewEntry("{$arrayName}.{$keyName}", $expectedValue); $expectedArray = $newConfiguration->get($arrayName); - $this->assertIsArray($expectedArray); - $this->assertArrayHasKey($keyName, $expectedArray); - $this->assertSame($expectedArray[$keyName], $expectedValue); + self::assertIsArray($expectedArray); + self::assertArrayHasKey($keyName, $expectedArray); + self::assertSame($expectedArray[$keyName], $expectedValue); } /** @param array $config */ diff --git a/tests/Unit/Configuration/FileParserTest.php b/tests/Unit/Configuration/FileParserTest.php index 3b6f8b2..f2c3479 100644 --- a/tests/Unit/Configuration/FileParserTest.php +++ b/tests/Unit/Configuration/FileParserTest.php @@ -29,7 +29,7 @@ public function parse_throws_exception_on_non_existing_file(): void public function parse_throws_exception_on_non_readable_file(): void { if ($this->isWindows()) { - $this->markTestSkipped('Required Unix-based OS.'); + self::markTestSkipped('Required Unix-based OS.'); } $tempFile = new TemporaryFile(); @@ -56,7 +56,7 @@ public function parse_returns_parsed_file_content(): void $parser = $this->createFileParser(); - $this->assertSame([$configData], $parser->parse($filePath)); + self::assertSame([$configData], $parser->parse($filePath)); } /** diff --git a/tests/Unit/Console/Command/ScheduleRunCommandTest.php b/tests/Unit/Console/Command/ScheduleRunCommandTest.php index b092702..658b355 100644 --- a/tests/Unit/Console/Command/ScheduleRunCommandTest.php +++ b/tests/Unit/Console/Command/ScheduleRunCommandTest.php @@ -97,7 +97,7 @@ private function mockScheduleFactory() $mockSchedule = $this->createConfiguredMock(Schedule::class, ['events' => [$mockEvent]]); $mockScheduleFactory = $this->createMock(Schedule\ScheduleFactory::class); $mockScheduleFactory - ->expects($this->once()) + ->expects(self::once()) ->method('singleTaskSchedule') ->willReturn([$mockSchedule]) ; @@ -110,11 +110,11 @@ private function mockEventRunner(OutputInterface $output): EventRunner { $mockEventRunner = $this->createMock(EventRunner::class); $mockEventRunner - ->expects($this->once()) + ->expects(self::once()) ->method('handle') ->with( $output, - $this->callback( + self::callback( function ($schedules) { $isArray = \is_array($schedules); $count = \count($schedules); diff --git a/tests/Unit/EnvFlags/EnvFlagsTest.php b/tests/Unit/EnvFlags/EnvFlagsTest.php index 7b4192e..2cde38e 100644 --- a/tests/Unit/EnvFlags/EnvFlagsTest.php +++ b/tests/Unit/EnvFlags/EnvFlagsTest.php @@ -18,7 +18,7 @@ public function deprecation_handler_status_is_correct(string $flagValue, bool $e \putenv(EnvFlags::DEPRECATION_HANDLER_FLAG . "={$flagValue}"); $envFlags = new EnvFlags(); - $this->assertSame($expectedEnabled, $envFlags->isDeprecationHandlerEnabled()); + self::assertSame($expectedEnabled, $envFlags->isDeprecationHandlerEnabled()); } /** @test */ @@ -48,7 +48,7 @@ public function container_debug_flag_is_correct(string $flagValue, bool $expecte \putenv(EnvFlags::CONTAINER_DEBUG_FLAG . "={$flagValue}"); $envFlags = new EnvFlags(); - $this->assertSame($expectedEnabled, $envFlags->isContainerDebugEnabled()); + self::assertSame($expectedEnabled, $envFlags->isContainerDebugEnabled()); } /** @test */ @@ -100,6 +100,6 @@ public function containerDebugProvider(): iterable private function assertFlagValue(string $flag, string $expectedValue): void { $actualValue = \getenv($flag); - $this->assertSame($expectedValue, $actualValue); + self::assertSame($expectedValue, $actualValue); } } diff --git a/tests/Unit/EventRunnerTest.php b/tests/Unit/EventRunnerTest.php index 602d0a3..a955208 100644 --- a/tests/Unit/EventRunnerTest.php +++ b/tests/Unit/EventRunnerTest.php @@ -61,7 +61,7 @@ public function test_event_logging_configuration(): void // mock the LoggerFactory $loggerFactory = $this->createMock(LoggerFactory::class); - $loggerFactory->expects($this->once()) + $loggerFactory->expects(self::once()) ->method('createEvent') ->with($logTarget); @@ -90,7 +90,7 @@ public function test_lock_is_released_on_error(): void } $mockStore - ->expects($this->once()) + ->expects(self::once()) ->method('delete') ; $schedule = new Schedule(); @@ -115,7 +115,7 @@ private function createEventRunnerForPing($url) $consoleLogger = $this->createMock(ConsoleLoggerInterface::class); $httpClient - ->expects($this->once()) + ->expects(self::once()) ->method('ping') ->with($url) ; diff --git a/tests/Unit/EventTest.php b/tests/Unit/EventTest.php index ef0a4a2..86fe914 100644 --- a/tests/Unit/EventTest.php +++ b/tests/Unit/EventTest.php @@ -48,28 +48,28 @@ public function tearDown(): void public function test_unit_methods(): void { $e = new Event($this->id, 'php foo'); - $this->assertEquals('0 * * * *', $e->hourly()->getExpression()); + self::assertEquals('0 * * * *', $e->hourly()->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('0 0 * * *', $e->daily()->getExpression()); + self::assertEquals('0 0 * * *', $e->daily()->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('45 15 * * *', $e->dailyAt('15:45')->getExpression()); + self::assertEquals('45 15 * * *', $e->dailyAt('15:45')->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('0 4,8 * * *', $e->twiceDaily(4, 8)->getExpression()); + self::assertEquals('0 4,8 * * *', $e->twiceDaily(4, 8)->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('0 0 * * 0', $e->weekly()->getExpression()); + self::assertEquals('0 0 * * 0', $e->weekly()->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('0 0 1 * *', $e->monthly()->getExpression()); + self::assertEquals('0 0 1 * *', $e->monthly()->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('0 0 1 */3 *', $e->quarterly()->getExpression()); + self::assertEquals('0 0 1 */3 *', $e->quarterly()->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('0 0 1 1 *', $e->yearly()->getExpression()); + self::assertEquals('0 0 1 1 *', $e->yearly()->getExpression()); } /** @@ -80,13 +80,13 @@ public function test_low_level_methods(): void $timezone = new \DateTimeZone('UTC'); $e = new Event($this->id, 'php foo'); - $this->assertEquals('30 1 11 4 *', $e->on('01:30 11-04-2016')->getExpression()); + self::assertEquals('30 1 11 4 *', $e->on('01:30 11-04-2016')->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('45 13 * * *', $e->on('13:45')->getExpression()); + self::assertEquals('45 13 * * *', $e->on('13:45')->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('45 13 * * *', $e->at('13:45')->getExpression()); + self::assertEquals('45 13 * * *', $e->at('13:45')->getExpression()); $e = new Event($this->id, 'php bar'); @@ -96,13 +96,13 @@ public function test_low_level_methods(): void ->month('1-8') ->dayOfWeek('mon,wed,thu'); - $this->assertEquals('12,24,35 1-5,4,8 1,6,12,19,25 1-8 mon,wed,thu', $e->getExpression()); + self::assertEquals('12,24,35 1-5,4,8 1,6,12,19,25 1-8 mon,wed,thu', $e->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('45 13 * * *', $e->cron('45 13 * * *')->getExpression()); + self::assertEquals('45 13 * * *', $e->cron('45 13 * * *')->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertTrue($e->isDue($timezone)); + self::assertTrue($e->isDue($timezone)); } /** @@ -111,22 +111,22 @@ public function test_low_level_methods(): void public function test_weekday_methods(): void { $e = new Event($this->id, 'php qux'); - $this->assertEquals('* * * * 2', $e->tuesdays()->getExpression()); + self::assertEquals('* * * * 2', $e->tuesdays()->getExpression()); $e = new Event($this->id, 'php flob'); - $this->assertEquals('* * * * 3', $e->wednesdays()->getExpression()); + self::assertEquals('* * * * 3', $e->wednesdays()->getExpression()); $e = new Event($this->id, 'php foo'); - $this->assertEquals('* * * * 4', $e->thursdays()->getExpression()); + self::assertEquals('* * * * 4', $e->thursdays()->getExpression()); $e = new Event($this->id, 'php bar'); - $this->assertEquals('* * * * 5', $e->fridays()->getExpression()); + self::assertEquals('* * * * 5', $e->fridays()->getExpression()); $e = new Event($this->id, 'php baz'); - $this->assertEquals('* * * * 1-5', $e->weekdays()->getExpression()); + self::assertEquals('* * * * 1-5', $e->weekdays()->getExpression()); $e = new Event($this->id, 'php bla'); - $this->assertEquals('30 1 * * 2', $e->weeklyOn('2', '01:30')->getExpression()); + self::assertEquals('30 1 * * 2', $e->weeklyOn('2', '01:30')->getExpression()); } public function test_cron_life_time(): void @@ -134,7 +134,7 @@ public function test_cron_life_time(): void $timezone = new \DateTimeZone('UTC'); $event = new Event($this->id, 'php foo'); - $this->assertFalse( + self::assertFalse( $event ->between('2015-01-01', '2015-01-02') ->isDue($timezone) @@ -144,7 +144,7 @@ public function test_cron_life_time(): void $futureDate = new \DateTimeImmutable('+1 year'); $event = new Event($this->id, 'php foo'); - $this->assertFalse( + self::assertFalse( $event ->from($futureDate->format('Y-m-d')) ->isDue($timezone) @@ -152,7 +152,7 @@ public function test_cron_life_time(): void ; $event = new Event($this->id, 'php foo'); - $this->assertFalse( + self::assertFalse( $event ->to('2015-01-01') ->isDue($timezone) @@ -165,16 +165,16 @@ public function test_cron_conditions(): void $timezone = new \DateTimeZone('UTC'); $e = new Event($this->id, 'php foo'); - $this->assertFalse($e->cron('* * * * *')->when(function () { return false; })->isDue($timezone)); + self::assertFalse($e->cron('* * * * *')->when(function () { return false; })->isDue($timezone)); $e = new Event($this->id, 'php foo'); - $this->assertTrue($e->cron('* * * * *')->when(function () { return true; })->isDue($timezone)); + self::assertTrue($e->cron('* * * * *')->when(function () { return true; })->isDue($timezone)); $e = new Event($this->id, 'php foo'); - $this->assertFalse($e->cron('* * * * *')->skip(function () { return true; })->isDue($timezone)); + self::assertFalse($e->cron('* * * * *')->skip(function () { return true; })->isDue($timezone)); $e = new Event($this->id, 'php foo'); - $this->assertTrue($e->cron('* * * * *')->skip(function () { return false; })->isDue($timezone)); + self::assertTrue($e->cron('* * * * *')->skip(function () { return false; })->isDue($timezone)); } /** @test */ @@ -191,7 +191,7 @@ public function test_build_command(): void { $e = new Event($this->id, 'php -i'); - $this->assertSame('php -i', $e->buildCommand()); + self::assertSame('php -i', $e->buildCommand()); } public function test_is_due(): void @@ -200,15 +200,15 @@ public function test_is_due(): void $this->setClockNow(new \DateTimeImmutable('2015-04-12 00:00:00', $timezone)); $e = new Event($this->id, 'php foo'); - $this->assertTrue($e->sundays()->isDue($timezone)); + self::assertTrue($e->sundays()->isDue($timezone)); $e = new Event($this->id, 'php bar'); - $this->assertEquals('0 19 * * 6', $e->saturdays()->at('19:00')->timezone('EST')->getExpression()); - $this->assertTrue($e->isDue($timezone)); + self::assertEquals('0 19 * * 6', $e->saturdays()->at('19:00')->timezone('EST')->getExpression()); + self::assertTrue($e->isDue($timezone)); $e = new Event($this->id, 'php bar'); $this->setClockNow(new \DateTimeImmutable(\date('Y') . '-04-12 00:00:00')); - $this->assertTrue($e->on('00:00 ' . \date('Y') . '-04-12')->isDue($timezone)); + self::assertTrue($e->on('00:00 ' . \date('Y') . '-04-12')->isDue($timezone)); } public function test_name(): void @@ -216,14 +216,14 @@ public function test_name(): void $e = new Event($this->id, 'php foo'); $e->description('Testing Cron'); - $this->assertEquals('Testing Cron', $e->description); + self::assertEquals('Testing Cron', $e->description); } /** @test */ public function in_change_working_directory_in_build_command_on_windows(): void { if (!$this->isWindows()) { - $this->markTestSkipped('Required Windows OS.'); + self::markTestSkipped('Required Windows OS.'); } $workingDir = 'C:\\windows\\temp'; @@ -231,21 +231,21 @@ public function in_change_working_directory_in_build_command_on_windows(): void $event->in($workingDir); - $this->assertSame("cd /d {$workingDir} & php -v", $event->buildCommand()); + self::assertSame("cd /d {$workingDir} & php -v", $event->buildCommand()); } /** @test */ public function in_change_working_directory_in_build_command_on_unix(): void { if ($this->isWindows()) { - $this->markTestSkipped('Required Unix-based OS.'); + self::markTestSkipped('Required Unix-based OS.'); } $event = new Event($this->id, 'php -v'); $event->in('/tmp'); - $this->assertSame('cd /tmp; php -v', $event->buildCommand()); + self::assertSame('cd /tmp; php -v', $event->buildCommand()); } /** @test */ @@ -255,28 +255,28 @@ public function on_do_not_run_task_every_minute(): void $event->on('Thursday 8:00'); - $this->assertSame('0 8 * * *', $event->getExpression()); + self::assertSame('0 8 * * *', $event->getExpression()); } /** @test */ public function setting_user_prepend_sudo_to_command(): void { if ($this->isWindows()) { - $this->markTestSkipped('Required Unix-based OS.'); + self::markTestSkipped('Required Unix-based OS.'); } $event = new Event($this->id, 'php -v'); $event->user('john'); - $this->assertSame('sudo -u john php -v', $event->buildCommand()); + self::assertSame('sudo -u john php -v', $event->buildCommand()); } /** @test */ public function custom_user_and_cwd(): void { if ($this->isWindows()) { - $this->markTestSkipped('Required Unix-based OS.'); + self::markTestSkipped('Required Unix-based OS.'); } $event = new Event($this->id, 'php -i'); @@ -284,14 +284,14 @@ public function custom_user_and_cwd(): void $event->user('john'); $event->in('/var/test'); - $this->assertSame('sudo -u john cd /var/test; sudo -u john php -i', $event->buildCommand()); + self::assertSame('sudo -u john cd /var/test; sudo -u john php -i', $event->buildCommand()); } /** @test */ public function not_implemented_user_change_on_windows(): void { if (!$this->isWindows()) { - $this->markTestSkipped('Required Windows OS.'); + self::markTestSkipped('Required Windows OS.'); } $this->expectException(\Crunz\Exception\NotImplementedException::class); @@ -324,7 +324,7 @@ public function closure_command_have_full_binary_paths(): void $command = $event->buildCommand(); - $this->assertSame(PHP_BINARY . " {$crunzBin} closure:run {$queryClosure}", $command); + self::assertSame(PHP_BINARY . " {$crunzBin} closure:run {$queryClosure}", $command); } /** @test */ @@ -341,12 +341,12 @@ public function whole_output_catches_stdout_and_stderr(): void $wholeOutput = $event->wholeOutput(); - $this->assertStringContainsString( + self::assertStringContainsString( 'Test output', $wholeOutput, 'Missing standard output' ); - $this->assertStringContainsString( + self::assertStringContainsString( 'Exception output', $wholeOutput, 'Missing error output' @@ -363,7 +363,7 @@ public function task_will_prevent_overlapping_with_default_store(): void public function task_will_prevent_overlapping_with_semaphore_store(): void { if (!\extension_loaded('sysvsem')) { - $this->markTestSkipped('Semaphore extension not installed.'); + self::markTestSkipped('Semaphore extension not installed.'); } $this->assertPreventOverlapping(new SemaphoreStore()); @@ -382,7 +382,7 @@ public function test_every_methods(string $method, string $expectedCronExpressio $methodCallClosure(); // Assert - $this->assertSame($expectedCronExpression, $event->getExpression()); + self::assertSame($expectedCronExpression, $event->getExpression()); } public function test_hourly_at_with_valid_minute(): void @@ -395,7 +395,7 @@ public function test_hourly_at_with_valid_minute(): void $event->hourlyAt($minute); // Assert - $this->assertSame("{$minute} * * * *", $event->getExpression()); + self::assertSame("{$minute} * * * *", $event->getExpression()); } /** @dataProvider hourlyAtInvalidProvider */ @@ -461,7 +461,7 @@ private function assertPreventOverlapping(BlockingStoreInterface $store = null): $event->start(); - $this->assertFalse($event2->isDue(new \DateTimeZone('UTC'))); + self::assertFalse($event2->isDue(new \DateTimeZone('UTC'))); } private function createPreventOverlappingEvent(BlockingStoreInterface $store = null): Event diff --git a/tests/Unit/Filesystem/FilesystemTest.php b/tests/Unit/Filesystem/FilesystemTest.php index 13d94b0..1e4b323 100644 --- a/tests/Unit/Filesystem/FilesystemTest.php +++ b/tests/Unit/Filesystem/FilesystemTest.php @@ -16,7 +16,7 @@ public function cwd_is_correct(): void { $filesystem = new Filesystem(); - $this->assertSame(\getcwd(), $filesystem->getCwd()); + self::assertSame(\getcwd(), $filesystem->getCwd()); } /** @@ -27,7 +27,7 @@ public function file_exists_is_correct(string $path, bool $expectedExistence): v { $filesystem = new Filesystem(); - $this->assertSame($expectedExistence, $filesystem->fileExists($path)); + self::assertSame($expectedExistence, $filesystem->fileExists($path)); } /** @test */ @@ -35,7 +35,7 @@ public function temp_directory_return_system_temp_directory(): void { $filesystem = new Filesystem(); - $this->assertSame(\sys_get_temp_dir(), $filesystem->tempDir()); + self::assertSame(\sys_get_temp_dir(), $filesystem->tempDir()); } /** @test */ @@ -57,7 +57,7 @@ public function remove_directory_removes_directories_recursively(): void $filesystem->removeDirectory($rootPath->toString()); - $this->assertDirectoryDoesNotExist($rootPath->toString()); + self::assertDirectoryDoesNotExist($rootPath->toString()); } /** @test */ @@ -70,7 +70,7 @@ public function dump_file_writes_content_to_file(): void $filesystem = new Filesystem(); $filesystem->dumpFile($filePath->toString(), $content); - $this->assertStringEqualsFile($filePath->toString(), $content); + self::assertStringEqualsFile($filePath->toString(), $content); \unlink($filePath->toString()); } @@ -90,7 +90,7 @@ public function create_directory_creates_directory_recursive(): void $filesystem = new Filesystem(); $filesystem->createDirectory($directoryPath->toString()); - $this->assertDirectoryExists($directoryPath->toString()); + self::assertDirectoryExists($directoryPath->toString()); $filesystem->removeDirectory($rootDirectoryPath->toString()); } @@ -109,8 +109,8 @@ public function copy_files(): void $filesystem = new Filesystem(); $filesystem->copy($filePath->toString(), $targetFile->toString()); - $this->assertFileExists($targetFile->toString()); - $this->assertStringEqualsFile($targetFile->toString(), $content); + self::assertFileExists($targetFile->toString()); + self::assertStringEqualsFile($targetFile->toString(), $content); $filesystem->removeDirectory($rootDirectoryPath->toString()); } @@ -120,7 +120,7 @@ public function project_root_directory(): void { $filesystem = new Filesystem(); - $this->assertSame($this->findProjectRootDirectory(), $filesystem->projectRootDirectory()); + self::assertSame($this->findProjectRootDirectory(), $filesystem->projectRootDirectory()); } /** @test */ @@ -129,7 +129,7 @@ public function read_content_return_file_content(): void $filesystem = new Filesystem(); $content = $filesystem->readContent(__FILE__); - $this->assertStringContainsString('final class FilesystemTest extends TestCase', $content); + self::assertStringContainsString('final class FilesystemTest extends TestCase', $content); } /** @test */ diff --git a/tests/Unit/Finder/FinderTest.php b/tests/Unit/Finder/FinderTest.php index 509765b..ea06fcd 100644 --- a/tests/Unit/Finder/FinderTest.php +++ b/tests/Unit/Finder/FinderTest.php @@ -56,8 +56,8 @@ public function find_returns_spl_file_info_collection(string $suffix, Path ...$f $finder = new Finder(); $foundFiles = $finder->find($tasksDirectory, $suffix); - $this->assertCount(\count($files), $foundFiles); - $this->assertContainsOnlyInstancesOf(\SplFileInfo::class, $foundFiles); + self::assertCount(\count($files), $foundFiles); + self::assertContainsOnlyInstancesOf(\SplFileInfo::class, $foundFiles); } /** @@ -98,7 +98,7 @@ public function find_files_in_symlinked_folder(): void if ($this->isWindows()) { // Committed symlinks require extra steps to work on Windows // https://stackoverflow.com/questions/5917249/git-symlinks-in-windows - $this->markTestSkipped('Required Unix-based OS.'); + self::markTestSkipped('Required Unix-based OS.'); } $fixtureDirectory = $this->fixtureDirectory; @@ -108,9 +108,9 @@ public function find_files_in_symlinked_folder(): void $finder = new Finder(); $foundFiles = $finder->find($fixtureDirectory, 'Here.php'); - $this->assertCount(2, $foundFiles); - $this->assertArrayHasKey($directFile, $foundFiles); - $this->assertArrayHasKey($symlinkFileDestination, $foundFiles); + self::assertCount(2, $foundFiles); + self::assertArrayHasKey($directFile, $foundFiles); + self::assertArrayHasKey($symlinkFileDestination, $foundFiles); } private function createFiles(Path ...$files): void diff --git a/tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php b/tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php index 25b0aa6..bbe4dd6 100644 --- a/tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php +++ b/tests/Unit/Infrastructure/Psr/Logger/EnabledLoggerDecoratorTest.php @@ -28,7 +28,7 @@ public function test_disabled_channels_not_log( $enabledLoggerDecorator->log($logLevel, Faker::words()); // Assert - $this->assertCount(0, $spyLogger->getLogs()); + self::assertCount(0, $spyLogger->getLogs()); } /** @dataProvider enabledChannelProvider */ @@ -44,7 +44,7 @@ public function test_enabled_channels_log( $enabledLoggerDecorator->log($logLevel, Faker::words()); // Assert - $this->assertCount(1, $spyLogger->getLogs()); + self::assertCount(1, $spyLogger->getLogs()); } /** @return iterable */ diff --git a/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerFactoryTest.php b/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerFactoryTest.php index 3c31aca..d3e3183 100644 --- a/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerFactoryTest.php +++ b/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerFactoryTest.php @@ -22,7 +22,7 @@ public function test_factory_returns_decorated_logger(): void $logger = $psrStreamLoggerFactory->create(new FakeConfiguration()); // Assert - $this->assertInstanceOf(EnabledLoggerDecorator::class, $logger); + self::assertInstanceOf(EnabledLoggerDecorator::class, $logger); } private function createStreamLoggerFactory(): PsrStreamLoggerFactory diff --git a/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php b/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php index 4ee4fd5..798a093 100644 --- a/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php +++ b/tests/Unit/Infrastructure/Psr/Logger/PsrStreamLoggerTest.php @@ -24,7 +24,7 @@ public function test_supported_levels_are_logged(string $level): void $logger->log($level, $message); - $this->assertSame( + self::assertSame( $this->formatLine( $now, $message, @@ -43,7 +43,7 @@ public function test_unsupported_levels_are_ignored(string $level): void $logger->log($level, $message); - $this->assertEmpty($tempFile->contents()); + self::assertEmpty($tempFile->contents()); } /** @dataProvider supportedLevelsProvider */ @@ -61,7 +61,7 @@ public function test_empty_context_is_ignored(string $level): void $logger->log($level, $message); - $this->assertSame( + self::assertSame( $this->formatLine( $now, $message, @@ -89,7 +89,7 @@ public function test_date_use_passed_time_zone(string $level): void $logger->log($level, $message); - $this->assertSame( + self::assertSame( $this->formatLine( $now, $message, @@ -120,7 +120,7 @@ public function test_logging_with_allowed_line_breaks(string $level): void $logger->log($level, $message); - $this->assertSame( + self::assertSame( $this->formatLine( $now, $message, @@ -143,7 +143,7 @@ public function test_logging_with_disallowed_line_breaks(string $level): void $logger->log($level, $message); - $this->assertSame( + self::assertSame( $this->formatLine( $now, $message, diff --git a/tests/Unit/InvokerTest.php b/tests/Unit/InvokerTest.php index 0ef6022..d8eaae6 100644 --- a/tests/Unit/InvokerTest.php +++ b/tests/Unit/InvokerTest.php @@ -21,8 +21,8 @@ function () use (&$i) { } ); - $this->assertSame(2, $i); - $this->assertSame(2, $result); + self::assertSame(2, $i); + self::assertSame(2, $result); } /** @test */ @@ -38,7 +38,7 @@ function ($number) use (&$i): void { [2] ); - $this->assertSame(3, $i); + self::assertSame(3, $i); } /** @test */ @@ -53,6 +53,6 @@ function (): void { true ); - $this->assertSame('Callback was called, nice.', $result); + self::assertSame('Callback was called, nice.', $result); } } diff --git a/tests/Unit/Logger/ConsoleLoggerTest.php b/tests/Unit/Logger/ConsoleLoggerTest.php index fc4d5ea..45b860d 100644 --- a/tests/Unit/Logger/ConsoleLoggerTest.php +++ b/tests/Unit/Logger/ConsoleLoggerTest.php @@ -21,7 +21,7 @@ public function logger_writes_normal_only_with_suitable_verbosity(int $ioVerbosi $expectedCalls = ($ioVerbosity >= ConsoleLoggerInterface::VERBOSITY_NORMAL) ? 1 : 0; $mockSymfonyStyle = $this->mockSymfonyStyle($ioVerbosity); $mockSymfonyStyle - ->expects($this->exactly($expectedCalls)) + ->expects(self::exactly($expectedCalls)) ->method('writeln') ; @@ -38,7 +38,7 @@ public function logger_writes_verbose_only_with_suitable_verbosity(int $ioVerbos $expectedCalls = ($ioVerbosity >= ConsoleLoggerInterface::VERBOSITY_VERBOSE) ? 1 : 0; $mockSymfonyStyle = $this->mockSymfonyStyle($ioVerbosity); $mockSymfonyStyle - ->expects($this->exactly($expectedCalls)) + ->expects(self::exactly($expectedCalls)) ->method('writeln') ; @@ -55,7 +55,7 @@ public function logger_writes_very_verbose_only_with_suitable_verbosity(int $ioV $expectedCalls = ($ioVerbosity >= ConsoleLoggerInterface::VERBOSITY_VERY_VERBOSE) ? 1 : 0; $mockSymfonyStyle = $this->mockSymfonyStyle($ioVerbosity); $mockSymfonyStyle - ->expects($this->exactly($expectedCalls)) + ->expects(self::exactly($expectedCalls)) ->method('writeln') ; @@ -72,7 +72,7 @@ public function logger_writes_debug_only_with_suitable_verbosity(int $ioVerbosit $expectedCalls = ($ioVerbosity >= ConsoleLoggerInterface::VERBOSITY_DEBUG) ? 1 : 0; $mockSymfonyStyle = $this->mockSymfonyStyle($ioVerbosity); $mockSymfonyStyle - ->expects($this->exactly($expectedCalls)) + ->expects(self::exactly($expectedCalls)) ->method('writeln') ; diff --git a/tests/Unit/Output/OutputFactoryTest.php b/tests/Unit/Output/OutputFactoryTest.php index 44867cc..35cd1fc 100644 --- a/tests/Unit/Output/OutputFactoryTest.php +++ b/tests/Unit/Output/OutputFactoryTest.php @@ -22,7 +22,7 @@ public function input_defines_output_verbosity(InputInterface $input, int $expec $output = $factory->createOutput(); - $this->assertSame($expectedVerbosity, $output->getVerbosity()); + self::assertSame($expectedVerbosity, $output->getVerbosity()); } /** @return iterable */ diff --git a/tests/Unit/Path/PathTest.php b/tests/Unit/Path/PathTest.php index e3111eb..3bf16a4 100644 --- a/tests/Unit/Path/PathTest.php +++ b/tests/Unit/Path/PathTest.php @@ -30,7 +30,7 @@ public function parts_are_delimited_by_directory_separator(): void $path = Path::create($parts); - $this->assertSame( + self::assertSame( \implode(DIRECTORY_SEPARATOR, $parts), $path->toString() ); @@ -48,7 +48,7 @@ public function path_can_be_created_from_strings(): void ]; $path = Path::fromStrings(...$parts); - $this->assertSame( + self::assertSame( \implode(DIRECTORY_SEPARATOR, $parts), $path->toString() ); @@ -64,7 +64,7 @@ public function doubled_directory_separator_is_normalized(): void $path = Path::create($parts); - $this->assertSame( + self::assertSame( 'home' . DIRECTORY_SEPARATOR . 'user', $path->toString() ); diff --git a/tests/Unit/Process/ProcessTest.php b/tests/Unit/Process/ProcessTest.php new file mode 100644 index 0000000..1bfae2e --- /dev/null +++ b/tests/Unit/Process/ProcessTest.php @@ -0,0 +1,44 @@ +assertCommand($expectedCommandLine, $process); + } + + private function assertCommand(string $expectedCommand, Process $process): void + { + if (IS_WINDOWS === true) { + $expectedCommand = \str_replace( + "'", + '', + $expectedCommand, + ); + } + + self::assertSame($expectedCommand, $process->commandLine()); + } +} diff --git a/tests/Unit/Schedule/ScheduleFactoryTest.php b/tests/Unit/Schedule/ScheduleFactoryTest.php index f363c8a..f0cfba6 100644 --- a/tests/Unit/Schedule/ScheduleFactoryTest.php +++ b/tests/Unit/Schedule/ScheduleFactoryTest.php @@ -27,7 +27,7 @@ public function single_task_schedule(): void /** @var Schedule $firstSchedule */ $firstSchedule = \reset($schedules); - $this->assertSame([$event1], $firstSchedule->events()); + self::assertSame([$event1], $firstSchedule->events()); } /** @test */ @@ -42,7 +42,7 @@ public function single_task(): void $event = $factory->singleTask(TaskNumber::fromString('1'), $schedule); - $this->assertSame($event1, $event); + self::assertSame($event1, $event); } /** @test */ diff --git a/tests/Unit/ScheduleTest.php b/tests/Unit/ScheduleTest.php index 48b9842..e2ed2e2 100644 --- a/tests/Unit/ScheduleTest.php +++ b/tests/Unit/ScheduleTest.php @@ -4,33 +4,157 @@ namespace Crunz\Tests\Unit; +use Crunz\Event; use Crunz\Schedule; -use PHPUnit\Framework\TestCase; +use Crunz\Tests\TestCase\UnitTestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; -class ScheduleTest extends TestCase +final class ScheduleTest extends UnitTestCase { - public function test_run(): void + use ExpectDeprecationTrait; + + /** @dataProvider runProvider */ + public function test_run(\Closure $paramsGenerator): void { - $escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\''; - $escapeReal = '\\' === DIRECTORY_SEPARATOR ? '\\"' : '"'; + // Arrange + /** + * @var string $command + * @var string[] $parameters + * @var string $expectedCommand + */ + [ + 'command' => $command, + 'parameters' => $parameters, + 'expectedCommand' => $expectedCommand, + ] = $paramsGenerator(); + $schedule = new Schedule(); + + // Act + $event = $schedule->run($command, $parameters); + // Assert + $this->assertCommand($expectedCommand, $event); + } + + /** + * @group legacy + * @dataProvider nonStringParametersProvider + */ + public function test_run_with_non_string_parameters(\Closure $paramsGenerator): void + { + // Arrange + /** + * @var string $command + * @var string[] $parameters + * @var string $expectedCommand + */ + [ + 'command' => $command, + 'parameters' => $parameters, + 'expectedCommand' => $expectedCommand, + ] = $paramsGenerator(); $schedule = new Schedule(); - $schedule->run('path/to/command'); - $schedule->run('path/to/command -f --foo="bar"'); - $schedule->run('path/to/command', ['-f']); - $schedule->run('path/to/command', ['--foo' => 'bar']); - $schedule->run('path/to/command', ['-f', '--foo' => 'bar']); - $schedule->run('path/to/command', ['--title' => 'A "real" test']); + // Expect + $this->expectDeprecation('Passing non-string parameters is deprecated since v3.3, convert all parameters to string.'); + + // Act + $event = $schedule->run($command, $parameters); + + // Assert + $this->assertCommand($expectedCommand, $event); + } + + /** @return iterable */ + public function runProvider(): iterable + { + yield 'simple command' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => [], + 'expectedCommand' => '/usr/bin/php', + ], + ]; + + yield 'command with inline argument' => [ + static fn (): array => [ + 'command' => '/usr/bin/php -v', + 'parameters' => [], + 'expectedCommand' => '/usr/bin/php -v', + ], + ]; + + yield 'command with argument' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['-v'], + 'expectedCommand' => "/usr/bin/php '-v'", + ], + ]; + + yield 'command with option' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['--ini' => 'php.ini'], + 'expectedCommand' => "/usr/bin/php '--ini' 'php.ini'", + ], + ]; - $events = $schedule->events(); + yield 'command with mixed parameters' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['--ini' => 'php.ini', '-v'], + 'expectedCommand' => "/usr/bin/php '--ini' 'php.ini' '-v'", + ], + ]; + } + + /** @return iterable */ + public function nonStringParametersProvider(): iterable + { + yield 'boolean true parameter' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['-v' => true], + 'expectedCommand' => "/usr/bin/php '-v' '1'", + ], + ]; - $this->assertEquals('path/to/command', $events[0]->getCommand()); - $this->assertEquals('path/to/command -f --foo="bar"', $events[1]->getCommand()); - $this->assertEquals('path/to/command -f', $events[2]->getCommand()); - $this->assertEquals("path/to/command --foo={$escape}bar{$escape}", $events[3]->getCommand()); - $this->assertEquals("path/to/command -f --foo={$escape}bar{$escape}", $events[4]->getCommand()); + yield 'boolean false parameter' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['-v' => false], + 'expectedCommand' => "/usr/bin/php '-v' '0'", + ], + ]; + + yield 'int parameter' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['-v' => 4], + 'expectedCommand' => "/usr/bin/php '-v' '4'", + ], + ]; + + yield 'float parameter' => [ + static fn (): array => [ + 'command' => '/usr/bin/php', + 'parameters' => ['-v' => 3.14], + 'expectedCommand' => "/usr/bin/php '-v' '3.14'", + ], + ]; + } + + private function assertCommand(string $expectedCommand, Event $event): void + { + if (IS_WINDOWS === true) { + $expectedCommand = \str_replace( + "'", + '', + $expectedCommand, + ); + } - $this->assertEquals("path/to/command --title={$escape}A {$escapeReal}real{$escapeReal} test{$escape}", $events[5]->getCommand()); + self::assertSame($expectedCommand, $event->getCommand()); } } diff --git a/tests/Unit/Service/AbstractClosureSerializerTest.php b/tests/Unit/Service/AbstractClosureSerializerTest.php index acd1301..1409790 100644 --- a/tests/Unit/Service/AbstractClosureSerializerTest.php +++ b/tests/Unit/Service/AbstractClosureSerializerTest.php @@ -19,7 +19,7 @@ public function test_closure_code_can_be_extracted(): void $code = $serializer->closureCode($testClosure); // Assert - $this->assertSame('static function (): \stdClass {return new \stdClass(); }', $code); + self::assertSame('static function (): \stdClass {return new \stdClass(); }', $code); } abstract protected function createSerializer(): ClosureSerializerInterface; diff --git a/tests/Unit/Task/TaskNumberTest.php b/tests/Unit/Task/TaskNumberTest.php index ce07aff..9dda515 100644 --- a/tests/Unit/Task/TaskNumberTest.php +++ b/tests/Unit/Task/TaskNumberTest.php @@ -44,7 +44,7 @@ public function task_number_can_be_created_with_numeric_string_value(string $val { $taskNumber = TaskNumber::fromString($value); - $this->assertSame($expectedNumber, $taskNumber->asInt()); + self::assertSame($expectedNumber, $taskNumber->asInt()); } /** @test */ @@ -52,7 +52,7 @@ public function array_index_is_one_step_lower(): void { $taskNumber = TaskNumber::fromString('14'); - $this->assertSame(13, $taskNumber->asArrayIndex()); + self::assertSame(13, $taskNumber->asArrayIndex()); } /** @return iterable */ diff --git a/tests/Unit/Timezone/ProviderTest.php b/tests/Unit/Timezone/ProviderTest.php index 71ccc3c..3ea38f1 100644 --- a/tests/Unit/Timezone/ProviderTest.php +++ b/tests/Unit/Timezone/ProviderTest.php @@ -21,6 +21,6 @@ public function default_timezone_is_returned(): void $provider = new Provider(); $timezone = $provider->defaultTimezone(); - $this->assertSame($timezoneName, $timezone->getName()); + self::assertSame($timezoneName, $timezone->getName()); } } diff --git a/tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php b/tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php index 88933dc..d949306 100644 --- a/tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php +++ b/tests/Unit/UserInterface/Cli/ClosureRunCommandTest.php @@ -21,7 +21,7 @@ public function test_return_value_of_closure_is_omitted(int $returnValue): void $input = $this->createInput($closure); $output = new NullOutput(); - $this->assertSame( + self::assertSame( 0, $command->run($input, $output) ); @@ -32,7 +32,7 @@ public function command_is_hidden(): void { $command = $this->createCommand(); - $this->assertTrue($command->isHidden()); + self::assertTrue($command->isHidden()); } /** @return iterable> */