feat: inline testing

This commit is contained in:
Nuno Maduro
2022-12-04 18:38:20 +00:00
parent 3324455e0a
commit 7ad045d6b7
7 changed files with 90 additions and 1 deletions

4
.gitattributes vendored
View File

@ -12,3 +12,7 @@ phpstan.neon export-ignore
CHANGELOG.md export-ignore
CONTRIBUTING.md export-ignore
README.md export-ignore
# Inline
/src/NotExported export-ignore
/phpunit.inline.xml export-ignore

View File

@ -51,8 +51,15 @@
},
"require-dev": {
"pestphp/pest-dev-tools": "^2.0.0",
"pestphp/pest-plugin-inline": "2.x-dev",
"symfony/process": "^6.2.0"
},
"repositories": {
"inline": {
"type": "path",
"url": "../pest-plugin-inline"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
@ -70,6 +77,7 @@
"test:lint": "pint --test",
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
"test:unit": "php bin/pest --colors=always --exclude-group=integration --compact",
"test:inline": "php bin/pest --colors=always --configuration=phpunit.inline.xml",
"test:parallel": "exit 1",
"test:integration": "php bin/pest --colors=always --group=integration -v",
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",

34
phpunit.inline.xml Normal file
View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
cacheResult="false"
colors="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="default">
<directory suffix=".php">./src</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Pest\NotExported;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
class MyTestCase extends TestCase // @phpstan-ignore-line
{
public function assertIsTestable(string $testable): void
{
static::assertSame(MyTestableClass::class, $testable);
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Pest\NotExported;
/**
* @internal
*/
final class MyTestableClass
{
public function foo(): void
{
// ...
}
}
it('foo', function () {
$testable = new MyTestableClass();
$this->assertIsTestable(get_class($testable)); // @phpstan-ignore-line
});

View File

@ -23,7 +23,7 @@ final class Plugin
public static function uses(string ...$traits): void
{
self::$callables[] = function () use ($traits): void {
uses(...$traits)->in(TestSuite::getInstance()->rootPath.DIRECTORY_SEPARATOR.testDirectory());
uses(...$traits)->in(TestSuite::getInstance()->rootPath);
};
}
}

View File

@ -1,9 +1,12 @@
<?php
use Pest\NotExported\MyTestCase;
use Tests\CustomTestCaseInSubFolders\SubFolder\SubFolder\CustomTestCaseInSubFolder;
uses(CustomTestCaseInSubFolder::class)->in('PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder');
uses(MyTestCase::class)->in('../src/NotExported');
uses()->group('integration')->in('Visual');
// NOTE: global test value container to be mutated and checked across files, as needed