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

#11586 Fix duplicated crontab 2>&1 expression #11587

Conversation

adrian-martinez-interactiv4
Copy link
Contributor

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 commented Oct 20, 2017

Description

Installing or removing crontab via command adds 2>&1 repeatedly, even for crontab entries not related with Magento, if they match a regular expression. See details in #11586.

Fixed Issues (if relevant)

  1. Cron install / remove via command messes up stderr 2>&1 entries #11586: Cron install / remove via command messes up stderr 2>&1 entries

Manual testing scenarios

As explained in #11586

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@orlangur orlangur self-assigned this Oct 20, 2017
$arguments = array_map('escapeshellarg', $arguments);
do {
$command = preg_replace('/\s?2>&1\s?\|/', ' |', $command, -1, $count);
} while ($count > 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need a cycle to replace arbitrary amount of occurrences: https://regex101.com/r/kgZCj5/1


$this->assertEquals(
$expectedCommand,
$commandRenderer->render('php -r %s 2>&1 2>&1 | grep %s', [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more than one tested method call per test method, please.

@adrian-martinez-interactiv4
Copy link
Contributor Author

@orlangur reviewed and updated, used dataProvider for tests, and removed cycle for replacing.

);
}

public function testRenderWithoutArguments()
public function testRenderDataProvider()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't start data provider name with test. Describe what it actually returns, like commandsDataProvider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault, I'm changing that

$command = preg_replace('/\s?2>&1\s?\|/', ' |', $command, -1, $count);
} while ($count > 0);

$command = preg_replace('/(\s?2>&1)+\s?\|/', ' |', $command);
$command = preg_replace('/\s?\||$/', ' 2>&1$0', $command);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please combine into just one preg_replace call.

);
$expectedCommand = "php -r %s 2>&1 | grep %s 2>&1";
$expectedCommandArgs = "php -r " . escapeshellarg($testArgument) . " 2>&1 | grep "
. escapeshellarg($testArgument2) . " 2>&1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid logic in tests. Looks like escapeshellarg does not do anything here.

@adrian-martinez-interactiv4
Copy link
Contributor Author

@orlangur Updated according to the review, finally used this regexp: https://regex101.com/r/kgZCj5/2

@orlangur
Copy link
Contributor

Oh, great 👍 Kudos for rewriting it as one clean commit.

@orlangur orlangur added this to the October 2017 milestone Oct 23, 2017
@okorshenko okorshenko merged commit 7c54e6d into magento:2.3-develop Oct 24, 2017
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 deleted the FR#CRON-INSTALL-PARSE-STDERR branch October 24, 2017 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants