mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
added feedback from @nunomaduro
This commit is contained in:
@ -53,11 +53,6 @@ trait TestCase
|
||||
$this->setGroups($groups);
|
||||
}
|
||||
|
||||
public function addDependencies(array $tests): void
|
||||
{
|
||||
$this->setDependencies($tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test case name. Note that, in Pest
|
||||
* we ignore withDataset argument as the description
|
||||
@ -144,7 +139,7 @@ trait TestCase
|
||||
{
|
||||
return ExceptionTrace::ensure(function () use ($closure, $arguments) {
|
||||
return call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
|
||||
})->getValue();
|
||||
});
|
||||
}
|
||||
|
||||
public function getPrintableTestCaseName(): string
|
||||
|
||||
@ -84,20 +84,15 @@ final class TestCall
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dependsOn(string ...$tests): TestCall
|
||||
public function depends(string ...$tests): TestCall
|
||||
{
|
||||
$this->testCaseFactory
|
||||
->factoryProxies
|
||||
->add(Backtrace::file(), Backtrace::line(), 'addDependencies', [$tests]);
|
||||
->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function depends(string ...$tests): TestCall
|
||||
{
|
||||
return $this->dependsOn(...$tests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the test suite only this test case.
|
||||
*/
|
||||
|
||||
@ -18,10 +18,10 @@ final class ExceptionTrace
|
||||
* Ensures the given closure reports
|
||||
* the good execution context.
|
||||
*/
|
||||
public static function ensure(Closure $closure): Mixed
|
||||
public static function ensure(Closure $closure)
|
||||
{
|
||||
try {
|
||||
return new Mixed($closure());
|
||||
return $closure();
|
||||
} catch (Throwable $throwable) {
|
||||
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
||||
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Mixed
|
||||
{
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
@ -45,11 +45,10 @@
|
||||
PASS Tests\Features\Depends
|
||||
✓ first
|
||||
✓ second
|
||||
✓ dependsOn
|
||||
✓ dependsOn with ...params
|
||||
✓ dependsOn with defined arguments
|
||||
✓ dependsOn run test only once
|
||||
✓ depends alias for dependsOn
|
||||
✓ depends
|
||||
✓ depends with ...params
|
||||
✓ depends with defined arguments
|
||||
✓ depends run test only once
|
||||
|
||||
PASS Tests\Features\Exceptions
|
||||
✓ it gives access the the underlying expectException
|
||||
@ -153,5 +152,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
s visual snapshot of test suite on success
|
||||
|
||||
Tests: 6 skipped, 86 passed
|
||||
Time: 2.61s
|
||||
Tests: 6 skipped, 85 passed
|
||||
Time: 2.60s
|
||||
|
||||
@ -16,32 +16,25 @@ test('second', function () use (&$runCounter) {
|
||||
return 'second';
|
||||
});
|
||||
|
||||
test('dependsOn', function () {
|
||||
test('depends', function () {
|
||||
assertEquals(
|
||||
['first', 'second'],
|
||||
func_get_args()
|
||||
);
|
||||
})->dependsOn('first', 'second');
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('dependsOn with ...params', function (string ...$params) {
|
||||
assertEquals(
|
||||
['first', 'second'],
|
||||
$params
|
||||
);
|
||||
})->dependsOn('first', 'second');
|
||||
|
||||
test('dependsOn with defined arguments', function (string $first, string $second) {
|
||||
assertEquals('first', $first);
|
||||
assertEquals('second', $second);
|
||||
})->dependsOn('first', 'second');
|
||||
|
||||
test('dependsOn run test only once', function () use (&$runCounter) {
|
||||
assertEquals(2, $runCounter);
|
||||
})->dependsOn('first', 'second');
|
||||
|
||||
test('depends alias for dependsOn', function (string ...$params) {
|
||||
test('depends with ...params', function (string ...$params) {
|
||||
assertEquals(
|
||||
['first', 'second'],
|
||||
$params
|
||||
);
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('depends with defined arguments', function (string $first, string $second) {
|
||||
assertEquals('first', $first);
|
||||
assertEquals('second', $second);
|
||||
})->depends('first', 'second');
|
||||
|
||||
test('depends run test only once', function () use (&$runCounter) {
|
||||
assertEquals(2, $runCounter);
|
||||
})->depends('first', 'second');
|
||||
|
||||
Reference in New Issue
Block a user