PHP Classes

File: test/ssa/runner/resolver/ObjectResolverCORTest.php

Recommend this page to a friend!
  Packages of thomas   SSA   test/ssa/runner/resolver/ObjectResolverCORTest.php   Download  
File: test/ssa/runner/resolver/ObjectResolverCORTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: SSA
Call PHP classes from JavaScript on Web pages
Author: By
Last change:
Date: 12 years ago
Size: 2,835 bytes
 

 

Contents

Class file image Download
<?php

namespace ssa\runner\resolver;

/**
 * A chain of responsabilty (COR) for convert object into correct type
 *  PrimitiveResolverCOR
 *
 * @author thomas
 */
class ObjectResolverCORTest extends \PHPUnit_Framework_TestCase {
    
    private $objectResolverCor;
    private $objectResolverCor2;
    private $objectResolverCor3;
    
    public function setUp() {
        $this->objectResolverCor = $this->getMockForAbstractClass('ssa\runner\resolver\ObjectResolverCor');
        $this->objectResolverCor->expects($this->any())
                                ->method('canResolve')
                                ->will($this->returnValue(false));
        
        $this->objectResolverCor2 = $this->getMockForAbstractClass('ssa\runner\resolver\ObjectResolverCor');
        $this->objectResolverCor2->expects($this->any())
                                ->method('canResolve')
                                ->will($this->returnValue(true));
        $this->objectResolverCor2->expects($this->any())
                                ->method('resolve')
                                ->will($this->returnValue(2));
        
        $this->objectResolverCor3 = $this->getMockForAbstractClass('ssa\runner\resolver\ObjectResolverCor');
        $this->objectResolverCor3->expects($this->any())
                                ->method('canResolve')
                                ->will($this->returnValue(true));
        $this->objectResolverCor3->expects($this->any())
                                ->method('resolve')
                                ->will($this->returnValue(8));
        
    }
    
    /**
     * @expectedException \ssa\runner\resolver\TypeNotSupportedException
     */
    public function testCanNotResolve() {
        $docParam = array('Test');
        $this->objectResolverCor->resolveObject(
                new \ReflectionClass('\PHPUnit_Framework_TestCase'),
                array(),
                $docParam
        );
    }

    public function testUseSecondResolver() {
        $this->objectResolverCor->addResolver($this->objectResolverCor2);
        $docParam = array('Test');
        $return = $this->objectResolverCor->resolveObject(
                new \ReflectionClass('\PHPUnit_Framework_TestCase'),
                array(),
                $docParam
        );
        $this->assertEquals(2, $return);
    }
    
    public function testUseFirstPossibleResolver() {
        $this->objectResolverCor->addResolver($this->objectResolverCor2);
        $this->objectResolverCor->addResolver($this->objectResolverCor3);
        $docParam = array('Test');
        $return = $this->objectResolverCor->resolveObject(
                new \ReflectionClass('\PHPUnit_Framework_TestCase'),
                array(),
                $docParam
        );
        $this->assertEquals(8, $return);
    }
}