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

Breadcrumb

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

function PhptTestCase::assertPhptExpectation

Throws

Exception

ExpectationFailedException

1 call to PhptTestCase::assertPhptExpectation()
PhptTestCase::run in vendor/phpunit/phpunit/src/Runner/PhptTestCase.php
Runs a test and collects its result in a TestResult instance.

File

vendor/phpunit/phpunit/src/Runner/PhptTestCase.php, line 374

Class

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

Namespace

PHPUnit\Runner

Code

private function assertPhptExpectation(array $sections, string $output) : void {
    $assertions = [
        'EXPECT' => 'assertEquals',
        'EXPECTF' => 'assertStringMatchesFormat',
        'EXPECTREGEX' => 'assertMatchesRegularExpression',
    ];
    $actual = preg_replace('/\\r\\n/', "\n", trim($output));
    foreach ($assertions as $sectionName => $sectionAssertion) {
        if (isset($sections[$sectionName])) {
            $sectionContent = preg_replace('/\\r\\n/', "\n", trim($sections[$sectionName]));
            $expected = $sectionName === 'EXPECTREGEX' ? "/{$sectionContent}/" : $sectionContent;
            Assert::$sectionAssertion($expected, $actual);
            return;
        }
    }
    throw new InvalidPhptFileException();
}
RSS feed
Powered by Drupal