From 7ad045d6b771dddd929f772d0d1b7adfb363d8ac Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 4 Dec 2022 18:38:20 +0000 Subject: [PATCH] feat: inline testing --- .gitattributes | 4 ++++ composer.json | 8 +++++++ phpunit.inline.xml | 34 +++++++++++++++++++++++++++++ src/NotExported/MyTestCase.php | 18 +++++++++++++++ src/NotExported/MyTestableClass.php | 22 +++++++++++++++++++ src/Plugin.php | 2 +- tests/Pest.php | 3 +++ 7 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 phpunit.inline.xml create mode 100644 src/NotExported/MyTestCase.php create mode 100644 src/NotExported/MyTestableClass.php diff --git a/.gitattributes b/.gitattributes index 3654b689..9f929526 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/composer.json b/composer.json index 31b8bdb7..35dfe005 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpunit.inline.xml b/phpunit.inline.xml new file mode 100644 index 00000000..0e18d164 --- /dev/null +++ b/phpunit.inline.xml @@ -0,0 +1,34 @@ + + + + + ./src + + + + + ./src + + + diff --git a/src/NotExported/MyTestCase.php b/src/NotExported/MyTestCase.php new file mode 100644 index 00000000..1e403fba --- /dev/null +++ b/src/NotExported/MyTestCase.php @@ -0,0 +1,18 @@ +assertIsTestable(get_class($testable)); // @phpstan-ignore-line +}); diff --git a/src/Plugin.php b/src/Plugin.php index 55c91134..54780337 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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); }; } } diff --git a/tests/Pest.php b/tests/Pest.php index d0f656bd..83c8512b 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,9 +1,12 @@ 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