mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
Merge branch '4.x' into fix/sibling-describe-blocks
This commit is contained in:
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Pest\PendingCalls\TestCall;
|
||||
use Pest\TestSuite;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\CoversFunction;
|
||||
use Tests\Fixtures\Covers\CoversClass1;
|
||||
use Tests\Fixtures\Covers\CoversClass3;
|
||||
use Tests\Fixtures\Covers\CoversTrait;
|
||||
|
||||
$runCounter = 0;
|
||||
|
||||
function testCoversFunction() {}
|
||||
|
||||
covers([CoversClass1::class]);
|
||||
|
||||
it('uses the correct PHPUnit attribute for class', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[1]->getName())->toBe('PHPUnit\Framework\Attributes\CoversClass');
|
||||
expect($attributes[1]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversClass1');
|
||||
});
|
||||
|
||||
it('uses the correct PHPUnit attribute for function', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[3]->getName())->toBe('PHPUnit\Framework\Attributes\CoversFunction');
|
||||
expect($attributes[3]->getArguments()[0])->toBe('testCoversFunction');
|
||||
})->coversFunction('testCoversFunction');
|
||||
|
||||
it('guesses if the given argument is a class or function', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[5]->getName())->toBe(CoversClass::class);
|
||||
expect($attributes[5]->getArguments()[0])->toBe(CoversClass3::class);
|
||||
|
||||
expect($attributes[6]->getName())->toBe(CoversFunction::class);
|
||||
expect($attributes[6]->getArguments()[0])->toBe('testCoversFunction');
|
||||
})->covers(CoversClass3::class, 'testCoversFunction');
|
||||
|
||||
it('uses the correct PHPUnit attribute for trait', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[8]->getName())->toBe('PHPUnit\Framework\Attributes\CoversTrait');
|
||||
expect($attributes[8]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversTrait');
|
||||
})->coversTrait(CoversTrait::class);
|
||||
|
||||
it('uses the correct PHPUnit attribute for covers nothing', function () {
|
||||
$attributes = (new ReflectionMethod($this, $this->name()))->getAttributes();
|
||||
|
||||
expect($attributes[3]->getName())->toBe('PHPUnit\Framework\Attributes\CoversNothing');
|
||||
expect($attributes[3]->getArguments())->toHaveCount(0);
|
||||
})->coversNothing();
|
||||
|
||||
it('throws exception if no class nor method has been found', function () {
|
||||
$testCall = new TestCall(TestSuite::getInstance(), 'filename', 'description', fn () => 'closure');
|
||||
|
||||
$testCall->covers('fakeName');
|
||||
})->throws(InvalidArgumentException::class, 'No class, trait or method named "fakeName" has been found.');
|
||||
13
tests/Features/Covers/ClassCoverage.php
Normal file
13
tests/Features/Covers/ClassCoverage.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Tests\Fixtures\Covers\CoversClass1;
|
||||
|
||||
covers([CoversClass1::class]);
|
||||
|
||||
it('uses the correct PHPUnit attribute for class', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[1]->getName())->toBe(CoversClass::class);
|
||||
expect($attributes[1]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversClass1');
|
||||
});
|
||||
10
tests/Features/Covers/CoversNothing.php
Normal file
10
tests/Features/Covers/CoversNothing.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversNothing;
|
||||
|
||||
it('uses the correct PHPUnit attribute for covers nothing', function () {
|
||||
$attributes = (new ReflectionMethod($this, $this->name()))->getAttributes();
|
||||
|
||||
expect($attributes[2]->getName())->toBe(CoversNothing::class);
|
||||
expect($attributes[2]->getArguments())->toHaveCount(0);
|
||||
})->coversNothing();
|
||||
10
tests/Features/Covers/ExceptionHandling.php
Normal file
10
tests/Features/Covers/ExceptionHandling.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Pest\PendingCalls\TestCall;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('throws exception if no class nor method has been found', function () {
|
||||
$testCall = new TestCall(TestSuite::getInstance(), 'filename', 'description', fn () => 'closure');
|
||||
|
||||
$testCall->covers('fakeName');
|
||||
})->throws(InvalidArgumentException::class, 'No class, trait or method named "fakeName" has been found.');
|
||||
12
tests/Features/Covers/FunctionCoverage.php
Normal file
12
tests/Features/Covers/FunctionCoverage.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversFunction;
|
||||
|
||||
function testCoversFunction() {}
|
||||
|
||||
it('uses the correct PHPUnit attribute for function', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[1]->getName())->toBe(CoversFunction::class);
|
||||
expect($attributes[1]->getArguments()[0])->toBe('testCoversFunction');
|
||||
})->coversFunction('testCoversFunction');
|
||||
17
tests/Features/Covers/GuessCoverage.php
Normal file
17
tests/Features/Covers/GuessCoverage.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\CoversFunction;
|
||||
use Tests\Fixtures\Covers\CoversClass3;
|
||||
|
||||
function testCoversFunction2() {}
|
||||
|
||||
it('guesses if the given argument is a class or function', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[1]->getName())->toBe(CoversClass::class);
|
||||
expect($attributes[1]->getArguments()[0])->toBe(CoversClass3::class);
|
||||
|
||||
expect($attributes[2]->getName())->toBe(CoversFunction::class);
|
||||
expect($attributes[2]->getArguments()[0])->toBe('testCoversFunction2');
|
||||
})->covers(CoversClass3::class, 'testCoversFunction2');
|
||||
11
tests/Features/Covers/TraitCoverage.php
Normal file
11
tests/Features/Covers/TraitCoverage.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversTrait as PHPUnitCoversTrait;
|
||||
use Tests\Fixtures\Covers\CoversTrait;
|
||||
|
||||
it('uses the correct PHPUnit attribute for trait', function () {
|
||||
$attributes = (new ReflectionClass($this))->getAttributes();
|
||||
|
||||
expect($attributes[1]->getName())->toBe(PHPUnitCoversTrait::class);
|
||||
expect($attributes[1]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversTrait');
|
||||
})->coversTrait(CoversTrait::class);
|
||||
24
tests/Features/Expect/toBeSlug.php
Normal file
24
tests/Features/Expect/toBeSlug.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('This is a Test String!')->toBeSlug()
|
||||
->and('Another Test String')->toBeSlug();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('')->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('failures with custom message', function () {
|
||||
expect('')->toBeSlug('oh no!');
|
||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||
|
||||
test('failures with default message', function () {
|
||||
expect('')->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class, 'Failed asserting that can be converted to a slug.');
|
||||
|
||||
test('not failures', function () {
|
||||
expect('This is a Test String!')->not->toBeSlug();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
@ -74,7 +74,8 @@ test('pass with dataset', function ($data) {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
expect($filename)->toStartWith('tests/.pest/snapshots/')
|
||||
->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
->and($this->snapshotable)->toMatchSnapshot();
|
||||
})->with(['my-datas-set-value']);
|
||||
|
||||
@ -83,7 +84,8 @@ describe('within describe', function () {
|
||||
TestSuite::getInstance()->snapshots->save($this->snapshotable);
|
||||
[$filename] = TestSuite::getInstance()->snapshots->get();
|
||||
|
||||
expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
expect($filename)->toStartWith('tests/.pest/snapshots/')
|
||||
->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap')
|
||||
->and($this->snapshotable)->toMatchSnapshot();
|
||||
});
|
||||
})->with(['my-datas-set-value']);
|
||||
|
||||
12
tests/Features/Fixture.php
Normal file
12
tests/Features/Fixture.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
it('may return a file path', function () {
|
||||
$file = fixture('phpunit-in-isolation.xml');
|
||||
|
||||
expect($file)->toBeString()
|
||||
->toBeFile();
|
||||
});
|
||||
|
||||
it('may throw an exception if the file does not exist', function () {
|
||||
fixture('file-that-does-not-exist.php');
|
||||
})->throws(InvalidArgumentException::class);
|
||||
11
tests/Features/References.php
Normal file
11
tests/Features/References.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Pest\Panic;
|
||||
|
||||
it('can reference a specific class', function () {
|
||||
expect(Panic::class)->toBeString();
|
||||
})->references(Panic::class);
|
||||
|
||||
it('can reference a specific class method', function () {
|
||||
expect(Panic::with(...))->toBeCallable();
|
||||
})->references([Panic::class, 'with']);
|
||||
11
tests/Features/See.php
Normal file
11
tests/Features/See.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Pest\Panic;
|
||||
|
||||
it('can reference a specific class', function () {
|
||||
expect(Panic::class)->toBeString();
|
||||
})->see(Panic::class);
|
||||
|
||||
it('can reference a specific class method', function () {
|
||||
expect(Panic::with(...))->toBeCallable();
|
||||
})->see([Panic::class, 'with']);
|
||||
Reference in New Issue
Block a user