Skip to content
OperationManufacturerTest.php 2.61 KiB
Newer Older
<?php

/**
 * Class OperationManufacturerTest
 *
 * Date: 26.03.13
 * Time: 12:30
 * @author Thomas Joußen <tjoussen@databay.de>
 */
Michael Jansen's avatar
Michael Jansen committed
class OperationManufacturerTest extends PHPUnit_Framework_TestCase
{
Michael Jansen's avatar
Michael Jansen committed
    /**
     * @var ReflectionClass
     */
    protected $reflection;
Michael Jansen's avatar
Michael Jansen committed
    /**
     * @var OperationManufacturer
     */
    protected $manufacturer;
Michael Jansen's avatar
Michael Jansen committed
    /**
     * @var string
     */
    protected $expected_pattern = '/[&\|<>=]+/';
Michael Jansen's avatar
Michael Jansen committed
    public function setUp()
    {
        include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php';
Michael Jansen's avatar
Michael Jansen committed
        $this->reflection = new ReflectionClass("OperationManufacturer");
        $this->manufacturer = OperationManufacturer::_getInstance();
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_NotConstructable()
    {
        $this->assertFalse($this->reflection->isInstantiable());
        $method = $this->reflection->getMethod("__construct");
        $this->assertTrue($method->isPrivate());
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_NotCloneable()
    {
        $this->assertFalse($this->reflection->isCloneable());
        $method = $this->reflection->getMethod("__clone");
        $this->assertTrue($method->isPrivate());
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_Singleton()
    {
        $this->assertNotNull($this->manufacturer);
        $this->assertEquals($this->manufacturer, OperationManufacturer::_getInstance());
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_GetPattern()
    {
        $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern());
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_MatchPattern()
    {
        $subject = '< = > & | <> <= >=';
        $matches = $this->manufacturer->match($subject);
        $tokens = \explode(" ", $subject);
        foreach ($tokens as $token) {
            $this->assertContains($token, $matches);
        }
    }
Michael Jansen's avatar
Michael Jansen committed
    public function test_SupportedOperations()
    {
        $operations = array(
            "<" => 'LesserOperation',
            "<=" => "LesserOrEqualsOperation",
            "=" => "EqualsOperation",
            ">=" => "GreaterOrEqualsOperation",
            ">" => "GreaterOperation",
            "<>" => "NotEqualsOperation",
            "&" => "AndOperation",
            "|" => "OrOperation"
        );
Michael Jansen's avatar
Michael Jansen committed
        foreach ($operations as $key => $operation) {
            include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php";
            $operation_object = $this->manufacturer->manufacture($key);
            $this->assertInstanceOf($operation, $operation_object);
        }
    }
Michael Jansen's avatar
Michael Jansen committed
    /**
     * @expectedException UnsupportedOperation
     */
    public function test_UnsupportedOperation()
    {
        $this->manufacturer->manufacture("==");
    }