<?php

namespace SimpleIT;

/**
 * Class BaseServiceTest
 *
 * @author Sylvain Mauduit <sylvain.mauduit@simple-it.fr>
 * @deprectaed
 */
abstract class BaseServiceTest extends BaseTest
{
    /**
     * @var  mixed
     */
    private $testedService;

    protected static $mocked = array();

    public function setUp()
    {
        $this->getTestedService();
    }

    /**
     * Get testedService
     *
     * @return mixed Service
     */
    public function getTestedService()
    {
        if (is_null($this->testedService)) {
            $this->testedService = $this->buildService();
        }

        return $this->testedService;
    }

    protected static function registerMock($className)
    {
        self::$mocked[$className] = null;
    }

    protected function getMocked($className)
    {
        if (array_key_exists($className, self::$mocked)) {

            $mocked = self::$mocked[$className];
            if (is_null($mocked)) {
                $mocked = $this->getSingleMock(
                    $className,
                    self::$mocked[$className]
                );
            }

            return $mocked;

        } else {
            throw new \DomainException('Mock '.$className.' is not registered.');
        }
    }

    /**
     * Build and initialize the tested service
     *
     * @return mixed
     */
    abstract protected function buildService();
}
