Skip to content
This repository

Inspect header #21

Merged
merged 12 commits into from almost 3 years ago

2 participants

Claus Beerta Fabrice Luraine
Claus Beerta
CBeerta commented May 29, 2011

For my little Embedded Server Project i needed a way to track the headers that are beeing sent by Limonade, as unfortunetly in a 'CLI' SAPI environment PHP simply discards calls to header(), and no headers ever show up in headers_list()

Thus i added a inspect_header() abstract that allows you to track the headers sent by Limonade. Example added to the Documentation that shows usage outside my use case aswell.

I'm aware that one could use after() with PHP's headers_list() but this way is a little safer from content beeing sent before after() is called, and a little easier to use.

The First commit reorders the run() function slightly without altering it's functionality. If one uses Limonade from a CLI SAPI you need to cancel run() before any $_SERVER variables are beeing used, and this way it's a bit easier to add. This is entirely Optional, but would make life easier for people using limonade in a CLI environment (as wierd as that may be :)

added some commits May 29, 2011
Claus Beerta Reorder run() configuration.
To be able to use Limonade fro CLI SAPI one needs to intercept the run() before any $_SERVER Variables are used, so reorder it accordingly.
a3b34ee
Claus Beerta Add `inspect_header`to allow inspection of headers beeing sent.
 - New function _lim_header that takes care of sending the header
 - Replace all direct calls of header() with _lim_header()
 - Added Example to abstract.php
 - Added Example Usage to the Documentation.
039e699
Fabrice Luraine
Owner

That an interersting hook. I just think about:

  • renaming the _lim_header function in a more explicit one named send_header. It should be public.
  • renaming the hook inspect_header in before_sending_header to keep consistency with other hooks.

What do you think ?

Claus Beerta
CBeerta commented May 30, 2011

Yeah, cool with the renaming, makes sense to unify these. I'll change the functions accordingly.

The only thing that might be considered if you make send_header public is, that you could end up causing a loop: before_sending_header -> send_header -before_sending_header etc.

Not sure if that is something the framework should protect the developer from though.

Fabrice Luraine
Owner

We can make something like in the render function to protect from loop ?

# Avoid infinite loop: this function is in the backtrace ?
if(function_exists($content_or_func))
{
  $back_trace = debug_backtrace();
  while($trace = array_shift($back_trace))
  {
    if($trace['function'] == strtolower($content_or_func))
    {
      $infinite_loop = true;
      break;
    }
  }
}
Fabrice Luraine
Owner

…Not very good for performances, so maybe we can just put a notice in the documentation ?

Claus Beerta
CBeerta commented May 30, 2011

Yeah, agree. I'll just add a little warning to the Docs.

and others added some commits March 14, 2011
Fix fatal error if memory_get_usage() isn't available. Now benchmark(…
…) only return execution time in this case.

memory_get_usage() might be unavailable before PHP5.2.1 if PHP wasn't compiled with option `--enable-memory-limit`.
Add tests to control `benchmark()` return.
125248a
Fix warning in tests on PHP5.2.3 < . Avoid test for call_if_exists wi…
…th static class method call.
dc8c198
Fix PHP Parse error when running tests on PHP5.3.0 < : use eval to de…
…clare a lambda function.
fd10ee6
Fix a small PHP notice in a test (undefined index…) 17e8bfe
Add a way to manage fallbacks for not implemented functions.
Raise warning if try to use json_encode() when it's not available. PHP 5 < PHP 5.2.0 doesn't provide json functions natively.
f26e049
Fix backward compatibilty function limonade_htmlspecialchars_decode. …
…Now supports &#39; entities
bf5fb97
Prevents flash sweep for HEAD requests like suggested by @msaspence i…
…n issue #20.

Can be useful when using browser extensions like webug in Chrome which
send a HEAD request after each GET or POST request.
491bbaf
Add requirements in README [#50 state:resolved] 0906634
Remove from the README file the link to the public API because it's n…
…o longer maintened.
2fd4138
Claus Beerta Rename _lim_header to send_header. Rename inspect_header to before_se…
…nding_header.
eafcb90
Claus Beerta
CBeerta commented May 30, 2011

Rebased my branch with your head with all those fixes you made in the meantime.

Also: Feel free to discard my very first commit a3b34ee as i've found a much nicer way to do the embedded server thingy.

Fabrice Luraine sofadesign merged commit 3c07e9a into from July 15, 2011
Fabrice Luraine sofadesign closed this July 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 12 unique commits by 2 authors.

May 29, 2011
Claus Beerta Reorder run() configuration.
To be able to use Limonade fro CLI SAPI one needs to intercept the run() before any $_SERVER Variables are used, so reorder it accordingly.
a3b34ee
Claus Beerta Add `inspect_header`to allow inspection of headers beeing sent.
 - New function _lim_header that takes care of sending the header
 - Replace all direct calls of header() with _lim_header()
 - Added Example to abstract.php
 - Added Example Usage to the Documentation.
039e699
May 30, 2011
Fix fatal error if memory_get_usage() isn't available. Now benchmark(…
…) only return execution time in this case.

memory_get_usage() might be unavailable before PHP5.2.1 if PHP wasn't compiled with option `--enable-memory-limit`.
Add tests to control `benchmark()` return.
125248a
Fix warning in tests on PHP5.2.3 < . Avoid test for call_if_exists wi…
…th static class method call.
dc8c198
Fix PHP Parse error when running tests on PHP5.3.0 < : use eval to de…
…clare a lambda function.
fd10ee6
Fix a small PHP notice in a test (undefined index…) 17e8bfe
Add a way to manage fallbacks for not implemented functions.
Raise warning if try to use json_encode() when it's not available. PHP 5 < PHP 5.2.0 doesn't provide json functions natively.
f26e049
Fix backward compatibilty function limonade_htmlspecialchars_decode. …
…Now supports &#39; entities
bf5fb97
Prevents flash sweep for HEAD requests like suggested by @msaspence i…
…n issue #20.

Can be useful when using browser extensions like webug in Chrome which
send a HEAD request after each GET or POST request.
491bbaf
Add requirements in README [#50 state:resolved] 0906634
Remove from the README file the link to the public API because it's n…
…o longer maintened.
2fd4138
Claus Beerta Rename _lim_header to send_header. Rename inspect_header to before_se…
…nding_header.
eafcb90
This page is out of date. Refresh to see the latest.
32  README.mkd
Source Rendered
@@ -22,12 +22,14 @@ Limonade is easy to learn and provides everything that you can expect from a mod
22 22
 
23 23
 This document provides a quick, but comprehensive, guide of Limonade features.
24 24
 
25  
-For more informations, you can see the [website](http://www.limonade-php.net/), 
26  
-[public API documentation](http://www.limonade-php.net/api/), [examples](http://www.limonade-php.net/examples.htm), and of course the [source code](http://github.com/sofadesign/limonade/blob/master/lib/limonade.php) which is still the best documentation.
  25
+For more informations, you can see the [website](http://www.limonade-php.net/), [examples](http://www.limonade-php.net/examples.htm), and of course the [source code](http://github.com/sofadesign/limonade/blob/master/lib/limonade.php) which is still the best documentation.
27 26
 
28 27
 A [discussion group](http://groups.google.fr/group/limonade) is also available for more exchanges.
29 28
 
30  
-    
  29
+## Requirements ##
  30
+
  31
+* PHP 5.1.6 > (successfully tested with PHP 5.1.6 but it might work with older versions)
  32
+   
31 33
 ## Routes ##
32 34
 
33 35
 Routes combine 
@@ -525,6 +527,28 @@ If you define a `before_exit`, it is called at the begining of the stop/exit pro
525 527
         # by default it is true
526 528
     }
527 529
 
  530
+### Before sending a header ###
  531
+
  532
+You can define a `before_sending_header` function that will be called before Limonade emits a header() call. This way you can add additional headers:
  533
+
  534
+    dispatch('/style.css', 'css');
  535
+    function css()
  536
+    {
  537
+        # Generate css file and output
  538
+        return css('style.css.php');
  539
+    }
  540
+
  541
+    function before_sending_header($header)
  542
+    {
  543
+        if (strpos($header, 'text/css') !== false)
  544
+        {
  545
+            # intercept text/css content-type and add caching to the headers
  546
+            send_header("Cache-Control: max-age=600, public");
  547
+        }
  548
+    }
  549
+
  550
+__Caution__: Take care not to cause a loop by repeatedly calling `send_header()` from the `before_sending_header()` function!
  551
+
528 552
 
529 553
 ## Configuration ##
530 554
 
@@ -705,4 +729,4 @@ Limonade also provides a useful set of functions that can help you managing file
705 729
 * [Issue tracking / release planning](http://sofadesign.lighthouseapp.com/projects/29612-limonade/overview)
706 730
 * [Support / Discussions](http://groups.google.fr/group/limonade)
707 731
 
708  
-        
  732
+
136  lib/limonade.php
@@ -60,7 +60,8 @@
60 60
 define('LIM_START_MICROTIME',   (float)substr(microtime(), 0, 10));
61 61
 define('LIM_SESSION_NAME',      'LIMONADE'.str_replace('.','x',LIMONADE));
62 62
 define('LIM_SESSION_FLASH_KEY', '_lim_flash_messages');
63  
-define('LIM_START_MEMORY',      memory_get_usage());
  63
+if(function_exists('memory_get_usage'))
  64
+	define('LIM_START_MEMORY',      memory_get_usage());
64 65
 define('E_LIM_HTTP',            32768);
65 66
 define('E_LIM_PHP',             65536);
66 67
 define('E_LIM_DEPRECATED',      35000);
@@ -186,6 +187,7 @@ function render_limonade_file()
186 187
 # - function before_exit(){}
187 188
 # - function before_render($content_or_func, $layout, $locals, $view_path){}
188 189
 # - function autorender($route){}
  190
+# - function before_sending_header($header){}
189 191
 #
190 192
 # See abstract.php for more details.
191 193
 
@@ -315,17 +317,12 @@ function set_or_default($name, $value, $default)
315 317
  */
316 318
 function run($env = null)
317 319
 {
318  
-  if(is_null($env)) $env = env();
319 320
    
320 321
   # 0. Set default configuration
321 322
   $root_dir  = dirname(app_file());
322  
-  $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME']));
323  
-  $base_file = basename($env['SERVER']['SCRIPT_NAME']);
324  
-  $base_uri  = file_path($base_path, (($base_file == 'index.php') ? '?' : $base_file.'?'));
325 323
   $lim_dir   = dirname(__FILE__);
  324
+  
326 325
   option('root_dir',           $root_dir);
327  
-  option('base_path',          $base_path);
328  
-  option('base_uri',           $base_uri); // set it manually if you use url_rewriting
329 326
   option('limonade_dir',       file_path($lim_dir));
330 327
   option('limonade_views_dir', file_path($lim_dir, 'limonade', 'views'));
331 328
   option('limonade_public_dir',file_path($lim_dir, 'limonade', 'public'));
@@ -344,6 +341,16 @@ function run($env = null)
344 341
                                    // X-SENDFILE: for Apache and Lighttpd v. >= 1.5,
345 342
                                    // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5
346 343
 
  344
+  if(is_null($env)) $env = env();
  345
+
  346
+  $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME']));
  347
+  $base_file = basename($env['SERVER']['SCRIPT_NAME']);
  348
+  $base_uri  = file_path($base_path, (($base_file == 'index.php') ? '?' : $base_file.'?'));
  349
+
  350
+  option('base_path',          $base_path);
  351
+  option('base_uri',           $base_uri); // set it manually if you use url_rewriting
  352
+
  353
+
347 354
   # 1. Set handlers
348 355
   # 1.1 Set error handling
349 356
   ini_set('display_errors', 1);
@@ -362,10 +369,11 @@ function run($env = null)
362 369
   }
363 370
   
364 371
   # 2.2 Set X-Limonade header
365  
-  if($signature = option('signature')) header("X-Limonade: $signature");
  372
+  if($signature = option('signature')) send_header("X-Limonade: $signature");
366 373
 
367 374
   # 3. Loading libs
368 375
   require_once_dir(option('lib_dir'));
  376
+  fallbacks_for_not_implemented_functions();
369 377
 
370 378
   # 4. Starting session
371 379
   if(!defined('SID') && option('session'))
@@ -443,21 +451,25 @@ function autoload_controller($callback)
443 451
 function stop_and_exit($exit = true)
444 452
 {
445 453
   call_if_exists('before_exit', $exit);
446  
-  $flash_sweep = true;
447 454
   $headers = headers_list();
448  
-  foreach($headers as $header)
449  
-  {
450  
-    // If a Content-Type header exists, flash_sweep only if is text/html
451  
-    // Else if there's no Content-Type header, flash_sweep by default
452  
-    if(stripos($header, 'Content-Type:') === 0)
  455
+  if(request_is_head())
  456
+  { 
  457
+     ob_end_clean();
  458
+  } else {
  459
+    $flash_sweep = true;
  460
+    foreach($headers as $header)
453 461
     {
454  
-      $flash_sweep = stripos($header, 'Content-Type: text/html') === 0;
455  
-      break;
  462
+      // If a Content-Type header exists, flash_sweep only if is text/html
  463
+      // Else if there's no Content-Type header, flash_sweep by default
  464
+      if(stripos($header, 'Content-Type:') === 0)
  465
+      {
  466
+        $flash_sweep = stripos($header, 'Content-Type: text/html') === 0;
  467
+        break;
  468
+      }
456 469
     }
  470
+    if($flash_sweep) flash_sweep();
457 471
   }
458  
-  if($flash_sweep) flash_sweep();
459 472
   if(defined('SID')) session_write_close();
460  
-  if(request_is_head()) ob_end_clean();
461 473
   if($exit) exit;
462 474
 }
463 475
 
@@ -1457,7 +1469,7 @@ function partial($content_or_func, $locals = array())
1457 1469
  */ 
1458 1470
 function html($content_or_func, $layout = '', $locals = array())
1459 1471
 {
1460  
-  if(!headers_sent()) header('Content-Type: text/html; charset='.strtolower(option('encoding')));
  1472
+  send_header('Content-Type: text/html; charset='.strtolower(option('encoding')));
1461 1473
   $args = func_get_args();
1462 1474
   return call_user_func_array('render', $args);
1463 1475
 }
@@ -1485,7 +1497,7 @@ function layout($function_or_file = null)
1485 1497
  */
1486 1498
 function xml($data)
1487 1499
 {
1488  
-  if(!headers_sent()) header('Content-Type: text/xml; charset='.strtolower(option('encoding')));
  1500
+  send_header('Content-Type: text/xml; charset='.strtolower(option('encoding')));
1489 1501
   $args = func_get_args();
1490 1502
   return call_user_func_array('render', $args);
1491 1503
 }
@@ -1500,7 +1512,7 @@ function xml($data)
1500 1512
  */
1501 1513
 function css($content_or_func, $layout = '', $locals = array())
1502 1514
 {
1503  
-  if(!headers_sent()) header('Content-Type: text/css; charset='.strtolower(option('encoding')));
  1515
+  send_header('Content-Type: text/css; charset='.strtolower(option('encoding')));
1504 1516
   $args = func_get_args();
1505 1517
   return call_user_func_array('render', $args);
1506 1518
 }
@@ -1515,7 +1527,7 @@ function css($content_or_func, $layout = '', $locals = array())
1515 1527
  */
1516 1528
 function js($content_or_func, $layout = '', $locals = array())
1517 1529
 {
1518  
-  if(!headers_sent()) header('Content-Type: application/javascript; charset='.strtolower(option('encoding')));
  1530
+  send_header('Content-Type: application/javascript; charset='.strtolower(option('encoding')));
1519 1531
   $args = func_get_args();
1520 1532
   return call_user_func_array('render', $args);
1521 1533
 }
@@ -1530,13 +1542,15 @@ function js($content_or_func, $layout = '', $locals = array())
1530 1542
  */
1531 1543
 function txt($content_or_func, $layout = '', $locals = array())
1532 1544
 {
1533  
-  if(!headers_sent()) header('Content-Type: text/plain; charset='.strtolower(option('encoding')));
  1545
+  send_header('Content-Type: text/plain; charset='.strtolower(option('encoding')));
1534 1546
   $args = func_get_args();
1535 1547
   return call_user_func_array('render', $args);
1536 1548
 }
1537 1549
 
1538 1550
 /**
1539  
- * Returns json representation of data with proper http headers
  1551
+ * Returns json representation of data with proper http headers.
  1552
+ * On PHP 5 < PHP 5.2.0, you must provide your own implementation of the
  1553
+ * <code>json_encode()</code> function beore using <code>json()</code>.
1540 1554
  *
1541 1555
  * @param string $data 
1542 1556
  * @param int $json_option
@@ -1544,7 +1558,7 @@ function txt($content_or_func, $layout = '', $locals = array())
1544 1558
  */
1545 1559
 function json($data, $json_option = 0)
1546 1560
 {
1547  
-  if(!headers_sent()) header('Content-Type: application/json; charset='.strtolower(option('encoding')));
  1561
+  send_header('Content-Type: application/json; charset='.strtolower(option('encoding')));
1548 1562
   return version_compare(PHP_VERSION, '5.3.0', '>=') ? json_encode($data, $json_option) : json_encode($data);
1549 1563
 }
1550 1564
 
@@ -1574,12 +1588,26 @@ function render_file($filename, $return = false)
1574 1588
     $content_type = mime_type(file_extension($filename));
1575 1589
     $header = 'Content-type: '.$content_type;
1576 1590
     if(file_is_text($filename)) $header .= '; charset='.strtolower(option('encoding'));
1577  
-    if(!headers_sent()) header($header);
  1591
+    send_header($header);
1578 1592
     return file_read($filename, $return);
1579 1593
   }
1580 1594
   else halt(NOT_FOUND, "unknown filename $filename");
1581 1595
 }
1582 1596
 
  1597
+/**
  1598
+ * Call before_sending_header() if it exists, then send headers
  1599
+ * 
  1600
+ * @param string $header
  1601
+ * @return void
  1602
+ */
  1603
+function send_header($header = null, $replace = true, $code = false)
  1604
+{
  1605
+    if(!headers_sent()) 
  1606
+    {
  1607
+        call_if_exists('before_sending_header', $header);
  1608
+        header($header, $replace, $code);
  1609
+    }
  1610
+}
1583 1611
 
1584 1612
 
1585 1613
 
@@ -1796,21 +1824,26 @@ function end_content_for()
1796 1824
 
1797 1825
 /**
1798 1826
  * Shows current memory and execution time of the application.
  1827
+ * Returns only execution time if <code>memory_get_usage()</code> 
  1828
+ * isn't available.
  1829
+ * ( That's the case before PHP5.2.1 if PHP isn't compiled with option 
  1830
+ *   <code>--enable-memory-limit</code>. )
1799 1831
  * 
1800 1832
  * @access public
1801 1833
  * @return array
1802 1834
  */
1803 1835
 function benchmark()
1804 1836
 {
1805  
-  $current_mem_usage = memory_get_usage();
1806  
-  $execution_time = microtime() - LIM_START_MICROTIME;
1807  
-  
1808  
-  return array(
1809  
-    'current_memory' => $current_mem_usage,
1810  
-    'start_memory' => LIM_START_MEMORY,
1811  
-    'average_memory' => (LIM_START_MEMORY + $current_mem_usage) / 2,
1812  
-    'execution_time' => $execution_time
1813  
-  );
  1837
+	$res = array( 'execution_time' => (microtime() - LIM_START_MICROTIME) );
  1838
+  if(defined('LIM_START_MEMORY'))
  1839
+	{
  1840
+		$current_mem_usage     = memory_get_usage();
  1841
+		$res['current_memory'] = $current_mem_usage;
  1842
+		$res['start_memory']   = LIM_START_MEMORY;
  1843
+		$res['average_memory'] = (LIM_START_MEMORY + $current_mem_usage) / 2;
  1844
+	}
  1845
+	
  1846
+	return $res;
1814 1847
 }
1815 1848
 
1816 1849
 
@@ -2006,7 +2039,7 @@ function status($code = 500)
2006 2039
   if(!headers_sent())
2007 2040
   {
2008 2041
     $str = http_response_status_code($code);
2009  
-    header($str);
  2042
+    send_header($str);
2010 2043
   }
2011 2044
 }
2012 2045
 
@@ -2052,10 +2085,10 @@ function redirect_to($params)
2052 2085
       }
2053 2086
       $n_params[] = $param;
2054 2087
     }
2055  
-		$uri = call_user_func_array('url_for', $n_params);
2056  
-		$uri = htmlspecialchars_decode($uri, ENT_NOQUOTES);
  2088
+    $uri = call_user_func_array('url_for', $n_params);
  2089
+    $uri = htmlspecialchars_decode($uri, ENT_NOQUOTES);
2057 2090
     stop_and_exit(false);
2058  
-    header('Location: '.$uri, true, $status);
  2091
+    send_header('Location: '.$uri, true, $status);
2059 2092
     exit;
2060 2093
   }
2061 2094
 }
@@ -2595,7 +2628,7 @@ function limonade_htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
2595 2628
 {
2596 2629
 	$table = array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style));
2597 2630
 	if($quote_style === ENT_QUOTES)
2598  
-		$table['&#039;'] = '\'';
  2631
+		$table['&#039;'] = $table['&#39;'] = '\'';
2599 2632
 	return strtr($string, $table);
2600 2633
 }
2601 2634
 
@@ -2607,5 +2640,28 @@ function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
2607 2640
 	}
2608 2641
 }
2609 2642
 
  2643
+/**
  2644
+ * Called just after loading libs, it provides fallback for some 
  2645
+ * functions if they don't exists.
  2646
+ *
  2647
+ */
  2648
+function fallbacks_for_not_implemented_functions()
  2649
+{
  2650
+  if(!function_exists('json_encode'))
  2651
+  {
  2652
+    /**
  2653
+     * for PHP 5 < PHP 5.2.0
  2654
+     *
  2655
+     */
  2656
+    function json_encode()
  2657
+    {
  2658
+      trigger_error(
  2659
+        __FUNCTION__ . '(): no JSON functions available. Please provide your own implementation of ' . __FUNCTION__ . '() in order to use it.', E_USER_WARNING
  2660
+      );
  2661
+    }
  2662
+  }
  2663
+}
  2664
+
  2665
+
2610 2666
 
2611 2667
 #   ================================= END ==================================   #
14  lib/limonade/abstract.php
@@ -177,3 +177,17 @@ function autorender($route)
177 177
   # process output depending on $route
178 178
   return $output;
179 179
 }
  180
+
  181
+/**
  182
+ * Called if a header is about to be sent
  183
+ *
  184
+ * @abstract this function might be defined by user
  185
+ * @param string the headers that limonade will send
  186
+ * @return void
  187
+ */
  188
+function before_sending_header($header)
  189
+{
  190
+
  191
+}
  192
+
  193
+
4  tests/apps/03-routing.php
@@ -44,9 +44,9 @@ static public function staticMethod($value=1)
44 44
 dispatch('/route4', 'MyController::staticMethod');
45 45
 if(version_compare(PHP_VERSION, '5.3.0') >= 0)
46 46
 {
47  
-  dispatch('/route-lambda', function(){
  47
+  eval("dispatch('/route-lambda', function(){
48 48
     return 'LAMBDA CALL';
49  
-  });
  49
+  });");
50 50
 }
51 51
 
52 52
 /* parameterized routes */
2  tests/apps/09-redirect.php
@@ -9,7 +9,7 @@ function index()
9 9
 		foreach($pairs as $pair)
10 10
 		{
11 11
 			$keyAndValue = explode('=', $pair);
12  
-			$params[$keyAndValue[0]] = $keyAndValue[1];
  12
+			$params[$keyAndValue[0]] = count($keyAndValue) > 1 ? $keyAndValue[1] : '';
13 13
 		}
14 14
 		array_shift($params);
15 15
 
11  tests/functional.php
@@ -184,6 +184,15 @@ function test_functional_flash()
184 184
      $response  = curl_exec($ch); 
185 185
      assert_match("/ON DISPLAY 2/", $response);
186 186
 
  187
+     # Run a HEAD request on a page where there is no new flash
  188
+     # message set. Previous flash message should still be
  189
+     # there after this request.
  190
+     curl_setopt($ch, CURLOPT_URL, $path.'four'); 
  191
+     curl_setopt($ch, CURLOPT_NOBODY, TRUE); 
  192
+     curl_setopt($ch, CURLOPT_HEADER, 1); 
  193
+     $response  = curl_exec($ch); 
  194
+
  195
+     curl_setopt($ch, CURLOPT_NOBODY, FALSE); 
187 196
      curl_setopt($ch, CURLOPT_URL, $path.'three'); 
188 197
      $response  = curl_exec($ch); 
189 198
      assert_match("/ON DISPLAY 3/", $response);
@@ -208,4 +217,4 @@ function test_functional_flash()
208 217
 
209 218
      curl_close($ch);
210 219
    }
211  
-end_test_case();
  220
+end_test_case();
19  tests/main.php
@@ -108,7 +108,10 @@ static public function testStatic($value=1)
108 108
      $obj = new TestCallIfExists();
109 109
      assert_equal(call_if_exists(array($obj, 'test'), 3), 30);
110 110
      assert_equal(call_if_exists(array('TestCallIfExists', 'testStatic'), 3), 60);
111  
-     assert_equal(call_if_exists('TestCallIfExists::testStatic', 3), 60);
  111
+		 if(version_compare(PHP_VERSION, '5.2.3', '>='))
  112
+		 {			
  113
+	     assert_equal(call_if_exists('TestCallIfExists::testStatic', 3), 60);
  114
+		 }
112 115
    }
113 116
    
114 117
    function test_main_define_unless_exists()
@@ -220,8 +223,22 @@ function test_main_htmlspecialchars_decode()
220 223
 		 assert_equal(limonade_htmlspecialchars_decode('&lt;'), '<');
221 224
 		 assert_equal(limonade_htmlspecialchars_decode('&gt;'), '>');
222 225
 		 assert_equal(limonade_htmlspecialchars_decode('&amp;'), '&');
  226
+     echo htmlspecialchars_decode('&#39;', ENT_QUOTES);
223 227
 		 assert_equal(limonade_htmlspecialchars_decode('&#39;', ENT_QUOTES), '\'');
224 228
 		 assert_equal(limonade_htmlspecialchars_decode('&#039;', ENT_QUOTES), '\'');
225 229
 	 }
  230
+	
  231
+	 function test_main_benchmark()
  232
+	 {
  233
+	 	 $bench = benchmark();
  234
+		 assert_true(is_array($bench));
  235
+		 assert_true(array_key_exists('execution_time', $bench));
  236
+		 if(function_exists('memory_get_usage'))
  237
+		 {
  238
+			 assert_true(defined('LIM_START_MEMORY'));
  239
+		   assert_true(array_key_exists('start_memory', $bench));
  240
+		   assert_equal(LIM_START_MEMORY, $bench['start_memory']);
  241
+		 }
  242
+	 }
226 243
    
227 244
 end_test_case();
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.