Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TestMethodBuilder.php

class TestMethodBuilder

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

@internal This class is not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Event\Code\TestMethodBuilder

Expanded class hierarchy of TestMethodBuilder

1 file declares its use of TestMethodBuilder
AbstractPhpProcess.php in vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php

File

vendor/phpunit/phpunit/src/Event/Value/Test/TestMethodBuilder.php, line 32

Namespace

PHPUnit\Event\Code
View source
final class TestMethodBuilder {
    
    /**
     * @throws MoreThanOneDataSetFromDataProviderException
     */
    public static function fromTestCase(TestCase $testCase) : TestMethod {
        $methodName = $testCase->name();
        assert(!empty($methodName));
        $location = Reflection::sourceLocationFor($testCase::class, $methodName);
        return new TestMethod($testCase::class, $methodName, $location['file'], $location['line'], TestDoxBuilder::fromTestCase($testCase), MetadataRegistry::parser()->forClassAndMethod($testCase::class, $methodName), self::dataFor($testCase));
    }
    
    /**
     * @throws NoTestCaseObjectOnCallStackException
     */
    public static function fromCallStack() : TestMethod {
        foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
            if (isset($frame['object']) && $frame['object'] instanceof TestCase) {
                return $frame['object']->valueObjectForEvents();
            }
        }
        throw new NoTestCaseObjectOnCallStackException();
    }
    
    /**
     * @throws MoreThanOneDataSetFromDataProviderException
     */
    private static function dataFor(TestCase $testCase) : TestDataCollection {
        $testData = [];
        if ($testCase->usesDataProvider()) {
            $dataSetName = $testCase->dataName();
            if (is_numeric($dataSetName)) {
                $dataSetName = (int) $dataSetName;
            }
            $testData[] = DataFromDataProvider::from($dataSetName, Exporter::export($testCase->providedData(), EventFacade::emitter()->exportsObjects()), $testCase->dataSetAsStringWithData());
        }
        if ($testCase->hasDependencyInput()) {
            $testData[] = DataFromTestDependency::from(Exporter::export($testCase->dependencyInput(), EventFacade::emitter()->exportsObjects()));
        }
        return TestDataCollection::fromArray($testData);
    }

}

Members

Title Sort descending Modifiers Object type Summary
TestMethodBuilder::dataFor private static function
TestMethodBuilder::fromCallStack public static function
TestMethodBuilder::fromTestCase public static function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal