You are here

public function MongoDbSessionHandlerTest::testWrite in Zircon Profile 8

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

File

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

Class

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

Namespace

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

Code

public function testWrite() {
  $collection = $this
    ->createMongoCollectionMock();
  $this->mongo
    ->expects($this
    ->once())
    ->method('selectCollection')
    ->with($this->options['database'], $this->options['collection'])
    ->will($this
    ->returnValue($collection));
  $that = $this;
  $data = array();
  $collection
    ->expects($this
    ->once())
    ->method('update')
    ->will($this
    ->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) {
    $that
      ->assertEquals(array(
      $that->options['id_field'] => 'foo',
    ), $criteria);
    $that
      ->assertEquals(array(
      'upsert' => true,
      'multiple' => false,
    ), $options);
    $data = $updateData['$set'];
  }));
  $expectedExpiry = time() + (int) ini_get('session.gc_maxlifetime');
  $this
    ->assertTrue($this->storage
    ->write('foo', 'bar'));
  $this
    ->assertEquals('bar', $data[$this->options['data_field']]->bin);
  $that
    ->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
  $this
    ->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]);
  $this
    ->assertGreaterThanOrEqual($expectedExpiry, $data[$this->options['expiry_field']]->sec);
}