You are here

public function MongoDbSessionHandlerTest::testRead in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php \Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler\MongoDbSessionHandlerTest::testRead()

File

vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php, line 77

Class

MongoDbSessionHandlerTest
@author Markus Bachmann <markus.bachmann@bachi.biz>

Namespace

Symfony\Component\HttpFoundation\Tests\Session\Storage\Handler

Code

public function testRead() {
  $collection = $this
    ->createMongoCollectionMock();
  $this->mongo
    ->expects($this
    ->once())
    ->method('selectCollection')
    ->with($this->options['database'], $this->options['collection'])
    ->will($this
    ->returnValue($collection));
  $that = $this;

  // defining the timeout before the actual method call
  // allows to test for "greater than" values in the $criteria
  $testTimeout = time() + 1;
  $collection
    ->expects($this
    ->once())
    ->method('findOne')
    ->will($this
    ->returnCallback(function ($criteria) use ($that, $testTimeout) {
    $that
      ->assertArrayHasKey($that->options['id_field'], $criteria);
    $that
      ->assertEquals($criteria[$that->options['id_field']], 'foo');
    $that
      ->assertArrayHasKey($that->options['expiry_field'], $criteria);
    $that
      ->assertArrayHasKey('$gte', $criteria[$that->options['expiry_field']]);
    $that
      ->assertInstanceOf('MongoDate', $criteria[$that->options['expiry_field']]['$gte']);
    $that
      ->assertGreaterThanOrEqual($criteria[$that->options['expiry_field']]['$gte']->sec, $testTimeout);
    return array(
      $that->options['id_field'] => 'foo',
      $that->options['data_field'] => new \MongoBinData('bar', \MongoBinData::BYTE_ARRAY),
      $that->options['id_field'] => new \MongoDate(),
    );
  }));
  $this
    ->assertEquals('bar', $this->storage
    ->read('foo'));
}