diff --git a/composer.json b/composer.json index 4bee4a38..ce14bb71 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "test:types": "phpstan analyse --ansi", "test:unit": "php bin/pest --colors=always --exclude-group=integration", "test:integration": "php bin/pest --colors=always --group=integration", - "test:integration:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", + "test:update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", "test": [ "@test:lint", "@test:types", diff --git a/tests/.snapshots/coverage.txt b/tests/.snapshots/coverage.txt new file mode 100644 index 00000000..e7cf7549 --- /dev/null +++ b/tests/.snapshots/coverage.txt @@ -0,0 +1,60 @@ + + PASS Tests\Playground + ✓ basic + + Tests: 1 passed + Time: 0.20s + Cov: 6.49% + + Actions/AddsDefaults ........................................... 0.0 % + Actions/AddsTests .............................................. 0.0 % + Actions/LoadStructure .......................................... 0.0 % + Actions/ValidatesConfiguration ................................. 0.0 % + Actions/ValidatesEnvironment ................................... 0.0 % + Concerns/TestCase 40..54, 71..88, 123..126, 147 ............... 44.4 % + Console/Command ................................................ 0.0 % + Contracts/HasPrintableTestCaseName ............................. 0.0 % + Contracts/Plugins/AddsOutput ................................ 100.0 % + Contracts/Plugins/HandlesArguments .......................... 100.0 % + Datasets ....................................................... 0.0 % + Exceptions/AfterAllAlreadyExist ................................ 0.0 % + Exceptions/AfterEachAlreadyExist ............................... 0.0 % + Exceptions/AttributeNotSupportedYet ............................ 0.0 % + Exceptions/BeforeEachAlreadyExist .............................. 0.0 % + Exceptions/DatasetAlreadyExist ................................. 0.0 % + Exceptions/DatasetDoesNotExist ................................. 0.0 % + Exceptions/FileOrFolderNotFound ................................ 0.0 % + Exceptions/InvalidConsoleArgument .............................. 0.0 % + Exceptions/InvalidPestCommand .................................. 0.0 % + Exceptions/InvalidUsesPath ..................................... 0.0 % + Exceptions/ShouldNotHappen ..................................... 0.0 % + Exceptions/TestAlreadyExist .................................... 0.0 % + Exceptions/TestCaseAlreadyInUse ................................ 0.0 % + Exceptions/TestCaseClassOrTraitNotFound ........................ 0.0 % + Factories/TestCaseFactory 111..133, 141..204 ................... 8.2 % + Laravel/Commands/PestDatasetCommand ............................ 0.0 % + Laravel/Commands/PestInstallCommand ............................ 0.0 % + Laravel/Commands/PestTestCommand ............................... 0.0 % + Laravel/PestServiceProvider .................................... 0.0 % + PendingObjects/AfterEachCall ................................... 0.0 % + PendingObjects/BeforeEachCall .................................. 0.0 % + PendingObjects/TestCall ........................................ 0.0 % + PendingObjects/UsesCall ........................................ 0.0 % + Plugin ......................................................... 0.0 % + Repositories/AfterAllRepository ................................ 0.0 % + Repositories/AfterEachRepository 28..33 ....................... 60.0 % + Repositories/BeforeAllRepository ............................... 0.0 % + Repositories/BeforeEachRepository 26..31 ...................... 20.0 % + Repositories/TestRepository .................................... 0.0 % + Support/Backtrace .............................................. 0.0 % + Support/ChainableClosure .................................... 100.0 % + Support/Container .............................................. 0.0 % + Support/ExceptionTrace 25..32 ................................. 28.6 % + Support/HigherOrderMessage ..................................... 0.0 % + Support/HigherOrderMessageCollection 24..25, 33, 43 ........... 50.0 % + Support/HigherOrderTapProxy .................................... 0.0 % + Support/NullClosure ......................................... 100.0 % + Support/Reflection ............................................. 0.0 % + Support/Str .................................................... 0.0 % + TestSuite 80..87, 95..101, 105 ................................ 20.0 % + globals ........................................................ 0.0 % diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 1db9c356..c6c462a4 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -121,10 +121,10 @@ PASS Tests\Unit\Support\Container ✓ it exists ✓ it gets an instance + ✓ autowire ✓ it creates an instance and resolves parameters ✓ it creates an instance and resolves also sub parameters ✓ it can resolve builtin value types - ✓ it cannot resolve a parameter that requires additional dependencies ✓ it cannot resolve a parameter without type PASS Tests\Unit\Support\Reflection @@ -134,6 +134,9 @@ PASS Tests\Unit\TestSuite ✓ it does not allow to add the same test description twice + PASS Tests\Visual\Coverage + ✓ coverage + PASS Tests\Visual\SingleTestOrDirectory ✓ allows to run a single test ✓ allows to run a directory @@ -143,5 +146,5 @@ WARN Tests\Visual\Success s visual snapshot of test suite on success - Tests: 6 skipped, 78 passed - Time: 3.40s + Tests: 6 skipped, 79 passed + Time: 3.91s diff --git a/tests/Visual/Coverage.php b/tests/Visual/Coverage.php new file mode 100644 index 00000000..a7b6d7a2 --- /dev/null +++ b/tests/Visual/Coverage.php @@ -0,0 +1,30 @@ +run(); + + return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); +}; + +$snapshot = function ($name) { + $testsPath = dirname(__DIR__); + + return file_get_contents(implode(DIRECTORY_SEPARATOR, [ + $testsPath, + '.snapshots', + "$name.txt", + ])); +}; + +test('coverage', function () use ($run, $snapshot) { + $text = $run('tests/Playground.php'); + + assertStringContainsString( + $snapshot('coverage'), + $run('tests/Playground.php') + ); +})->skip(PHP_OS_FAMILY === 'Windows');