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
Add --default-time-limit #3224
Merged
sebastianbergmann
merged 12 commits into
sebastianbergmann:master
from
epdenouden:issue-2085-default-time-limit
Sep 8, 2018
Merged
Add --default-time-limit #3224
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f81f22b
Basic config infrastructure to support #2085
epdenouden 25f924d
Restrict default time limit to enforced scenarios
epdenouden 2455907
Add checks for required libraries
epdenouden 5f818d5
Add description of --default-time-limit to CLI help
epdenouden 1a4bd4f
Restore availability checks for php-invoker and pcntl preventing errors
epdenouden f7899ba
Fix test skip-if condition
epdenouden 253bbb2
Cleanup: remove obsolete code
epdenouden d428667
Improved CLI help to match behaviour more closely
epdenouden 4494e22
Improved test coverage when php-invoker is not available
epdenouden 56212b6
Add test coverage for enforceTimeLimit and defaultTimeLimit
epdenouden 1439026
Improve coverage for enforceTimeLimit and defaultTimeLimit
epdenouden fdab4a3
Make new attributes private
epdenouden File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class Issue2085Test extends TestCase | ||
{ | ||
public function testShouldAbortSlowTestByEnforcingTimeLimit(): void | ||
{ | ||
$this->assertTrue(true); | ||
\sleep(1.2); | ||
$this->assertTrue(true); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/Regression/GitHub/2085/configuration_enforce_time_limit_options.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit enforceTimeLimit="true" defaultTimeLimit="1" /> |
31 changes: 31 additions & 0 deletions
31
tests/Regression/GitHub/2085/enforce-time-limit-options-via-config-without-invoker.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
Test XML config enforceTimeLimit, defaultTimeLimit without php-invoker, with pcntl | ||
--SKIPIF-- | ||
<?php | ||
if (\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is installed" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '-c'; | ||
$_SERVER['argv'][2] = __DIR__ . '/configuration_enforce_time_limit_options.xml'; | ||
$_SERVER['argv'][3] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
|
||
Error: Package phpunit/php-invoker is required for enforcing time limits | ||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
OK (1 test, 2 assertions) |
32 changes: 32 additions & 0 deletions
32
tests/Regression/GitHub/2085/issue-2085-test-without-invoker.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
Test CLI flags --enforce-time-limit --default-time-limit without php-invoker, with pcntl | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--SKIPIF-- | ||
<?php | ||
if (\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is installed" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '--no-configuration'; | ||
$_SERVER['argv'][2] = '--enforce-time-limit'; | ||
$_SERVER['argv'][3] = '--default-time-limit=10'; | ||
$_SERVER['argv'][4] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
|
||
Error: Package phpunit/php-invoker is required for enforcing time limits | ||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
OK (1 test, 2 assertions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
Test CLI flags --enforce-time-limit --default-time-limit | ||
--DESCRIPTION-- | ||
https://github.com/sebastianbergmann/phpunit/issues/2085 | ||
--SKIPIF-- | ||
<?php | ||
if (!\class_exists(Invoker::class)) { | ||
print "Skip: package phpunit/php-invoker is required for enforcing time limits" . PHP_EOL; | ||
} | ||
|
||
if (!\extension_loaded('pcntl') || \strpos(\ini_get('disable_functions'), 'pcntl') !== false) { | ||
print "Skip: extension pcntl is required for enforcing time limits" . PHP_EOL; | ||
} | ||
--FILE-- | ||
<?php | ||
$_SERVER['argv'][1] = '--no-configuration'; | ||
$_SERVER['argv'][2] = '--enforce-time-limit'; | ||
$_SERVER['argv'][3] = '--default-time-limit=1'; | ||
$_SERVER['argv'][4] = __DIR__ . '/Issue2085Test.php'; | ||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
PHPUnit\TextUI\Command::main(); | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
R 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s | ||
|
||
There was 1 risky test: | ||
|
||
1) Issue2085Test::testShouldAbortSlowTestByEnforcingTimeLimit | ||
Execution aborted after 1 second | ||
|
||
OK, but incomplete, skipped, or risky tests! | ||
Tests: 1, Assertions: 1, Risky: 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, I would rather not add an option like
--default-time-limit
to set the default time limit on the CLI. The timeouts for@small
,@medium
, and@large
can also only be configured in the configuration file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is true. I asked @reinholdfuereder what the exact use case would be and this time limit is meant to be for tests that are not marked with a
@size
: #2085 (comment)I know a bunch of older test collections with legacy would benefit from this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the trailing
=
, what do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
=
is required for--key=value
, right? I have not found a clean way of doing--key[=value]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
=
means that the option requires a value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarifying, @sebastianbergmann!