1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sitetheory\Bundle\ProfilerStorageBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Sitetheory\Bundle\ProfilerStorageBundle\Profiler\MongoDbProfilerStorage; |
7
|
|
|
use Sitetheory\Bundle\ProfilerStorageBundle\Profiler\Profiler; |
8
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
9
|
|
|
use Symfony\Component\HttpKernel\Profiler\Profile; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @internal |
13
|
|
|
* @coversNothing |
14
|
|
|
*/ |
15
|
|
|
class FunctionalTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var KernelInterface |
19
|
|
|
*/ |
20
|
|
|
//private $kernel; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var Profiler |
24
|
|
|
*/ |
25
|
|
|
private $profiler; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
/* TODO: There are more tests we could run with a kernel present * |
30
|
|
|
$this->kernel = new AppKernel('test', true); |
31
|
|
|
$this->kernel->boot(); |
32
|
|
|
/* */ |
33
|
|
|
//$this->kernel->getContainer()->get('yaml.test'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function tearDown() |
37
|
|
|
{ |
38
|
|
|
/* * |
39
|
|
|
$this->kernel->shutdown(); |
40
|
|
|
/* */ |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param int $length |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
protected function makeToken($length = 8) |
49
|
|
|
{ |
50
|
|
|
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; |
51
|
|
|
$string = ''; |
52
|
|
|
$max = strlen($characters) - 1; |
53
|
|
|
for ($i = 0; $i < $length; ++$i) { |
54
|
|
|
$string .= $characters[mt_rand(0, $max)]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $string; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return MongoDbProfilerStorage|Profiler |
62
|
|
|
*/ |
63
|
|
|
public function getProfiler() |
64
|
|
|
{ |
65
|
|
|
if (null !== $this->profiler) { |
66
|
|
|
return $this->profiler; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$profiler = new MongoDbProfilerStorage('mongodb://127.0.0.1/test/profiler'); |
70
|
|
|
|
71
|
|
|
return $this->profiler = $profiler; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testConnect() |
75
|
|
|
{ |
76
|
|
|
$this->assertNotEmpty($this->getProfiler()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testPurge() |
80
|
|
|
{ |
81
|
|
|
$this->assertNotEmpty($this->getProfiler()->purge()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testReadWrite() |
85
|
|
|
{ |
86
|
|
|
// Store Token |
87
|
|
|
$token = $this->makeToken(); |
88
|
|
|
|
89
|
|
|
// Run Profile |
90
|
|
|
$profile = new Profile($token); |
91
|
|
|
$profile->setTime(time()); |
92
|
|
|
$profile->setIp('127.0.0.1'); |
93
|
|
|
$profile->setUrl('http://127.0.0.1/'); |
94
|
|
|
$profile->setMethod('GET'); |
95
|
|
|
$profile->setStatusCode(500); |
96
|
|
|
|
97
|
|
|
// Write |
98
|
|
|
$this->assertTrue($this->getProfiler()->write($profile), 'Write Profile'); |
|
|
|
|
99
|
|
|
|
100
|
|
|
// Read |
101
|
|
|
$profiles = $this->getProfiler()->find( |
102
|
|
|
$profile->getIp(), |
103
|
|
|
$profile->getUrl(), |
104
|
|
|
20, |
105
|
|
|
$profile->getMethod(), |
106
|
|
|
null, |
107
|
|
|
null, |
108
|
|
|
$profile->getStatusCode() |
109
|
|
|
); |
110
|
|
|
|
111
|
|
|
// Ensure Profiles Exist |
112
|
|
|
$this->assertNotEmpty($profiles); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..