mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
Fixes using test cases on uses with tests
This commit is contained in:
@ -65,7 +65,11 @@ trait Testable
|
|||||||
{
|
{
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
|
||||||
$this->__test = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($name)->getClosure($this);
|
$test = TestSuite::getInstance()->tests->get(self::$__filename);
|
||||||
|
|
||||||
|
if ($test->hasMethod($name)) {
|
||||||
|
$this->__test = $test->getMethod($name)->getClosure($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,6 +167,8 @@ trait Testable
|
|||||||
*/
|
*/
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
|
self::$__description = $this->name();
|
||||||
|
|
||||||
TestSuite::getInstance()->test = $this;
|
TestSuite::getInstance()->test = $this;
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@ -212,6 +218,7 @@ trait Testable
|
|||||||
private function __resolveTestArguments(array $arguments): array
|
private function __resolveTestArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
|
||||||
|
|
||||||
if ($this->dataName()) {
|
if ($this->dataName()) {
|
||||||
self::$__description = $method->description . ' with ' . $this->dataName();
|
self::$__description = $method->description . ' with ' . $this->dataName();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -240,6 +240,24 @@ final class TestCaseFactory
|
|||||||
$this->methods[$method->description] = $method;
|
$this->methods[$method->description] = $method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a test case has a method.
|
||||||
|
*/
|
||||||
|
public function hasMethod(string $methodName): bool
|
||||||
|
{
|
||||||
|
foreach ($this->methods as $method) {
|
||||||
|
if ($method->description === null) {
|
||||||
|
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Str::evaluable($method->description) === $methodName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a Method by the given name.
|
* Gets a Method by the given name.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -18,7 +18,7 @@ final class Printer implements HandlesArguments
|
|||||||
*/
|
*/
|
||||||
public function handleArguments(array $arguments): array
|
public function handleArguments(array $arguments): array
|
||||||
{
|
{
|
||||||
if (! array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
if (!array_key_exists('COLLISION_PRINTER', $_SERVER)) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,13 +2,12 @@
|
|||||||
|
|
||||||
use Pest\Plugins\Coverage as CoveragePlugin;
|
use Pest\Plugins\Coverage as CoveragePlugin;
|
||||||
use Pest\Support\Coverage;
|
use Pest\Support\Coverage;
|
||||||
use Pest\TestSuite;
|
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
it('has plugin')->assertTrue(class_exists(CoveragePlugin::class));
|
it('has plugin')->assertTrue(class_exists(CoveragePlugin::class));
|
||||||
|
|
||||||
it('adds coverage if --coverage exist', function () {
|
it('adds coverage if --coverage exist', function () {
|
||||||
$plugin = new CoveragePlugin(new ConsoleOutput());
|
$plugin = new CoveragePlugin(new ConsoleOutput());
|
||||||
|
|
||||||
expect($plugin->coverage)->toBeFalse();
|
expect($plugin->coverage)->toBeFalse();
|
||||||
$arguments = $plugin->handleArguments([]);
|
$arguments = $plugin->handleArguments([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user