assertNotEquals(Crypt::randomBytes($count), Crypt::randomBytes($count)); // Check the length. $this->assertEquals($count, strlen(Crypt::randomBytes($count))); } $this->assertEquals(30, static::$functionCalled, 'The namespaced function was called the expected number of times.'); } } namespace Drupal\Component\Utility; use Drupal\Tests\Component\Utility\CryptRandomFallbackTest; /** * Defines a function in same namespace as Drupal\Component\Utility\Crypt. * * Forces throwing an exception in this test environment because the function * in the namespace is used in preference to the global function. * * @param int $count * Matches the global function definition. * * @throws \Exception */ function random_bytes($count) { CryptRandomFallbackTest::functionCalled(); throw new \Exception($count); }