- <?
- class domainsTest extends PHPUnit_Framework_TestCase {
- public $filename;
- public $stringList;
- function __construct($file = false) {
- if ($file)
- $this->loadFromFile($file);
- }
- // it's the same constructor class but in php4 notation
- // function domainsTest () {
- // domainsGetData();
- // }
- function loadFromFile($file) {
- $result = true;
- $this->filename = $file;
- if (file_exists($file) && is_readable($file)) {
- $this->initArray();
- // $this->domainsListDisplay();
- }
- else
- $result = false;
- return $result;
- }
- function initArray() {
- $this->stringList = 'someval';
- //$this->$stringList = parse_ini_file($this->filename, true);
- }
- function domainsCountRecords() {
- $filename = 'input_file.txt';
- $file = file($filename);
- //if (file_exists($filename))
- // $emailsList = fopen($filename, "r") or die ("file opening not so well");
- $emailList['INVALID'] = 0;
- foreach ($file as $key => $emails) {
- $emailParts = explode('@', $emails);
- $domain = $emailParts[1];
- if (in_array("$domain", array_keys(&$emailList))) {
- $emailList["$domain"] += 1;
- }
- else {
- $emailList["$domain"] = 1;
- }
- //preg_match
- }
- return var_dump($emailList);
- }
- function domainsGetData() {
- }
- function domainsListSort() {
- return msg;
- }
- public function domainsList () {
- $val = 'OOP PHP - Cool thing!';
- return $val;
- }
- //-----------tests
- public function testPushAndPop() {
- $stack = array();
- $this->assertEquals(0, count($stack));
- array_push($stack, 'foo');
- $this->assertEquals('foo', $stack[count($stack) - 1]);
- $this->assertEquals(1, count($stack));
- $this->assertEquals('foo', array_pop($stack));
- $this->assertEquals(0, count($stack));
- }
- public function testEmpty() {
- $stack = array();
- $this->assertTrue(empty($stack));
- return $stack;
- }
- /**
- * @depends testEmpty
- */
- public function testPush(array $stack) {
- array_push($stack, 'foo');
- $this->assertEquals('foo', $stack[count($stack) - 1]);
- $this->assertFalse(empty($stack));
- return $stack;
- }
- /**
- * @depends testPush
- */
- public function testPop(array $stack) {
- $this->assertEquals('foo', array_pop($stack));
- $this->assertTrue(empty($stack));
- }
- //$suite = new PHPUnit_TestSuite('MessageTest');
- //$result = PHPUnit::run($suite);
- //echo $result->toHTML();
- function __destruct() {
- print "Descruct class " . $this->name . "\n";
- }
- }
- $obj = new domainsTest('input_file.txt');
- $ibj->domainsList;
- ?>