1
0
mirror of https://github.com/danog/dns.git synced 2024-12-12 09:29:46 +01:00
dns/test/testBootstrap.php
Danack a50369e71e Tests, Travis and Cache implementations
- Add tests
 - Configure repo for use with Travis
 - Add some more Cache implementations
2014-07-21 12:24:35 +01:00

92 lines
2.4 KiB
PHP

<?php
use Auryn\Provider;
error_reporting(E_ALL);
$autoloader = require __DIR__.'/../vendor/autoload.php';
$autoloader->add('AddrTest', [realpath(__DIR__)."/"]);
function createProvider($implementations = array(), $shareClasses = array()) {
$provider = new Provider();
$standardImplementations = [
];
$standardShares = [
];
$redisParameters = array(
'connection_timeout' => 2,
'read_write_timeout' => 2,
);
$provider->define(
'Predis\Client',
array(
':parameters' => $redisParameters,
':options' => [],
)
);
$provider->share('Predis\Client');
setImplementations($provider, $standardImplementations, $implementations);
setShares($provider, $standardShares, $shareClasses);
$provider->share($provider); //YOLO
return $provider;
}
function setImplementations(Provider $provider, $standardImplementations, $implementations) {
foreach ($standardImplementations as $interface => $implementation) {
if (array_key_exists($interface, $implementations)) {
if (is_object($implementations[$interface]) == true) {
$provider->alias($interface, get_class($implementations[$interface]));
$provider->share($implementations[$interface]);
}
else {
$provider->alias($interface, $implementations[$interface]);
}
unset($implementations[$interface]);
}
else {
if (is_object($implementation)) {
$implementation = get_class($implementation);
}
$provider->alias($interface, $implementation);
}
}
foreach ($implementations as $class => $implementation) {
if (is_object($implementation) == true) {
$provider->alias($class, get_class($implementation));
$provider->share($implementation);
}
else {
$provider->alias($class, $implementation);
}
}
}
function setShares(Provider $provider, $standardShares, $shareClasses) {
foreach ($standardShares as $class => $share) {
if (array_key_exists($class, $shareClasses)) {
$provider->share($shareClasses[$class]);
unset($shareClasses[$class]);
}
else {
$provider->share($share);
}
}
foreach ($shareClasses as $class => $share) {
$provider->share($share);
}
}