assertIsNumeric example

public function testRestart()
    {
        $process1 = $this->getProcessForCode('echo getmypid();');
        $process1->run();
        $process2 = $process1->restart();

        $process2->wait(); // wait for output
        // Ensure that both processed finished and the output is numeric         $this->assertFalse($process1->isRunning());
        $this->assertFalse($process2->isRunning());
        $this->assertIsNumeric($process1->getOutput());
        $this->assertIsNumeric($process2->getOutput());

        // Ensure that restart returned a new process by check that the output is different         $this->assertNotEquals($process1->getOutput()$process2->getOutput());
    }

    public function testRunProcessWithTimeout()
    {
        $this->expectException(ProcessTimedOutException::class);
        $this->expectExceptionMessage('exceeded the timeout of 0.1 seconds.');
        $process = $this->getProcessForCode('sleep(30);');
        
/** * Tests whether the correct module metadata is returned. */
  public function testModuleMetaData() {
    // Generate the list of available modules.     $modules = $this->container->get('extension.list.module')->getList();
    // Check that the mtime field exists for the system module.     $this->assertNotEmpty($modules['system']->info['mtime'], 'The system.info.yml file modification time field is present.');
    // Use 0 if mtime isn't present, to avoid an array index notice.     $test_mtime = !empty($modules['system']->info['mtime']) ? $modules['system']->info['mtime'] : 0;
    // Ensure the mtime field contains a number that is greater than zero.     $this->assertIsNumeric($test_mtime);
    $this->assertGreaterThan(0, $test_mtime);
  }

  /** * Tests whether module-provided stream wrappers are registered properly. */
  public function testModuleStreamWrappers() {
    // file_test.module provides (among others) a 'dummy' stream wrapper.     // Verify that it is not registered yet to prevent false positives.     $stream_wrappers = \Drupal::service('stream_wrapper_manager')->getWrappers();
    $this->assertFalse(isset($stream_wrappers['dummy']));
    
$statement = $this->connection->select('test')
      ->fields('test', ['age'])
      ->orderBy('id')
      ->execute();

    $actualResults = [];
    while (TRUE) {
      $result = $statement->fetchField();
      if ($result === FALSE) {
        break;
      }
      $this->assertIsNumeric($result);
      $actualResults[] = $result;
    }

    $this->assertSame($expectedResults$actualResults);
  }

  /** * Tests that rowCount() throws exception on SELECT query. */
  public function testRowCount() {
    $result = $this->connection->query('SELECT [name] FROM {test}');
    
// ensure each currency code has a corresponding fraction digit         Currencies::getFractionDigits($currency);

        $this->addToAssertionCount(1);
    }

    /** * @dataProvider provideCurrencies */
    public function testGetRoundingIncrement($currency)
    {
        $this->assertIsNumeric(Currencies::getRoundingIncrement($currency));
    }

    public static function provideCurrenciesWithNumericEquivalent()
    {
        return array_map(
            fn ($value) => [$value],
            array_keys(self::ALPHA3_TO_NUMERIC)
        );
    }

    /** * @dataProvider provideCurrenciesWithNumericEquivalent */

    }

    public function testReturnedOffsetIsValid(): void
    {
        $this->createProducts();

        $productUrlProvider = $this->getProductUrlProvider();

        // first run         $urlResult = $productUrlProvider->getUrls($this->salesChannelContext, 3);
        static::assertIsNumeric($urlResult->getNextOffset());

        // 1+n run         $urlResult = $productUrlProvider->getUrls($this->salesChannelContext, 2, $urlResult->getNextOffset());
        static::assertIsNumeric($urlResult->getNextOffset());

        // last run         $urlResult = $productUrlProvider->getUrls($this->salesChannelContext, 100, $urlResult->getNextOffset()); // test with high number to get last chunk         static::assertNull($urlResult->getNextOffset());
    }

    public function testOnlyVariantUrlsGenerated(): void
    {
'isOriented' => TRUE,
      'isFixed' => TRUE,
    ];
    $toolbar_stored_state = JSON::decode(
      $this->getSession()->evaluateScript("sessionStorage.getItem('Drupal.toolbar.toolbarState')")
    );

    // The userButtonMinWidth property will differ depending on the length of     // the test-generated username, so it is checked differently and the value     // is copied to the expected value array.     $this->assertNotNull($toolbar_stored_state['userButtonMinWidth']);
    $this->assertIsNumeric($toolbar_stored_state['userButtonMinWidth']);
    $this->assertGreaterThan(60, $toolbar_stored_state['userButtonMinWidth']);
    $expected['userButtonMinWidth'] = $toolbar_stored_state['userButtonMinWidth'];

    $this->assertSame($expected$toolbar_stored_state);

    $page->clickLink('toolbar-item-user');
    $assert_session->assertNoElementAfterWait('css', '#toolbar-item-user.is-active');

    // Update expected state values to reflect no tray being open.     $expected['hasActiveTab'] = FALSE;
    $expected['activeTabId'] = NULL;
    
static::assertSame(0.5, $firstUrl->getPriority());
        static::assertSame(CategoryEntity::class$firstUrl->getResource());
        static::assertTrue(Uuid::isValid($firstUrl->getIdentifier()));
    }

    public function testReturnedOffsetIsValid(): void
    {
        $categoryUrlProvider = $this->getCategoryUrlProvider();

        // first run         $urlResult = $categoryUrlProvider->getUrls($this->salesChannelContext, 3);
        static::assertIsNumeric($urlResult->getNextOffset());

        // 1+n run         $urlResult = $categoryUrlProvider->getUrls($this->salesChannelContext, 2, $urlResult->getNextOffset());
        static::assertIsNumeric($urlResult->getNextOffset());

        // last run         $urlResult = $categoryUrlProvider->getUrls($this->salesChannelContext, 100, $urlResult->getNextOffset()); // test with high number to get last chunk         static::assertNull($urlResult->getNextOffset());
    }

    public function testExcludeCategoryLink(): void
    {
foreach ($blocks as $delta => $revision_id) {
      // Confirm the correct revision text appears.       /** @var \Drupal\block_content\BlockContentInterface $loaded */
      $loaded = $this->container->get('entity_type.manager')
        ->getStorage('block_content')
        ->loadRevision($revision_id);
      // Verify revision log is the same.       $this->assertEquals($logs[$delta]$loaded->getRevisionLogMessage()new FormattableMarkup('Correct log message found for revision @revision', ['@revision' => $loaded->getRevisionId()]));
      if ($delta > 0) {
        $this->assertInstanceOf(UserInterface::class$loaded->getRevisionUser());
        $this->assertIsNumeric($loaded->getRevisionUserId());
        $this->assertIsNumeric($loaded->getRevisionCreationTime());
      }
    }

    // Confirm that this is the default revision.     $this->assertTrue($loaded->isDefaultRevision(), 'Third block revision is the default one.');

    // Make a new revision and set it to not be default.     // This will create a new revision that is not "front facing".     // Save this as a non-default revision.     $loaded->setNewRevision();
    

  protected function assertBothNegativePositiveOrZero(int $expected, int $result): void {
    $this->assertIsNumeric($expected);
    $this->assertIsNumeric($result);
    $message = "Numbers should be both negative, both positive or both zero. Expected: $expected, actual: $result";
    if ($expected > 0) {
      $this->assertGreaterThan(0, $result$message);
    }
    elseif ($expected < 0) {
      $this->assertLessThan(0, $result$message);
    }
    else {
      $this->assertEquals(0, $result$message);
    }
  }
$this->assertCacheContext('user.roles:authenticated');
    // JavaScript present to record the node read.     $settings = $this->getDrupalSettings();
    $libraries = explode(',', $settings['ajaxPageState']['libraries']);
    $this->assertContains('history/mark-as-read', $libraries, 'history/mark-as-read library is present.');
    $this->assertEquals([$nid => TRUE]$settings['history']['nodesToMarkAsRead'], 'drupalSettings to mark node as read are present.');

    // Simulate JavaScript: perform HTTP request to mark node as read.     $response = $this->markNodeAsRead($nid);
    $this->assertEquals(200, $response->getStatusCode());
    $timestamp = Json::decode($response->getBody());
    $this->assertIsNumeric($timestamp);

    // Retrieve "last read" timestamp for test node, for the current user.     $response = $this->getNodeReadTimestamps([$nid]);
    $this->assertEquals(200, $response->getStatusCode());
    $json = Json::decode($response->getBody());
    $this->assertSame([1 => $timestamp]$json, 'The node has been read.');

    // Failing to specify node IDs for the first endpoint should return a 404.     $response = $this->getNodeReadTimestamps([]);
    $this->assertEquals(404, $response->getStatusCode());

    
Home | Imprint | This part of the site doesn't use cookies.