Guest

Untitled

By: a guest on Jan 28th, 2012  |  syntax: None  |  size: 2.97 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?
  2.  
  3. class domainsTest extends PHPUnit_Framework_TestCase {
  4.     public $filename;
  5.     public $stringList;
  6.  
  7.     function __construct($file = false) {
  8.         if ($file)
  9.             $this->loadFromFile($file);
  10.     }
  11.  
  12. //  it's the same constructor class but in php4 notation
  13. //    function domainsTest () {
  14. //        domainsGetData();
  15. //    }
  16.  
  17.     function loadFromFile($file) {
  18.         $result = true;
  19.         $this->filename = $file;
  20.         if (file_exists($file) && is_readable($file)) {
  21.             $this->initArray();
  22.  //           $this->domainsListDisplay();
  23.         }
  24.         else
  25.             $result = false;
  26.         return $result;
  27.     }
  28.  
  29.     function initArray() {
  30.  
  31.         $this->stringList = 'someval';
  32.         //$this->$stringList = parse_ini_file($this->filename, true);
  33.     }
  34.  
  35.     function domainsCountRecords() {
  36.  
  37.         $filename = 'input_file.txt';
  38.         $file = file($filename);
  39.  
  40.         //if (file_exists($filename))
  41.         //    $emailsList = fopen($filename, "r") or die ("file opening not so well");
  42.  
  43.         $emailList['INVALID'] = 0;
  44.  
  45.         foreach ($file as $key => $emails) {
  46.  
  47.             $emailParts = explode('@', $emails);
  48.             $domain = $emailParts[1];
  49.  
  50.             if (in_array("$domain", array_keys(&$emailList))) {
  51.                 $emailList["$domain"] += 1;
  52.             }
  53.             else {
  54.                 $emailList["$domain"] = 1;
  55.             }
  56.  
  57.             //preg_match
  58.         }
  59.  
  60.         return var_dump($emailList);
  61.     }
  62.  
  63.     function domainsGetData() {
  64.  
  65.     }
  66.  
  67.     function domainsListSort() {
  68.         return msg;
  69.     }
  70.  
  71.     public function domainsList () {
  72.         $val = 'OOP PHP - Cool thing!';
  73.         return $val;
  74.     }
  75.  
  76. //-----------tests
  77.     public function testPushAndPop() {
  78.         $stack = array();
  79.         $this->assertEquals(0, count($stack));
  80.  
  81.         array_push($stack, 'foo');
  82.         $this->assertEquals('foo', $stack[count($stack) - 1]);
  83.         $this->assertEquals(1, count($stack));
  84.  
  85.         $this->assertEquals('foo', array_pop($stack));
  86.         $this->assertEquals(0, count($stack));
  87.     }
  88.  
  89.     public function testEmpty() {
  90.         $stack = array();
  91.         $this->assertTrue(empty($stack));
  92.  
  93.         return $stack;
  94.     }
  95.  
  96.     /**
  97.      * @depends testEmpty
  98.      */
  99.     public function testPush(array $stack) {
  100.         array_push($stack, 'foo');
  101.         $this->assertEquals('foo', $stack[count($stack) - 1]);
  102.         $this->assertFalse(empty($stack));
  103.  
  104.         return $stack;
  105.     }
  106.  
  107.     /**
  108.      * @depends testPush
  109.      */
  110.     public function testPop(array $stack) {
  111.         $this->assertEquals('foo', array_pop($stack));
  112.         $this->assertTrue(empty($stack));
  113.     }
  114.  
  115. //$suite = new PHPUnit_TestSuite('MessageTest');
  116. //$result = PHPUnit::run($suite);
  117. //echo $result->toHTML();
  118.  
  119.     function __destruct() {
  120.         print "Descruct class " . $this->name . "\n";
  121.     }
  122. }
  123.  
  124. $obj = new domainsTest('input_file.txt');
  125. $ibj->domainsList;
  126.  
  127. ?>