/**
  * Default constructor
  *
  * We will do all the necessary work to load without any further hassle.
  * Will check if there is content in the cache directory.
  * If not we will parse anew.
  *
  * @param \TechDivision\PBC\Config|null $config An already existing config instance
  */
 public function __construct(Config $config = null)
 {
     // If we got a config we can use it, if not we will get a context less config instance
     if (is_null($config)) {
         $config = new Config();
         $config->load(self::CONFIG_FILE);
     }
     // Construct the parent from the config we got
     parent::__construct($config);
     // We now have a structure map instance, so fill it initially
     $this->getStructureMap()->fill();
     // Check if there are files in the cache.
     // If not we will fill the cache, if there are we will check if there have been any changes to the enforced dirs
     $fileIterator = new \FilesystemIterator($this->config->getValue('cache/dir'), \FilesystemIterator::SKIP_DOTS);
     if (iterator_count($fileIterator) <= 1 || $this->config->getValue('environment') === 'development') {
         // Fill the cache
         $this->fillCache();
     } else {
         if (!$this->structureMap->isRecent()) {
             $this->refillCache();
         }
     }
 }
<?php

/**
 * File bootstrapping the PHPUnit test environment
 *
 * PHP version 5
 *
 * @category  Php-by-contract
 * @package   TechDivision\PBC
 * @author    Bernhard Wick <*****@*****.**>
 * @copyright 2014 TechDivision GmbH - <*****@*****.**>
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 * @link      http://www.techdivision.com/
 */
use TechDivision\PBC\Config;
// Get the vendor dir
$vendorDir = '';
if (realpath(__DIR__ . "/vendor")) {
    $vendorDir = realpath(__DIR__ . "/vendor");
} else {
    throw new Exception('Could not locate vendor dir');
}
// Include the composer autoloader as a fallback
$loader = (require $vendorDir . DIRECTORY_SEPARATOR . 'autoload.php');
$loader->add('TechDivision\\PBC', array(__DIR__ . '/src', __DIR__ . '/tests'));
// Load the test config file
$config = new Config();
$config->load(__DIR__ . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'TechDivision' . DIRECTORY_SEPARATOR . 'PBC' . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'tests.conf.json');
// We have to register our autoLoader to put our proxies in place
$autoLoader = new TechDivision\PBC\AutoLoader($config);
$autoLoader->register();
 /**
  * Will test if a configuration using regexed paths can be used properly
  *
  * @return null
  */
 public function testRegexMapping()
 {
     // We have to load the config for regular expressions in the project dirs
     $config = new Config();
     $config->load(str_replace(DIRECTORY_SEPARATOR . 'Functional', '', __DIR__) . DIRECTORY_SEPARATOR . 'Data' . DIRECTORY_SEPARATOR . 'RegexTest' . DIRECTORY_SEPARATOR . 'regextest.conf.json');
     $e = null;
     try {
         $regexTestClass1 = new RegexTestClass1();
     } catch (Exception $e) {
     }
     // Did we get the right $e?
     $this->assertNull($e);
     $e = null;
     try {
         $regexTestClass2 = new RegexTestClass2();
     } catch (\Exception $e) {
     }
     // Did we get the right $e?
     $this->assertNull($e);
     $e = null;
     try {
         $regexTestClass = new RegexTestClass();
     } catch (\Exception $e) {
     }
     // Did we get the right $e?
     $this->assertNull($e);
 }