PHP Classes
elePHPant
Icontem

File: test/cleanerTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eustaquio Rangel de Oliveira Jr.  >  PHP Delayed Email class  >  test/cleanerTest.php  >  Download  
File: test/cleanerTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP Delayed Email class
Queue email messages in files to send them later
Author: By
Last change:
Date: 1 year ago
Size: 1,201 bytes
 

Contents

Class file image Download
<?php
include_once "../cleaner.php";

class
CleanerTest extends PHPUnit_Framework_TestCase {
   protected static
$cleaner = null;
   protected static
$dir = "/tmp/delayedmailtest/sent/";

   public function
setUp() {
     
self::$cleaner = new DelayedMail\Cleaner(self::$dir,0.1);
   }

   public function
testToString() {
     
$this->assertEquals("cleaning files older than 0.1 minutes on /tmp/delayedmailtest/sent/",self::$cleaner."");
   }

   public function
testFind() {
     
self::createFiles();
     
$files = self::$cleaner->find();
     
$this->assertEquals(2,sizeof($files));
     
self::clearFiles();
   }

   public function
testRun() {
     
self::createFiles();
     
self::$cleaner->run();
     
$this->assertEquals(1,sizeof(glob(self::$dir."/*")));
     
self::clearFiles();
   }

   private function
createFiles() {
     
$time = mktime()-18;
      if(!
file_exists(self::$dir))
        
mkdir(self::$dir,0777,true);

      foreach(array(
"a","b","c") as $name) {
        
$file = self::$dir."/$name";
        
touch($file,$time);
        
$time += 6;
      }
   }

   private function
clearFiles() {
      foreach(
glob(self::$dir."/*") as $file)
        
unlink($file);
   }
}