randomObject example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Define two data collections,     $this->collections = [0 => 'zero', 1 => 'one'];

    // Create several objects for testing.     for ($i = 0; $i <= 5; $i++) {
      $this->objects[$i] = $this->randomObject();
    }
  }

  /** * Tests CRUD operations. */
  public function testCRUD() {
    $stores = $this->createStorage();
    // Verify that each store returns its own collection name.     $this->assertSame($this->collections[0]$stores[0]->getCollectionName());
    $this->assertSame($this->collections[1]$stores[1]->getCollectionName());

    
/** * Tests garbage collection. */
  public function testGarbageCollection() {
    $collection = $this->randomMachineName();
    $connection = Database::getConnection();
    $store = new DatabaseStorageExpirable($collectionnew PhpSerialize()$connection);

    // Insert some items and confirm that they're set.     for ($i = 0; $i <= 3; $i++) {
      $store->setWithExpire('key_' . $i$this->randomObject()rand(500, 100000));
    }
    $this->assertCount(4, $store->getAll(), 'Four items were written to the storage.');

    // Manually expire the data.     for ($i = 0; $i <= 3; $i++) {
      $connection->merge('key_value_expire')
        ->keys([
          'name' => 'key_' . $i,
          'collection' => $collection,
        ])
        ->fields([
          

class TempStoreDatabaseTest extends KernelTestBase {

  /** * Tests the SharedTempStore API. */
  public function testSharedTempStore() {
    // Create testing objects.     $objects = [];
    for ($i = 0; $i <= 3; $i++) {
      $objects[$i] = $this->randomObject();
    }

    // Create a key/value collection.     $database = Database::getConnection();
    // Mock the current user service so that isAnonymous returns FALSE.     $current_user = $this->prophesize(AccountProxyInterface::class);
    $factory = new SharedTempStoreFactory(
      new KeyValueExpirableFactory(\Drupal::getContainer()),
      new DatabaseLockBackend($database),
      $this->container->get('request_stack'),
      $current_user->reveal()
    );
Home | Imprint | This part of the site doesn't use cookies.