4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Profiler;
14 use Symfony\Component\HttpKernel\Profiler\FileProfilerStorage;
15 use Symfony\Component\HttpKernel\Profiler\Profile;
17 class FileProfilerStorageTest extends AbstractProfilerStorageTest
22 protected function cleanDir()
24 $flags = \FilesystemIterator::SKIP_DOTS;
25 $iterator = new \RecursiveDirectoryIterator($this->tmpDir, $flags);
26 $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
28 foreach ($iterator as $file) {
35 protected function setUp()
37 $this->tmpDir = sys_get_temp_dir().'/sf2_profiler_file_storage';
38 if (is_dir($this->tmpDir)) {
41 $this->storage = new FileProfilerStorage('file:'.$this->tmpDir);
42 $this->storage->purge();
45 protected function tearDown()
51 * @return \Symfony\Component\HttpKernel\Profiler\ProfilerStorageInterface
53 protected function getStorage()
55 return $this->storage;
58 public function testMultiRowIndexFile()
61 for ($i = 0; $i < $iteration; ++$i) {
62 $profile = new Profile('token'.$i);
63 $profile->setIp('127.0.0.'.$i);
64 $profile->setUrl('http://foo.bar/'.$i);
65 $storage = $this->getStorage();
67 $storage->write($profile);
68 $storage->write($profile);
69 $storage->write($profile);
72 $handle = fopen($this->tmpDir.'/index.csv', 'r');
73 for ($i = 0; $i < $iteration; ++$i) {
74 $row = fgetcsv($handle);
75 $this->assertEquals('token'.$i, $row[0]);
76 $this->assertEquals('127.0.0.'.$i, $row[1]);
77 $this->assertEquals('http://foo.bar/'.$i, $row[3]);
79 $this->assertFalse(fgetcsv($handle));
82 public function testReadLineFromFile()
84 $r = new \ReflectionMethod($this->storage, 'readLineFromFile');
86 $r->setAccessible(true);
90 fwrite($h, "line1\n\n\nline2\n");
91 fseek($h, 0, SEEK_END);
93 $this->assertEquals('line2', $r->invoke($this->storage, $h));
94 $this->assertEquals('line1', $r->invoke($this->storage, $h));