1 | <?php |
||
7 | abstract class BootstrapTestSuite extends WebTestCase |
||
8 | { |
||
9 | public $client; |
||
10 | public $crawler; |
||
11 | public $response; |
||
12 | |||
13 | protected function setupTest($path) |
||
14 | { |
||
15 | $client = static::createClient(); |
||
16 | |||
17 | $this->setClient($client); |
||
18 | $client->enableProfiler(); |
||
19 | $crawler = $client->request('GET', $path); |
||
20 | $response = $client->getResponse(); |
||
21 | $this->setupBootstrapping($client, $crawler, $response); |
||
22 | |||
23 | return array('client' => $client, 'crawler' => $crawler, 'response' => $response); |
||
24 | } |
||
25 | |||
26 | public function setupBootstrapping($client, $crawler, $response) |
||
27 | { |
||
28 | $this->setClient($client); |
||
29 | $this->setCrawler($crawler); |
||
30 | $this->setResponse($response); |
||
31 | } |
||
32 | |||
33 | public function globalTests($status = 200) |
||
34 | { |
||
35 | if (strpos(strval($status), '2') === 0) { |
||
36 | $this->assertTrue($this->client->getResponse()->isSuccessful(), 'Response is a sucessful one'); |
||
37 | } else { |
||
38 | $this->assertEquals($this->response->getStatusCode(), $status, 'Response Code Check'); |
||
39 | } |
||
40 | |||
41 | if ($status == 200) { |
||
42 | $this->assertTrue($this->crawler->filter('html:contains("PHP FIG")')->count() > 0, 'Header Check'); |
||
43 | } |
||
44 | |||
45 | if ($profile = $this->client->getProfile()) { |
||
46 | $this->profileCheck($profile); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | private function profileCheck($profile) |
||
51 | { |
||
52 | $this->assertLessThan( |
||
53 | 50, |
||
54 | $profile->getCollector('db')->getQueryCount(), |
||
55 | ('Checks that query count is less than 50 (token '.$profile->getToken().')') |
||
56 | ); |
||
57 | |||
58 | $this->assertLessThan( |
||
59 | 10000, // ms |
||
60 | $profile->getCollector('time')->getDuration(), |
||
61 | ('Checks that time count is '.$profile->getCollector('time')->getDuration().' which is not less than 10000ms (token '.$profile->getToken().')') |
||
62 | ); |
||
63 | |||
64 | $this->assertLessThan( |
||
65 | 70000000, // 70MB |
||
66 | $profile->getCollector('memory')->getMemory(), |
||
67 | ('Checks that memory check is '.$profile->getCollector('memory')->getMemory().' bytes which is not less than 70MB (token '.$profile->getToken().')') |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | public function get($dependency) |
||
72 | { |
||
73 | $container = $this->client->getContainer(); |
||
74 | |||
75 | return $container->get($dependency); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Gets the value of client. |
||
80 | * |
||
81 | * @return mixed |
||
82 | */ |
||
83 | public function getClient() |
||
84 | { |
||
85 | return $this->client; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Sets the value of client. |
||
90 | * |
||
91 | * @param mixed $client the client |
||
92 | * |
||
93 | * @return self |
||
94 | */ |
||
95 | public function setClient($client) |
||
96 | { |
||
97 | $this->client = $client; |
||
98 | |||
99 | return $this; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Gets the value of crawler. |
||
104 | * |
||
105 | * @return mixed |
||
106 | */ |
||
107 | public function getCrawler() |
||
108 | { |
||
109 | return $this->crawler; |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Sets the value of crawler. |
||
114 | * |
||
115 | * @param mixed $crawler the crawler |
||
116 | * |
||
117 | * @return self |
||
118 | */ |
||
119 | public function setCrawler($crawler) |
||
120 | { |
||
121 | $this->crawler = $crawler; |
||
122 | |||
123 | return $this; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Gets the value of response. |
||
128 | * |
||
129 | * @return mixed |
||
130 | */ |
||
131 | public function getResponse() |
||
132 | { |
||
133 | return $this->response; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Sets the value of response. |
||
138 | * |
||
139 | * @param mixed $response the response |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | public function setResponse($response) |
||
144 | { |
||
145 | $this->response = $response; |
||
146 | |||
147 | return $this; |
||
148 | } |
||
149 | } |
||
150 |