X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FProfiler%2FMongoDbProfilerStorageTest.php;fp=vendor%2Fsymfony%2Fhttp-kernel%2FTests%2FProfiler%2FMongoDbProfilerStorageTest.php;h=2d093dfd37c29a724682f04caafb4ab48d518ddb;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/symfony/http-kernel/Tests/Profiler/MongoDbProfilerStorageTest.php b/vendor/symfony/http-kernel/Tests/Profiler/MongoDbProfilerStorageTest.php new file mode 100644 index 000000000..2d093dfd3 --- /dev/null +++ b/vendor/symfony/http-kernel/Tests/Profiler/MongoDbProfilerStorageTest.php @@ -0,0 +1,151 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\Profiler; + +use Symfony\Component\HttpKernel\Profiler\MongoDbProfilerStorage; +use Symfony\Component\HttpKernel\Profiler\Profile; +use Symfony\Component\HttpKernel\DataCollector\DataCollector; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; + +class MongoDbProfilerStorageTestDataCollector extends DataCollector +{ + public function setData($data) + { + $this->data = $data; + } + + public function getData() + { + return $this->data; + } + + public function collect(Request $request, Response $response, \Exception $exception = null) + { + } + + public function getName() + { + return 'test_data_collector'; + } +} + +/** + * @group legacy + * @requires extension mongo + */ +class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest +{ + private $storage; + + public function getDsns() + { + return array( + array('mongodb://localhost/symfony_tests/profiler_data', array( + 'mongodb://localhost/symfony_tests', + 'symfony_tests', + 'profiler_data', + )), + array('mongodb://user:password@localhost/symfony_tests/profiler_data', array( + 'mongodb://user:password@localhost/symfony_tests', + 'symfony_tests', + 'profiler_data', + )), + array('mongodb://user:password@localhost/admin/symfony_tests/profiler_data', array( + 'mongodb://user:password@localhost/admin', + 'symfony_tests', + 'profiler_data', + )), + array('mongodb://user:password@localhost:27009,localhost:27010/?replicaSet=rs-name&authSource=admin/symfony_tests/profiler_data', array( + 'mongodb://user:password@localhost:27009,localhost:27010/?replicaSet=rs-name&authSource=admin', + 'symfony_tests', + 'profiler_data', + )), + ); + } + + public function testCleanup() + { + $dt = new \DateTime('-2 day'); + for ($i = 0; $i < 3; ++$i) { + $dt->modify('-1 day'); + $profile = new Profile('time_'.$i); + $profile->setTime($dt->getTimestamp()); + $profile->setMethod('GET'); + $this->storage->write($profile); + } + $records = $this->storage->find('', '', 3, 'GET'); + $this->assertCount(1, $records, '->find() returns only one record'); + $this->assertEquals($records[0]['token'], 'time_2', '->find() returns the latest added record'); + $this->storage->purge(); + } + + /** + * @dataProvider getDsns + */ + public function testDsnParser($dsn, $expected) + { + $m = new \ReflectionMethod($this->storage, 'parseDsn'); + $m->setAccessible(true); + + $this->assertEquals($expected, $m->invoke($this->storage, $dsn)); + } + + public function testUtf8() + { + $profile = new Profile('utf8_test_profile'); + + $data = 'HЁʃʃϿ, ϢorЃd!'; + $nonUtf8Data = iconv('UTF-8', 'UCS-2', $data); + + $collector = new MongoDbProfilerStorageTestDataCollector(); + $collector->setData($nonUtf8Data); + + $profile->setCollectors(array($collector)); + + $this->storage->write($profile); + + $readProfile = $this->storage->read('utf8_test_profile'); + $collectors = $readProfile->getCollectors(); + + $this->assertCount(1, $collectors); + $this->assertArrayHasKey('test_data_collector', $collectors); + $this->assertEquals($nonUtf8Data, $collectors['test_data_collector']->getData(), 'Non-UTF8 data is properly encoded/decoded'); + } + + /** + * @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface + */ + protected function getStorage() + { + return $this->storage; + } + + protected function setUp() + { + $this->storage = new MongoDbProfilerStorage('mongodb://localhost/symfony_tests/profiler_data', '', '', 86400); + $m = new \ReflectionMethod($this->storage, 'getMongo'); + $m->setAccessible(true); + try { + $m->invoke($this->storage); + } catch (\MongoConnectionException $e) { + $this->markTestSkipped('A MongoDB server on localhost is required.'); + } + + $this->storage->purge(); + } + + protected function tearDown() + { + $this->storage->purge(); + } +}