Skip to content

Commit

Permalink
Merge pull request #5 from ergebnis/feature/example
Browse files Browse the repository at this point in the history
Enhancement: Add example tests
  • Loading branch information
ergebnis-bot authored Jan 23, 2021
2 parents cb30c17 + 338fd17 commit 09cdee3
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ jobs:
- name: "Run integration tests with phpunit/phpunit"
run: "vendor/bin/phpunit --configuration=test/Integration/phpunit.xml"

- name: "Run example tests with phpunit/phpunit"
run: "vendor/bin/phpunit --configuration=test/Example/phpunit.xml"

code-coverage:
name: "Code Coverage"

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
vendor/bin/psalm --config=psalm.xml --set-baseline=psalm-baseline.xml

.PHONY: tests
tests: vendor ## Runs auto-review, unit, and integration tests with phpunit/phpunit
tests: vendor ## Runs auto-review, unit, integration, and example tests with phpunit/phpunit
mkdir -p .build/phpunit
vendor/bin/phpunit --configuration=test/AutoReview/phpunit.xml
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/Integration/phpunit.xml
vendor/bin/phpunit --configuration=test/Example/phpunit.xml

vendor: composer.json composer.lock
composer validate
Expand Down
83 changes: 83 additions & 0 deletions test/Example/ExampleTest.php
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());
}
}
30 changes: 30 additions & 0 deletions test/Example/phpunit.xml
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>
49 changes: 49 additions & 0 deletions test/Fixture/Sleeper.php
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);
}
}

0 comments on commit 09cdee3

Please sign in to comment.