Login   Register  
PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cesar D. Rodas  >  Persistent Array  >  test.php  >  Download  
File: test.php
Role: Unit test script
Content type: text/plain
Description: Testing
Class: Persistent Array
Access flat file databases like arrays
Author: By
Last change:
Date: 6 years ago
Size: 3,009 bytes
 

Contents

Class file image Download
<?php
/*
 +-------------------------------------------------------------------------+
 |   Copyright (C) 2007-2008 by SixDegrees                                 |
 |   cesar@sixdegrees.com.br                                               |
 |   http://www.sixdegrees.com.br/                                         |
 |                                                                         |
 |   Permission is hereby granted, free of charge, to any person obtaining |
 |   a copy of this software and associated documentation files (the       |
 |   "Software"), to deal in the Software without restriction, including   |
 |   without limitation the rights to use, copy, modify, merge, publish,   |
 |   distribute, sublicense, and/or sell copies of the Software, and to    |
 |   permit persons to whom the Software is furnished to do so, subject to |
 |   the following conditions:                                             |
 |                                                                         |
 |   The above copyright notice and this permission notice shall be        |
 |   included in all copies or substantial portions of the Software.       |
 |                                                                         |
 |   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       |
 |   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    |
 |   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.|
 |   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     |
 |   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
 |   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
 |   OTHER DEALINGS IN THE SOFTWARE.                                       |
 +-------------------------------------------------------------------------+
 |   Author: Cesar D. Rodas <cesar@sixdegrees.com.br>                      |
 +-------------------------------------------------------------------------+
*/

/**
 *  Testing.
 *  
 *  One important thing, I don't know why "isSet" always returns
 *  false... If anyone know please let me know.
 *  
 *  Actually if element doesn't exist it will return a empty string.
 */
 
require(dirname(__FILE__)."/parray.php");

$example_set = array( 
    
=> range(1,50),
    
'foo' => 'bar',
    
=> array("another","array",1)
);

$parray = new parray("test.db");
if ( !
$parray['create'] ) {
    print 
"Creating Array. This should happend only the first time<br>\n";
    foreach( 
$example_set as $k => $v
        
$parray[$k] = $v;
    
$parray['create'] = 1;
    print 
"To test it well, please refresh the page (or re-run this script)<br>\n";
}
print 
"<h1>Testing</h1>\n";
foreach( 
$example_set as $k => $v) {
    print 
"Comparing $k...";
    
    
$result =  is_array($example_set[$k]) ? count array_diff($example_set[$k],$parray[$k]) ) == $example_set[$k] == $parray[$k];
    if ( 
$result )
        print 
" OK<br>\n";
    else
        die(
"failed");
}
?>