MetadataBag example

        $collector->collectSessionUsage();

        $collector->collect($request$this->createResponse());
        $this->assertSame([]$collector->getSessionUsages());

        $collector->reset();

        $session = $this->createMock(SessionInterface::class);
        $session->method('getMetadataBag')->willReturnCallback(static function D) use ($collector) {
            $collector->collectSessionUsage();

            return new MetadataBag();
        });
        $session->getMetadataBag();

        $collector->collect($request$this->createResponse());
        $collector->lateCollect();

        $usages = $collector->getSessionUsages();

        $this->assertCount(1, $usages);
        $this->assertSame(__FILE__, $usages[0]['file']);
        $this->assertSame(__LINE__ - 9, $line = $usages[0]['line']);

        

class MetadataBagTest extends TestCase
{
    protected MetadataBag $bag;
    protected array $array = [];

    protected function setUp(): void
    {
        parent::setUp();
        $this->bag = new MetadataBag();
        $this->array = [MetadataBag::CREATED => 1234567, MetadataBag::UPDATED => 12345678, MetadataBag::LIFETIME => 0];
        $this->bag->initialize($this->array);
    }

    public function testInitialize()
    {
        $sessionMetadata = [];

        $bag1 = new MetadataBag();
        $bag1->initialize($sessionMetadata);
        $this->assertGreaterThanOrEqual(time()$bag1->getCreated());
        
return $this->started;
    }

    /** * @return void */
    public function setMetadataBag(MetadataBag $bag = null)
    {
        if (1 > \func_num_args()) {
            trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
        }
        $this->metadataBag = $bag ?? new MetadataBag();
    }

    /** * Gets the MetadataBag. */
    public function getMetadataBag(): MetadataBag
    {
        return $this->metadataBag;
    }

    /** * Generates a session ID. * * This doesn't need to be particularly cryptographically secure since this is just * a mock. */
return $this->bags[$name];
    }

    /** * @return void */
    public function setMetadataBag(MetadataBag $metaBag = null)
    {
        if (1 > \func_num_args()) {
            trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
        }
        $this->metadataBag = $metaBag ?? new MetadataBag();
    }

    /** * Gets the MetadataBag. */
    public function getMetadataBag(): MetadataBag
    {
        return $this->metadataBag;
    }

    public function isStarted(): bool
    {
return $this->started;
    }

    /** * @return void */
    public function setMetadataBag(MetadataBag $bag = null)
    {
        if (1 > \func_num_args()) {
            trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
        }
        $this->metadataBag = $bag ?? new MetadataBag();
    }

    /** * Gets the MetadataBag. */
    public function getMetadataBag(): MetadataBag
    {
        return $this->metadataBag;
    }

    /** * Generates a session ID. * * This doesn't need to be particularly cryptographically secure since this is just * a mock. */
return $this->bags[$name];
    }

    /** * @return void */
    public function setMetadataBag(MetadataBag $metaBag = null)
    {
        if (1 > \func_num_args()) {
            trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
        }
        $this->metadataBag = $metaBag ?? new MetadataBag();
    }

    /** * Gets the MetadataBag. */
    public function getMetadataBag(): MetadataBag
    {
        return $this->metadataBag;
    }

    public function isStarted(): bool
    {
/** * @coversDefaultClass \Drupal\Core\Session\MetadataBag * @group Session */
class MetadataBagTest extends UnitTestCase {

  /** * @covers ::stampNew */
  public function testStampNew() {
    $metadata = new MetadataBag(new Settings([]));
    $metadata->setCsrfTokenSeed('a_cryptographically_secure_long_random_string_should_used_here');
    $metadata->stampNew();
    $this->assertNotEquals('a_cryptographically_secure_long_random_string_should_used_here', $metadata->getCsrfTokenSeed());
  }

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