PHP Classes

File: test/AbstractTaskTest.php

Recommend this page to a friend!
  Classes of nvb   Process Fork Manager for PHP   test/AbstractTaskTest.php   Download  
File: test/AbstractTaskTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Process Fork Manager for PHP
Run parallel processes and manage their execution
Author: By
Last change:
Date: 8 years ago
Size: 2,335 bytes
 

Contents

Class file image Download
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2014-07-28
 */

namespace Test\Net\Bazzline\Component\ProcessForkManager;

/**
 * Class AbstractTaskTest
 * @package Test\Net\Bazzline\Component\ProcessForkManager
 */
class AbstractTaskTest extends ForkManagerTestCase
{
    public function
testSetStartTimeAndGetRunTime()
    {
       
$currentTimestamp = time();
       
$task = $this->getPartialMockOfAbstractTask();

       
$this->assertGreaterThanOrEqual($currentTimestamp, $task->getRunTime());

       
$startTime = $currentTimestamp - 100;
       
$expectedRunTime = $currentTimestamp - $startTime;
       
$task->setStartTime($startTime);
       
$this->assertGreaterThanOrEqual($expectedRunTime, $task->getRunTime());
    }

    public function
testSimpleGetterAndSetter()
    {
       
$task = $this->getPartialMockOfAbstractTask();

       
$currentMemoryLimit = memory_get_usage(true);
       
$this->assertGreaterThanOrEqual($currentMemoryLimit, $task->getMemoryUsage());

       
$this->assertNull($task->getParentProcessId());
       
$parentProcessId = __LINE__;
       
$task->setParentProcessId($parentProcessId);
       
$this->assertEquals($parentProcessId, $task->getParentProcessId());

       
$processId = getmypid();
       
$this->assertEquals($processId, $task->getProcessId());
    }

    public function
testMarkingAndValidatingStatus()
    {
       
$task = $this->getPartialMockOfAbstractTask();

       
$this->assertFalse($task->isAborted());
       
$this->assertFalse($task->isFinished());
       
$this->assertTrue($task->isNotStarted());
       
$this->assertFalse($task->isRunning());

       
$task->markAsAborted();
       
$this->assertTrue($task->isAborted());
       
$this->assertFalse($task->isFinished());
       
$this->assertFalse($task->isNotStarted());
       
$this->assertFalse($task->isRunning());

       
$task->markAsFinished();
       
$this->assertFalse($task->isAborted());
       
$this->assertTrue($task->isFinished());
       
$this->assertFalse($task->isNotStarted());
       
$this->assertFalse($task->isRunning());

       
$task->markAsRunning();
       
$this->assertFalse($task->isAborted());
       
$this->assertFalse($task->isFinished());
       
$this->assertFalse($task->isNotStarted());
       
$this->assertTrue($task->isRunning());
    }
}