Merge branch '2.x' into dataset-arguments-check

This commit is contained in:
Nuno Maduro
2023-03-21 21:10:22 +00:00
committed by GitHub
56 changed files with 550 additions and 648 deletions

View File

@ -1,6 +1,6 @@
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:302|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:302|nat src/Concerns/Testable.php:221|nat src/Kernel.php:84' type='comparisonFailure' actual='true' expected='false' flowId='1234']
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
@ -9,7 +9,7 @@
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:302|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:302|nat src/Concerns/Testable.php:221|nat src/Kernel.php:84' flowId='1234']
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.x-dev.
Pest Testing Framework 2.1.0.
USAGE: pest <file> [options]
@ -33,6 +33,7 @@
--test-suffix [suffixes] Only search for test in files with specified suffix(es). Default: Test.php,.phpt
EXECUTION OPTIONS:
--parallel ........................................... Run tests in parallel
--process-isolation ................ Run each test in a separate PHP process
--globals-backup ................. Backup and restore $GLOBALS for each test
--static-backup ......... Backup and restore static properties for each test

View File

@ -4,6 +4,9 @@
✓ dependencies
✓ contracts
PASS Tests\Environments\Windows
✓ global functions are loaded
PASS Tests\Features\AfterAll
✓ deletes file after all
@ -331,12 +334,14 @@
PASS Tests\Features\Expect\toBeGreatherThan
✓ passes
✓ passes with DateTime and DateTimeImmutable
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeGreatherThanOrEqual
✓ passes
✓ passes with DateTime and DateTimeImmutable
✓ failures
✓ failures with custom message
✓ not failures
@ -379,12 +384,14 @@
PASS Tests\Features\Expect\toBeLessThan
✓ passes
✓ passes with DateTime and DateTimeImmutable
✓ failures
✓ failures with custom message
✓ not failures
PASS Tests\Features\Expect\toBeLessThanOrEqual
✓ passes
✓ passes with DateTime and DateTimeImmutable
✓ failures
✓ failures with custom message
✓ not failures
@ -837,15 +844,6 @@
✓ it allows global uses
✓ it allows multiple global uses registered in the same path
WARN Tests\Unit\ConfigLoader
✓ it fallbacks to default path if no phpunit file is found
- it fallbacks to default path if phpunit is not a valid XML
- it fallbacks to default path if failing to read phpunit content
- it fallbacks to default path if there is no test suites directory
- it fallbacks to default path if test suite directory has no value
- it fallbacks to default path if test suite directory does not exist
- it returns the parent folder of first test suite directory
PASS Tests\Unit\Console\Help
✓ it outputs the help information when --help is used
@ -910,6 +908,59 @@
✓ it evaluates the code with ('version__ ', '__pest_evaluable_version___')
✓ it evaluates the code with ('version\', '__pest_evaluable_version_')
PASS Tests\Unit\TestName
✓ it may start with P with ('P\Tests\BarTest', 'Tests\BarTest')
✓ it may start with P with ('P\Packages\Foo', 'Packages\Foo')
✓ it may start with P with ('P\PPPackages\Foo', 'PPPackages\Foo')
✓ it may start with P with ('PPPackages\Foo', 'PPPackages\Foo') #1
✓ it may start with P with ('PPPackages\Foo', 'PPPackages\Foo') #2
✓ ふ+が+
✓ ほげ
✓ 卜竹弓一十山
✓ アゴデヸ
✓ !p8VrB
✓ &xe6VeKWF#n4
✓ %%HurHUnw7zM!
✓ rundeliekend
✓ g%%c!Jt9$fy#Kf
✓ NRs*Gz2@hmB$W$BPD%%b2U%3P%z%apnwSX
✓ ÀĤ{¼÷
✓ ìèéàòç
✓ زهراء المعادي
✓ الجبيهه
✓ الظهران
✓ Каролин
✓ অ্যান্টার্কটিকা
✓ Frýdek-Místek"
✓ Allingåbro&
✓ Κεντροαφρικανική Δημοκρατία
✓ آذربایجان غربی
✓ זימבבואה
✓ Belišće
✓ Գվատեմալա
✓ パプアニューギニア
✓ 富山県
✓ Қарағанды
✓ Қостанай
✓ 안양시 동안구
✓ Itālija
✓ Honningsvåg
✓ Águeda
✓ Râșcani
✓ Năsăud
✓ Орехово-Зуево
✓ Čereňany
✓ Moravče
✓ Šentjernej
✓ Врање
✓ Крушевац
✓ Åkersberga
✓ บอสเนียและเฮอร์เซโกวีนา
✓ Birleşik Arap Emirlikleri
✓ Німеччина
✓ Nam Định
✓ 呼和浩特
PASS Tests\Unit\TestSuite
✓ it does not allow to add the same test description twice
✓ it alerts users about tests with arguments but no input
@ -943,4 +994,4 @@
PASS Tests\Visual\Version
✓ visual snapshot of help command output
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 644 passed (1586 assertions)
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 12 skipped, 699 passed (1696 assertions)

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.x-dev.
Pest Testing Framework 2.1.0.

View File

@ -0,0 +1,5 @@
<?php
test('global functions are loaded', function () {
expect(helper_returns_string())->toBeString();
});

View File

@ -19,7 +19,7 @@ it('throws exception if dataset does not exist', function () {
it('throws exception if dataset already exist', function () {
DatasetsRepository::set('second', [[]], __DIR__);
$this->expectException(DatasetAlreadyExists::class);
$this->expectExceptionMessage('A dataset with the name `second` already exist in scope ['.__DIR__.'].');
$this->expectExceptionMessage('A dataset with the name `second` already exists in scope ['.__DIR__.'].');
DatasetsRepository::set('second', [[]], __DIR__);
});

View File

@ -7,6 +7,15 @@ test('passes', function () {
expect(4)->toBeGreaterThan(3.9);
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
expect($now)->toBeGreaterThan($past);
expect($past)->not->toBeGreaterThan($now);
});
test('failures', function () {
expect(4)->toBeGreaterThan(4);
})->throws(ExpectationFailedException::class);

View File

@ -7,6 +7,17 @@ test('passes', function () {
expect(4)->toBeGreaterThanOrEqual(4);
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
expect($now)->toBeGreaterThanOrEqual($now);
expect($now)->toBeGreaterThanOrEqual($past);
expect($past)->not->toBeGreaterThanOrEqual($now);
});
test('failures', function () {
expect(4)->toBeGreaterThanOrEqual(4.1);
})->throws(ExpectationFailedException::class);

View File

@ -7,6 +7,15 @@ test('passes', function () {
expect(4)->toBeLessThan(5);
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
expect($past)->toBeLessThan($now);
expect($now)->not->toBeLessThan($now);
});
test('failures', function () {
expect(4)->toBeLessThan(4);
})->throws(ExpectationFailedException::class);

View File

@ -7,6 +7,17 @@ test('passes', function () {
expect(4)->toBeLessThanOrEqual(4);
});
test('passes with DateTime and DateTimeImmutable', function () {
$now = new DateTime();
$past = (new DateTimeImmutable())->modify('-1 day');
expect($now)->toBeLessThanOrEqual($now);
expect($past)->toBeLessThanOrEqual($now);
expect($now)->not->toBeLessThanOrEqual($past);
});
test('failures', function () {
expect(4)->toBeLessThanOrEqual(3.9);
})->throws(ExpectationFailedException::class);

View File

@ -25,3 +25,8 @@ uses()
$_SERVER['globalHook']->calls->afterAll++;
})
->in('Hooks');
function helper_returns_string()
{
return 'string';
}

View File

@ -1,19 +0,0 @@
<?php
use Pest\ConfigLoader;
use Pest\Support\Reflection;
it('fallbacks to default path if no phpunit file is found', function () {
$instance = new ConfigLoader('fake-path');
expect(Reflection::getPropertyValue($instance, 'config'))->toBeNull();
expect($instance->getConfigurationFilePath())->toBeFalse();
expect($instance->getTestsDirectory())->toBe(ConfigLoader::DEFAULT_TESTS_PATH);
});
it('fallbacks to default path if phpunit is not a valid XML')->skip();
it('fallbacks to default path if failing to read phpunit content')->skip();
it('fallbacks to default path if there is no test suites directory')->skip();
it('fallbacks to default path if test suite directory has no value')->skip();
it('fallbacks to default path if test suite directory does not exist')->skip();
it('returns the parent folder of first test suite directory')->skip();

70
tests/Unit/TestName.php Normal file
View File

@ -0,0 +1,70 @@
<?php
it('may start with P', function (string $real, string $toBePrinted) {
$printed = preg_replace('/P\\\/', '', $real, 1);
expect($printed)->toBe($toBePrinted);
})->with([
['P\Tests\BarTest', 'Tests\BarTest'],
['P\Packages\Foo', 'Packages\Foo'],
['P\PPPackages\Foo', 'PPPackages\Foo'],
['PPPackages\Foo', 'PPPackages\Foo'],
['PPPackages\Foo', 'PPPackages\Foo'],
]);
$names = [
'ふ+が+' => '__pest_evaluable_ふ_が_',
'ほげ' => '__pest_evaluable_ほげ',
'卜竹弓一十山' => '__pest_evaluable_卜竹弓一十山',
'アゴデヸ' => '__pest_evaluable_アゴデヸ',
'!p8VrB' => '__pest_evaluable__p8VrB',
'&xe6VeKWF#n4' => '__pest_evaluable__xe6VeKWF_n4',
'%%HurHUnw7zM!' => '__pest_evaluable___HurHUnw7zM_',
'rundeliekend' => '__pest_evaluable_rundeliekend',
'g%%c!Jt9$fy#Kf' => '__pest_evaluable_g__c_Jt9_fy_Kf',
'NRs*Gz2@hmB$W$BPD%%b2U%3P%z%apnwSX' => '__pest_evaluable_NRs_Gz2_hmB_W_BPD__b2U_3P_z_apnwSX',
'ÀĤ{¼÷' => '__pest_evaluable_ÀĤ_¼÷',
'ìèéàòç' => '__pest_evaluable_ìèéàòç',
'زهراء المعادي' => '__pest_evaluable_زهراء_المعادي',
'الجبيهه' => '__pest_evaluable_الجبيهه',
'الظهران' => '__pest_evaluable_الظهران',
'Каролин' => '__pest_evaluable_Каролин',
'অ্যান্টার্কটিকা' => '__pest_evaluable_অ্যান্টার্কটিকা',
'Frýdek-Místek"' => '__pest_evaluable_Frýdek_Místek_',
'Allingåbro&' => '__pest_evaluable_Allingåbro_',
'Κεντροαφρικανική Δημοκρατία' => '__pest_evaluable_Κεντροαφρικανική_Δημοκρατία',
'آذربایجان غربی' => '__pest_evaluable_آذربایجان_غربی',
'זימבבואה' => '__pest_evaluable_זימבבואה',
'Belišće' => '__pest_evaluable_Belišće',
'Գվատեմալա' => '__pest_evaluable_Գվատեմալա',
'パプアニューギニア' => '__pest_evaluable_パプアニューギニア',
'富山県' => '__pest_evaluable_富山県',
'Қарағанды' => '__pest_evaluable_Қарағанды',
'Қостанай' => '__pest_evaluable_Қостанай',
'안양시 동안구' => '__pest_evaluable_안양시_동안구',
'Itālija' => '__pest_evaluable_Itālija',
'Honningsvåg' => '__pest_evaluable_Honningsvåg',
'Águeda' => '__pest_evaluable_Águeda',
'Râșcani' => '__pest_evaluable_Râșcani',
'Năsăud' => '__pest_evaluable_Năsăud',
'Орехово-Зуево' => '__pest_evaluable_Орехово_Зуево',
'Čereňany' => '__pest_evaluable_Čereňany',
'Moravče' => '__pest_evaluable_Moravče',
'Šentjernej' => '__pest_evaluable_Šentjernej',
'Врање' => '__pest_evaluable_Врање',
'Крушевац' => '__pest_evaluable_Крушевац',
'Åkersberga' => '__pest_evaluable_Åkersberga',
'บอสเนียและเฮอร์เซโกวีนา' => '__pest_evaluable_บอสเนียและเฮอร์เซโกวีนา',
'Birleşik Arap Emirlikleri' => '__pest_evaluable_Birleşik_Arap_Emirlikleri',
'Німеччина' => '__pest_evaluable_Німеччина',
'Nam Định' => '__pest_evaluable_Nam_Định',
'呼和浩特' => '__pest_evaluable_呼和浩特',
];
foreach ($names as $name => $methodName) {
test($name)
->expect(fn () => static::getLatestPrintableTestCaseMethodName())
->toBe($name)
->and(fn () => $this->name())
->toBe($methodName);
}

View File

@ -13,7 +13,7 @@ it('does not allow to add the same test description twice', function () {
$testSuite->tests->set($method);
})->throws(
TestAlreadyExist::class,
sprintf('A test with the description `%s` already exist in the filename `%s`.', 'bar', 'foo'),
sprintf('A test with the description `%s` already exists in the filename `%s`.', 'bar', 'foo'),
);
it('alerts users about tests with arguments but no input', function () {

View File

@ -9,12 +9,12 @@ $run = function () {
$process->run();
expect($process->getExitCode())->toBe(0);
// expect($process->getExitCode())->toBe(0);
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
test('parallel', function () use ($run) {
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 635 passed (1573 assertions)')
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 9 skipped, 690 passed (1684 assertions)')
->toContain('Parallel: 3 processes');
})->skip(PHP_OS_FAMILY === 'Windows');

View File

@ -25,9 +25,9 @@ $snapshot = function ($name) {
};
test('todo', function () use ($run, $snapshot) {
expect($run('--todo', false))->toContain($snapshot('todo'));
expect($run('--todos', false))->toContain($snapshot('todo'));
})->skip(PHP_OS_FAMILY === 'Windows');
test('todo in parallel', function () use ($run, $snapshot) {
expect($run('--todo', true))->toContain($snapshot('todo'));
expect($run('--todos', true))->toContain($snapshot('todo'));
})->skip(PHP_OS_FAMILY === 'Windows');