PHP Classes

File: tests/ClockTest.php

Recommend this page to a friend!
  Classes of Tomas Pavlatka   PTX PHP GD Analog Clock   tests/ClockTest.php   Download  
File: tests/ClockTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PTX PHP GD Analog Clock
Render the time on analog clock as an image
Author: By
Last change:
Date: 9 years ago
Size: 1,524 bytes
 

Contents

Class file image Download
<?php

class ClockTest extends PHPUnit_Framework_TestCase {

   
/**
     * Keeps object to Clock class.
     *
     * @var
     */
   
private $Clock;

    protected function
setUp()
    {
       
parent::setUp();
    }

    protected function
tearDown()
    {
        unset(
$this->Clock);
       
parent::tearDown();
    }

   
/**
     * @param string $time
     * @param int $expected_hour
     * @param int $expected_min
     *
     * @dataProvider data_testInit_ValidTime_ProperData
     */
   
public function testInit_ValidTime_ProperData($time, $expected_hour, $expected_min)
    {
       
$this->init_object($time);

       
$hour = $this->Clock->get_hour();
       
$this->assertEquals($hour, $expected_hour);

       
$hour = $this->Clock->get_min();
       
$this->assertEquals($hour, $expected_min);
    }

   
/**
     * @expectedException \PTX\ClockException
     */
   
public function testInit_InvalidTime_Exception()
    {
       
$this->init_object('14:25');

       
$hour = $this->Clock->get_hour();
       
$this->assertEquals($hour, 10);

       
$hour = $this->Clock->get_min();
       
$this->assertEquals($hour, 25);
    }

    public function
data_testInit_ValidTime_ProperData() {
        return array(
            array(
'10:25', 10, 25),
            array(
'01:25', 01, 25),
            array(
'1:25', 01, 25),
            array(
'1:01', 01, 01),
            array(
'1:1', 01, 01),
        );
    }

    public function
init_object($time)
    {
       
$this->Clock = new \PTX\Clock($time);
    }
}