|
19 | 19 |
|
20 | 20 | class ProfilerTest extends \PHPUnit_Framework_TestCase
|
21 | 21 | {
|
22 |
| - protected function setUp() |
23 |
| - { |
24 |
| - if (!class_exists('Symfony\Component\HttpFoundation\Request')) { |
25 |
| - $this->markTestSkipped('The "HttpFoundation" component is not available'); |
26 |
| - } |
27 |
| - } |
| 22 | + private $tmp; |
| 23 | + private $storage; |
28 | 24 |
|
29 | 25 | public function testCollect()
|
30 | 26 | {
|
31 |
| - if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) { |
32 |
| - $this->markTestSkipped('This test requires SQLite support in your environment'); |
33 |
| - } |
34 |
| - |
35 | 27 | $request = new Request();
|
36 | 28 | $request->query->set('foo', 'bar');
|
37 | 29 | $response = new Response();
|
38 | 30 | $collector = new RequestDataCollector();
|
39 | 31 |
|
40 |
| - $tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler'); |
41 |
| - if (file_exists($tmp)) { |
42 |
| - @unlink($tmp); |
43 |
| - } |
44 |
| - $storage = new SqliteProfilerStorage('sqlite:'.$tmp); |
45 |
| - $storage->purge(); |
46 |
| - |
47 |
| - $profiler = new Profiler($storage); |
| 32 | + $profiler = new Profiler($this->storage); |
48 | 33 | $profiler->add($collector);
|
49 | 34 | $profile = $profiler->collect($request, $response);
|
50 | 35 |
|
51 | 36 | $profile = $profiler->loadProfile($profile->getToken());
|
52 | 37 | $this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
|
| 38 | + } |
| 39 | + |
| 40 | + public function testFindWorksWithDates() |
| 41 | + { |
| 42 | + $profiler = new Profiler($this->storage); |
| 43 | + |
| 44 | + $this->assertCount(0, $profiler->find(null, null, null, null, '7th April 2014', '9th April 2014')); |
| 45 | + } |
| 46 | + |
| 47 | + public function testFindWorksWithTimestamps() |
| 48 | + { |
| 49 | + $profiler = new Profiler($this->storage); |
| 50 | + |
| 51 | + $this->assertCount(0, $profiler->find(null, null, null, null, '1396828800', '1397001600')); |
| 52 | + } |
| 53 | + |
| 54 | + public function testFindWorksWithInvalidDates() |
| 55 | + { |
| 56 | + $profiler = new Profiler($this->storage); |
| 57 | + |
| 58 | + $this->assertCount(0, $profiler->find(null, null, null, null, 'some string', '')); |
| 59 | + } |
| 60 | + |
| 61 | + protected function setUp() |
| 62 | + { |
| 63 | + if (!class_exists('Symfony\Component\HttpFoundation\Request')) { |
| 64 | + $this->markTestSkipped('The "HttpFoundation" component is not available'); |
| 65 | + } |
| 66 | + |
| 67 | + if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) { |
| 68 | + $this->markTestSkipped('This test requires SQLite support in your environment'); |
| 69 | + } |
| 70 | + |
| 71 | + $this->tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler'); |
| 72 | + if (file_exists($this->tmp)) { |
| 73 | + @unlink($this->tmp); |
| 74 | + } |
| 75 | + |
| 76 | + $this->storage = new SqliteProfilerStorage('sqlite:'.$this->tmp); |
| 77 | + $this->storage->purge(); |
| 78 | + } |
| 79 | + |
| 80 | + protected function tearDown() |
| 81 | + { |
| 82 | + $this->storage->purge(); |
| 83 | + $this->storage = null; |
53 | 84 |
|
54 |
| - @unlink($tmp); |
| 85 | + @unlink($this->tmp); |
55 | 86 | }
|
56 | 87 | }
|
0 commit comments