generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ergebnis/feature/example
Enhancement: Add example tests
- Loading branch information
Showing
5 changed files
with
167 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-collector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestCollector\Test\Example; | ||
|
||
use Ergebnis\PHPUnit\SlowTestCollector\Test\Fixture; | ||
use Ergebnis\Test\Util; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\PHPUnit\SlowTestCollector\Test\Fixture\Sleeper | ||
*/ | ||
final class ExampleTest extends Framework\TestCase | ||
{ | ||
use Util\Helper; | ||
|
||
public function testSleeperDoesNotSleepAtAll(): void | ||
{ | ||
$milliseconds = 0; | ||
|
||
$sleeper = Fixture\Sleeper::fromMilliseconds($milliseconds); | ||
|
||
$sleeper->sleep(); | ||
|
||
self::assertSame($milliseconds, $sleeper->milliseconds()); | ||
} | ||
|
||
public function testSleeperSleepsOneQuarterOfASecond(): void | ||
{ | ||
$milliseconds = 250; | ||
|
||
$sleeper = Fixture\Sleeper::fromMilliseconds($milliseconds); | ||
|
||
$sleeper->sleep(); | ||
|
||
self::assertSame($milliseconds, $sleeper->milliseconds()); | ||
} | ||
|
||
public function testSleeperSleepsHalfASeconds(): void | ||
{ | ||
$milliseconds = 500; | ||
|
||
$sleeper = Fixture\Sleeper::fromMilliseconds($milliseconds); | ||
|
||
$sleeper->sleep(); | ||
|
||
self::assertSame($milliseconds, $sleeper->milliseconds()); | ||
} | ||
|
||
public function testSleeperSleepsThreeQuartersOfASecond(): void | ||
{ | ||
$milliseconds = 750; | ||
|
||
$sleeper = Fixture\Sleeper::fromMilliseconds($milliseconds); | ||
|
||
$sleeper->sleep(); | ||
|
||
self::assertSame($milliseconds, $sleeper->milliseconds()); | ||
} | ||
|
||
public function testSleeperSleepsOneSecond(): void | ||
{ | ||
$milliseconds = 1000; | ||
|
||
$sleeper = Fixture\Sleeper::fromMilliseconds($milliseconds); | ||
|
||
$sleeper->sleep(); | ||
|
||
self::assertSame($milliseconds, $sleeper->milliseconds()); | ||
} | ||
} |
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,30 @@ | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutResourceUsageDuringSmallTests="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
bootstrap="../../vendor/autoload.php" | ||
cacheResult="true" | ||
cacheResultFile="../../.build/phpunit/integration.cache" | ||
colors="true" | ||
columns="max" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
executionOrder="random" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Example Tests"> | ||
<directory>.</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-collector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestCollector\Test\Fixture; | ||
|
||
final class Sleeper | ||
{ | ||
private int $milliseconds; | ||
|
||
private function __construct(int $seconds) | ||
{ | ||
$this->milliseconds = $seconds; | ||
} | ||
|
||
/** | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public static function fromMilliseconds(int $milliseconds): self | ||
{ | ||
if (0 > $milliseconds) { | ||
throw new \InvalidArgumentException(\sprintf( | ||
'Value for milliseconds should be greater than or equal to 0, but %d is not.', | ||
$milliseconds | ||
)); | ||
} | ||
|
||
return new self($milliseconds); | ||
} | ||
|
||
public function milliseconds(): int | ||
{ | ||
return $this->milliseconds; | ||
} | ||
|
||
public function sleep(): void | ||
{ | ||
\usleep($this->milliseconds * 1000); | ||
} | ||
} |