Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[String] add test case for wordwrap method #35236

Merged
merged 12 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
return $default;
};

$passthruOrFail = function ($command) {
passthru($command, $status);

if ($status) {
exit($status);
}
};

if (PHP_VERSION_ID >= 70200) {
// PHPUnit 8 requires PHP 7.2+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.3');
Expand All @@ -63,9 +71,10 @@
// PHPUnit 6 requires PHP 7.0+
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
} elseif (PHP_VERSION_ID >= 50600) {
// PHPUnit 5 requires PHP 5.6+
// PHPUnit 4 does not support PHP 7
$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
} else {
// PHPUnit 5.1 requires PHP 5.6+
$PHPUNIT_VERSION = '4.8';
}

Expand Down Expand Up @@ -106,7 +115,7 @@
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar 2> /dev/null`))
|| ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer`) : `which composer 2> /dev/null`))
|| file_exists($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? `git rev-parse --show-toplevel 2> NUL` : `git rev-parse --show-toplevel 2> /dev/null`).DIRECTORY_SEPARATOR.'composer.phar')
? (file_get_contents($COMPOSER, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
? (file_get_contents($COMPOSER, false, null, 0, 18) === '#!/usr/bin/env php' ? $PHP : '').' '.escapeshellarg($COMPOSER) // detect shell wrappers by looking at the shebang
: 'composer';

$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml': ''));
Expand All @@ -122,25 +131,25 @@
rename("$PHPUNIT_VERSION_DIR", "$PHPUNIT_VERSION_DIR.old");
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s': 'rm -rf %s', "$PHPUNIT_VERSION_DIR.old"));
}
passthru("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
$passthruOrFail("$COMPOSER create-project --no-install --prefer-dist --no-scripts --no-plugins --no-progress --ansi phpunit/phpunit $PHPUNIT_VERSION_DIR \"$PHPUNIT_VERSION.*\"");
@copy("$PHPUNIT_VERSION_DIR/phpunit.xsd", 'phpunit.xsd');
chdir("$PHPUNIT_VERSION_DIR");
if ($SYMFONY_PHPUNIT_REMOVE) {
passthru("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
$passthruOrFail("$COMPOSER remove --no-update ".$SYMFONY_PHPUNIT_REMOVE);
}
if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) {
passthru("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
$passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\"");
}

passthru("$COMPOSER config --unset platform");
$passthruOrFail("$COMPOSER config --unset platform");
if (file_exists($path = $root.'/vendor/symfony/phpunit-bridge')) {
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
passthru("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*@dev\"");
$passthruOrFail("$COMPOSER config repositories.phpunit-bridge path ".escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $path)));
if ('\\' === DIRECTORY_SEPARATOR) {
file_put_contents('composer.json', preg_replace('/^( {8})"phpunit-bridge": \{$/m', "$0\n$1 ".'"options": {"symlink": false},', file_get_contents('composer.json')));
}
} else {
passthru("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
$passthruOrFail("$COMPOSER require --no-update symfony/phpunit-bridge \"*\"");
}
$prevRoot = getenv('COMPOSER_ROOT_VERSION');
putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99");
Expand Down Expand Up @@ -206,7 +215,7 @@ class SymfonyBlacklistPhpunit {}
$argv[1] = 'src/Symfony';
}
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
// Find Symfony components in plain PHP for Windows portability
// Find Symfony components in plain php for Windows portability

$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
$finder = new RecursiveIteratorIterator($finder);
Expand Down
27 changes: 15 additions & 12 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Process implements \IteratorAggregate
* @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no input
* @param int|float|null $timeout The timeout in seconds or null to disable
*
* @throws RuntimeException When proc_open is not installed
* @throws LogicException When proc_open is not installed
*/
public function __construct(array $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ public function __construct(array $command, string $cwd = null, array $env = nul
*
* @return static
*
* @throws RuntimeException When proc_open is not installed
* @throws LogicException When proc_open is not installed
*/
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
Expand Down Expand Up @@ -219,9 +219,11 @@ public function __clone()
*
* @return int The exit status code
*
* @throws RuntimeException When process can't be launched
* @throws RuntimeException When process stopped after receiving signal
* @throws LogicException In case a callback is provided and output has been disabled
* @throws RuntimeException When process can't be launched
* @throws RuntimeException When process is already running
* @throws ProcessTimedOutException When process timed out
* @throws ProcessSignaledException When process stopped after receiving signal
* @throws LogicException In case a callback is provided and output has been disabled
*
* @final
*/
Expand Down Expand Up @@ -389,9 +391,9 @@ public function restart(callable $callback = null, array $env = []): self
*
* @return int The exitcode of the process
*
* @throws RuntimeException When process timed out
* @throws RuntimeException When process stopped after receiving signal
* @throws LogicException When process is not yet started
* @throws ProcessTimedOutException When process timed out
* @throws ProcessSignaledException When process stopped after receiving signal
* @throws LogicException When process is not yet started
*/
public function wait(callable $callback = null)
{
Expand All @@ -402,7 +404,7 @@ public function wait(callable $callback = null)
if (null !== $callback) {
if (!$this->processPipes->haveReadSupport()) {
$this->stop(0);
throw new \LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait"');
throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::wait"');
}
$this->callback = $this->buildCallback($callback);
}
Expand Down Expand Up @@ -432,8 +434,9 @@ public function wait(callable $callback = null)
* from the output in real-time while writing the standard input to the process.
* It allows to have feedback from the independent process during execution.
*
* @throws RuntimeException When process timed out
* @throws LogicException When process is not yet started
* @throws RuntimeException When process timed out
* @throws LogicException When process is not yet started
* @throws ProcessTimedOutException In case the timeout was reached
*/
public function waitUntil(callable $callback): bool
{
Expand All @@ -442,7 +445,7 @@ public function waitUntil(callable $callback): bool

if (!$this->processPipes->haveReadSupport()) {
$this->stop(0);
throw new \LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::waitUntil".');
throw new LogicException('Pass the callback to the "Process::start" method or call enableOutput to use a callback with "Process::waitUntil".');
}
$callback = $this->buildCallback($callback);

Expand Down
44 changes: 44 additions & 0 deletions src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,50 @@ public static function provideBytesAt(): array
];
}

/**
* @dataProvider wordwrapProvider
*/
public function testWordwrap($expected, $actual, $length, $break, $cut = false)
{
$instance = static::createFromString($actual);
$actual = $instance->wordwrap($length, $break, $cut);

$this->assertEquals($expected, $actual);
}

public function wordwrapProvider()
{
return [
[
'Lo-re-m-Ip-su-m',
'Lorem Ipsum',
2,
'-',
true,
],
[
'Lorem-Ipsum',
'Lorem Ipsum',
2,
'-',
],
[
'Lor-em-Ips-um',
'Lorem Ipsum',
3,
'-',
true,
],
[
'L-o-r-e-m-I-p-s-u-m',
'Lorem Ipsum',
1,
'-',
true,
],
];
}

nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved
/**
* @dataProvider provideWrap
*/
Expand Down