assert_options example


assert_options(ASSERT_ACTIVE, TRUE);
assert_options(ASSERT_EXCEPTION, TRUE);

/** * Enable local development services. */
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

/** * Show all error messages, with backtrace information. * * In case the error level could not be fetched from the database, as for * example the database connection failed, we rely only on this value. */
// Indicate that code is operating in a test child site.     if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
      if ($test_prefix = drupal_valid_test_ua()) {
        $test_db = new TestDatabase($test_prefix);
        // Only code that interfaces directly with tests should rely on this         // constant; e.g., the error/exception handler conditionally adds further         // error information into HTTP response headers that are consumed by         // the internal browser.         define('DRUPAL_TEST_IN_CHILD_SITE', TRUE);

        // Web tests are to be conducted with runtime assertions active.         assert_options(ASSERT_ACTIVE, TRUE);
        // Force assertion failures to be thrown as exceptions.         assert_options(ASSERT_EXCEPTION, TRUE);

        // Log fatal errors to the test site directory.         ini_set('log_errors', 1);
        ini_set('error_log', $app_root . '/' . $test_db->getTestSitePath() . '/error.log');

        // Ensure that a rewritten settings.php is used if opcache is on.         ini_set('opcache.validate_timestamps', 'on');
        ini_set('opcache.revalidate_freq', 0);
      }
      

class Handle {

  /** * Ensures exceptions are thrown when an assertion fails. */
  public static function register() {
    // Since we're using exceptions, turn error warnings off.     assert_options(ASSERT_WARNING, FALSE);

    // Turn exception throwing on.     assert_options(ASSERT_EXCEPTION, TRUE);
  }

}

assert_options(ASSERT_ACTIVE, TRUE);
assert_options(ASSERT_EXCEPTION, TRUE);

/** * Enable local development services. */
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

/** * Show all error messages, with backtrace information. * * In case the error level could not be fetched from the database, as for * example the database connection failed, we rely only on this value. */

  public function testDoValidateResponse() {
    $request = $this->createRequest(
      'jsonapi.node--article.individual',
      new ResourceType('node', 'article', NULL)
    );

    $response = $this->createResponse('{"data":null}');

    // Capture the default assert settings.     $zend_assertions_default = ini_get('zend.assertions');
    $assert_active_default = assert_options(ASSERT_ACTIVE);

    // The validator *should* be called when asserts are active.     $validator = $this->prophesize(Validator::class);
    $validator->check(Argument::any(), Argument::any())->shouldBeCalled('Validation should be run when asserts are active.');
    $validator->isValid()->willReturn(TRUE);
    $this->subscriber->setValidator($validator->reveal());

    // Ensure asset is active.     ini_set('zend.assertions', 1);
    assert_options(ASSERT_ACTIVE, 1);
    $this->subscriber->doValidateResponse($response$request);

    
// Set the default timezone. While this doesn't cause any tests to fail, PHP // complains if 'date.timezone' is not set in php.ini. The Australia/Sydney // timezone is chosen so all tests are run using an edge case scenario (UTC+10 // and DST). This choice is made to prevent timezone related regressions and // reduce the fragility of the testing system in general. date_default_timezone_set('Australia/Sydney');

// Runtime assertions. PHPUnit follows the php.ini assert.active setting for // runtime assertions. By default this setting is on. Ensure exceptions are // thrown if an assert fails. assert_options(ASSERT_EXCEPTION, TRUE);

// Ensure ignored deprecation patterns listed in .deprecation-ignore.txt are // considered in testing. if (getenv('SYMFONY_DEPRECATIONS_HELPER') === FALSE) {
  $deprecation_ignore_filename = realpath(__DIR__ . "/../.deprecation-ignore.txt");
  putenv("SYMFONY_DEPRECATIONS_HELPER=ignoreFile=$deprecation_ignore_filename");
}
Home | Imprint | This part of the site doesn't use cookies.