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: Rewritten to the PHP coding standards.
Updating code to use better with Composer.
Date: 1 month ago
Size: 2,284 bytes
 

Contents

Class file image Download
<?php
/**
 * Cleaner test
 *
 * PHP version 5.3
 *
 * @category Tests
 * @package DelayedMail
 * @author Eustáquio Rangel <eustaquiorangel@gmail.com>
 * @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
 * @link http://github.com/taq/delayedmail
 *
 */
require_once "../vendor/autoload.php";

/**
 * Main class
 *
 * PHP version 5.3
 *
 * @category Tests
 * @package DelayedMail
 * @author Eustáquio Rangel <eustaquiorangel@gmail.com>
 * @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
 * @link http://github.com/taq/delayedmail
 *
 */
class CleanerTest extends PHPUnit_Framework_TestCase
{
    protected static
$cleaner = null;
    protected static
$dir = "/tmp/delayedmailtest/sent/";

   
/**
     * Run before every test
     *
     * @return null
     */
   
public function setUp()
    {
       
self::$cleaner = new DelayedMail\Cleaner(self::$dir, 0.1);
    }

   
/**
     * Test converting to a string
     *
     * @return null
     */
   
public function testToString()
    {
       
$this->assertEquals("cleaning files older than 0.1 minutes on /tmp/delayedmailtest/sent/", self::$cleaner. "");
    }

   
/**
     * Test finding files
     *
     * @return null
     */
   
public function testFind()
    {
       
self::_createFiles();
       
$files = self::$cleaner->find();
       
$this->assertEquals(2, sizeof($files));
       
self::_clearFiles();
    }

   
/**
     * Test running the cleaner
     *
     * @return null
     */
   
public function testRun()
    {
       
self::_createFiles();
       
self::$cleaner->run();
       
$this->assertEquals(1, sizeof(glob(self::$dir."/*")));
       
self::_clearFiles();
    }

   
/**
     * Create test files
     *
     * @return null
     */
   
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;
        }
    }

   
/**
     * Clear test files
     *
     * @return null
     */
   
private function _clearFiles()
    {
        foreach (
glob(self::$dir."/*") as $file) {
           
unlink($file);
        }
    }
}