X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fhttp-foundation%2FTests%2FSession%2FStorage%2FHandler%2FMongoDbSessionHandlerTest.php;h=186fc0a2d056463388616333e4f4e6a8ea8dc96f;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=f23161c10b0762ed28654f13609e1c9acbf2797b;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index f23161c10..186fc0a2d 100644 --- a/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/vendor/symfony/http-foundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandl /** * @author Markus Bachmann * @group time-sensitive + * @group legacy */ class MongoDbSessionHandlerTest extends TestCase { @@ -31,7 +32,11 @@ class MongoDbSessionHandlerTest extends TestCase { parent::setUp(); - if (!extension_loaded('mongo') && !extension_loaded('mongodb')) { + if (\extension_loaded('mongodb')) { + if (!class_exists('MongoDB\Client')) { + $this->markTestSkipped('The mongodb/mongodb package is required.'); + } + } elseif (!\extension_loaded('mongo')) { $this->markTestSkipped('The Mongo or MongoDB extension is required.'); } @@ -92,39 +97,37 @@ class MongoDbSessionHandlerTest extends TestCase ->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'); + ->will($this->returnCallback(function ($criteria) use ($testTimeout) { + $this->assertArrayHasKey($this->options['id_field'], $criteria); + $this->assertEquals($criteria[$this->options['id_field']], 'foo'); - $that->assertArrayHasKey($that->options['expiry_field'], $criteria); - $that->assertArrayHasKey('$gte', $criteria[$that->options['expiry_field']]); + $this->assertArrayHasKey($this->options['expiry_field'], $criteria); + $this->assertArrayHasKey('$gte', $criteria[$this->options['expiry_field']]); if (phpversion('mongodb')) { - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$that->options['expiry_field']]['$gte']); - $that->assertGreaterThanOrEqual(round(((int) $criteria[$that->options['expiry_field']]['$gte']) / 1000), $testTimeout); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$gte']); + $this->assertGreaterThanOrEqual(round((string) $criteria[$this->options['expiry_field']]['$gte'] / 1000), $testTimeout); } else { - $that->assertInstanceOf('MongoDate', $criteria[$that->options['expiry_field']]['$gte']); - $that->assertGreaterThanOrEqual($criteria[$that->options['expiry_field']]['$gte']->sec, $testTimeout); + $this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$gte']); + $this->assertGreaterThanOrEqual($criteria[$this->options['expiry_field']]['$gte']->sec, $testTimeout); } $fields = array( - $that->options['id_field'] => 'foo', + $this->options['id_field'] => 'foo', ); if (phpversion('mongodb')) { - $fields[$that->options['data_field']] = new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY); - $fields[$that->options['id_field']] = new \MongoDB\BSON\UTCDateTime(time() * 1000); + $fields[$this->options['data_field']] = new \MongoDB\BSON\Binary('bar', \MongoDB\BSON\Binary::TYPE_OLD_BINARY); + $fields[$this->options['id_field']] = new \MongoDB\BSON\UTCDateTime(time() * 1000); } else { - $fields[$that->options['data_field']] = new \MongoBinData('bar', \MongoBinData::BYTE_ARRAY); - $fields[$that->options['id_field']] = new \MongoDate(); + $fields[$this->options['data_field']] = new \MongoBinData('bar', \MongoBinData::BYTE_ARRAY); + $fields[$this->options['id_field']] = new \MongoDate(); } return $fields; @@ -142,20 +145,19 @@ class MongoDbSessionHandlerTest extends TestCase ->with($this->options['database'], $this->options['collection']) ->will($this->returnValue($collection)); - $that = $this; $data = array(); $methodName = phpversion('mongodb') ? 'updateOne' : 'update'; $collection->expects($this->once()) ->method($methodName) - ->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) { - $that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria); + ->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) { + $this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria); if (phpversion('mongodb')) { - $that->assertEquals(array('upsert' => true), $options); + $this->assertEquals(array('upsert' => true), $options); } else { - $that->assertEquals(array('upsert' => true, 'multiple' => false), $options); + $this->assertEquals(array('upsert' => true, 'multiple' => false), $options); } $data = $updateData['$set']; @@ -165,15 +167,15 @@ class MongoDbSessionHandlerTest extends TestCase $this->assertTrue($this->storage->write('foo', 'bar')); if (phpversion('mongodb')) { - $that->assertEquals('bar', $data[$that->options['data_field']]->getData()); - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['time_field']]); - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['expiry_field']]); - $that->assertGreaterThanOrEqual($expectedExpiry, round(((int) $data[$that->options['expiry_field']]) / 1000)); + $this->assertEquals('bar', $data[$this->options['data_field']]->getData()); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]); + $this->assertGreaterThanOrEqual($expectedExpiry, round((string) $data[$this->options['expiry_field']] / 1000)); } else { - $that->assertEquals('bar', $data[$that->options['data_field']]->bin); - $that->assertInstanceOf('MongoDate', $data[$that->options['time_field']]); - $that->assertInstanceOf('MongoDate', $data[$that->options['expiry_field']]); - $that->assertGreaterThanOrEqual($expectedExpiry, $data[$that->options['expiry_field']]->sec); + $this->assertEquals('bar', $data[$this->options['data_field']]->bin); + $this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]); + $this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]); + $this->assertGreaterThanOrEqual($expectedExpiry, $data[$this->options['expiry_field']]->sec); } } @@ -197,20 +199,19 @@ class MongoDbSessionHandlerTest extends TestCase ->with($this->options['database'], $this->options['collection']) ->will($this->returnValue($collection)); - $that = $this; $data = array(); $methodName = phpversion('mongodb') ? 'updateOne' : 'update'; $collection->expects($this->once()) ->method($methodName) - ->will($this->returnCallback(function ($criteria, $updateData, $options) use ($that, &$data) { - $that->assertEquals(array($that->options['id_field'] => 'foo'), $criteria); + ->will($this->returnCallback(function ($criteria, $updateData, $options) use (&$data) { + $this->assertEquals(array($this->options['id_field'] => 'foo'), $criteria); if (phpversion('mongodb')) { - $that->assertEquals(array('upsert' => true), $options); + $this->assertEquals(array('upsert' => true), $options); } else { - $that->assertEquals(array('upsert' => true, 'multiple' => false), $options); + $this->assertEquals(array('upsert' => true, 'multiple' => false), $options); } $data = $updateData['$set']; @@ -219,13 +220,13 @@ class MongoDbSessionHandlerTest extends TestCase $this->assertTrue($this->storage->write('foo', 'bar')); if (phpversion('mongodb')) { - $that->assertEquals('bar', $data[$that->options['data_field']]->getData()); - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['time_field']]); - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$that->options['expiry_field']]); + $this->assertEquals('bar', $data[$this->options['data_field']]->getData()); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['time_field']]); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $data[$this->options['expiry_field']]); } else { - $that->assertEquals('bar', $data[$that->options['data_field']]->bin); - $that->assertInstanceOf('MongoDate', $data[$that->options['time_field']]); - $that->assertInstanceOf('MongoDate', $data[$that->options['expiry_field']]); + $this->assertEquals('bar', $data[$this->options['data_field']]->bin); + $this->assertInstanceOf('MongoDate', $data[$this->options['time_field']]); + $this->assertInstanceOf('MongoDate', $data[$this->options['expiry_field']]); } } @@ -285,19 +286,17 @@ class MongoDbSessionHandlerTest extends TestCase ->with($this->options['database'], $this->options['collection']) ->will($this->returnValue($collection)); - $that = $this; - - $methodName = phpversion('mongodb') ? 'deleteOne' : 'remove'; + $methodName = phpversion('mongodb') ? 'deleteMany' : 'remove'; $collection->expects($this->once()) ->method($methodName) - ->will($this->returnCallback(function ($criteria) use ($that) { + ->will($this->returnCallback(function ($criteria) { if (phpversion('mongodb')) { - $that->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$that->options['expiry_field']]['$lt']); - $that->assertGreaterThanOrEqual(time() - 1, round(((int) $criteria[$that->options['expiry_field']]['$lt']) / 1000)); + $this->assertInstanceOf('MongoDB\BSON\UTCDateTime', $criteria[$this->options['expiry_field']]['$lt']); + $this->assertGreaterThanOrEqual(time() - 1, round((string) $criteria[$this->options['expiry_field']]['$lt'] / 1000)); } else { - $that->assertInstanceOf('MongoDate', $criteria[$that->options['expiry_field']]['$lt']); - $that->assertGreaterThanOrEqual(time() - 1, $criteria[$that->options['expiry_field']]['$lt']->sec); + $this->assertInstanceOf('MongoDate', $criteria[$this->options['expiry_field']]['$lt']); + $this->assertGreaterThanOrEqual(time() - 1, $criteria[$this->options['expiry_field']]['$lt']->sec); } }));