Merge pull request #753 from gehrisandro/fix-tests-in-helpers-directory

[2.x] fix: tests in Helpers directory are not executed
This commit is contained in:
Nuno Maduro
2023-03-30 22:32:13 +01:00
committed by GitHub
7 changed files with 26 additions and 6 deletions

View File

@ -30,7 +30,10 @@ final class Backtrace
$traceFile = str_replace(DIRECTORY_SEPARATOR, '/', $trace[self::FILE]);
if (Str::endsWith($traceFile, 'overrides/Runner/TestSuiteLoader.php')) {
if (
Str::endsWith($traceFile, 'overrides/Runner/TestSuiteLoader.php') ||
Str::endsWith($traceFile, 'src/Bootstrappers/BootFiles.php')
) {
break;
}

View File

@ -1,5 +1,5 @@
.
..
────────────────────────────────────────────────────────────────────────────
FAILED Tests\Fixtures\CollisionTest > error Exception
error
@ -19,4 +19,4 @@
2 src/Factories/TestCaseMethodFactory.php:100
Tests: 1 failed, 1 passed (1 assertions)
Tests: 1 failed, 2 passed (2 assertions)

View File

@ -673,6 +673,7 @@
✓ it throws error if method do not exist
✓ it can forward unexpected calls to any global function
✓ it can use helpers from helpers file
✓ it can use helpers from helpers directory
PASS Tests\Features\HigherOrderTests
✓ it proxies calls to object
@ -789,6 +790,9 @@
PASS Tests\Fixtures\ExampleTest
✓ it example 2
PASS Tests\Helpers\TestInHelpers
✓ it executes tests in the Helpers directory
PASS Tests\Hooks\AfterAllTest
✓ global afterAll execution order
✓ it only gets called once per file
@ -1009,4 +1013,4 @@
PASS Tests\Visual\Version
✓ visual snapshot of help command output
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 706 passed (1707 assertions)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 708 passed (1709 assertions)

View File

@ -44,3 +44,5 @@ it('throws error if method do not exist', function () {
it('can forward unexpected calls to any global function')->_assertThat();
it('can use helpers from helpers file')->myAssertTrue(true);
it('can use helpers from helpers directory')->myDirectoryAssertTrue(true);

6
tests/Helpers/Helper.php Normal file
View File

@ -0,0 +1,6 @@
<?php
function myDirectoryAssertTrue($value)
{
test()->assertTrue($value);
}

View File

@ -0,0 +1,5 @@
<?php
it('executes tests in the Helpers directory', function () {
expect(true)->toBeTrue();
});

View File

@ -18,10 +18,10 @@ $run = function () {
test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 694 passed (1692 assertions)')
->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 696 passed (1694 assertions)')
->toContain('Parallel: 3 processes');
})->skip(PHP_OS_FAMILY === 'Windows');
test('a parallel test can extend another test with same name', function () use ($run) {
expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 1 passed (1 assertions)');
expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)');
});