public function MongoDbSessionHandlerTest::testWrite

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/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 testWrite() {
  $collection = $this
    ->getMockBuilder('MongoCollection')
    ->disableOriginalConstructor()
    ->getMock();
  $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'];
  }));
  $this
    ->assertTrue($this->storage
    ->write('foo', 'bar'));
  $this
    ->assertEquals('bar', $data[$this->options['data_field']]->bin);
  $that
    ->assertInstanceOf('MongoDate', $data[$this->options['time_field']]);
}