setIfOwner example

/** * Tests the setIfOwner() method when no key exists. * * @covers ::setIfOwner */
  public function testSetIfOwnerWhenNotExists() {
    $this->keyValue->expects($this->once())
      ->method('setWithExpireIfNotExists')
      ->willReturn(TRUE);

    $this->assertTrue($this->tempStore->setIfOwner('test', 'test_data'));
  }

  /** * Tests the setIfOwner() method when a key already exists but no object. * * @covers ::setIfOwner */
  public function testSetIfOwnerNoObject() {
    $this->keyValue->expects($this->once())
      ->method('setWithExpireIfNotExists')
      ->willReturn(FALSE);

    
// This time it should succeed.     $this->assertEquals($objects[1]$stores[0]->get($key));

    // This user can update the object.     $stores[0]->set($key$objects[2]);
    $this->assertEquals($objects[2]$stores[0]->get($key));
    // The object is the same when another user loads it.     $this->assertEquals($objects[2]$stores[1]->get($key));

    // This user should be allowed to get, update, delete.     $this->assertInstanceOf(\stdClass::class$stores[0]->getIfOwner($key));
    $this->assertTrue($stores[0]->setIfOwner($key$objects[1]));
    $this->assertTrue($stores[0]->deleteIfOwner($key));

    // Another user can update the object and become the owner.     $stores[1]->set($key$objects[3]);
    $this->assertEquals($objects[3]$stores[0]->get($key));
    $this->assertEquals($objects[3]$stores[1]->get($key));
    $metadata = $stores[1]->getMetadata($key);
    $this->assertEquals($users[1]$metadata->getOwnerId());

    // The first user should be informed that the second now owns the data.     $metadata = $stores[0]->getMetadata($key);
    
Home | Imprint | This part of the site doesn't use cookies.