Пример #1
0
 /**
  * If the instance stored is neither stdClass nor Closure then throw exception.
  * @expectedExceptionMessage No class found registered with that name: hiThere
  * @expectedException \Exception
  */
 public function testIfTheInstanceStoredIsNeitherStdClassNorClosureThenThrowException()
 {
     $container = Container::getInstance();
     $refObject = new \ReflectionObject($container);
     $refProperty = $refObject->getProperty('registry');
     $refProperty->setAccessible(true);
     $refProperty->setValue($container, array('notHere' => new Resolver(new Builder(''))));
     $container->resolve('hiThere');
 }
Пример #2
0
 /**
  * Will always set the resolver as shared.
  * @depends testWhenCalledWillStoreAResolverInstanceWithTheGivenAliasToTheRegistryListing
  */
 public function testWillAlwaysSetTheResolverAsShared()
 {
     $container = Container::getInstance();
     $container->singleton('cashValidator', function ($numeric) {
         return is_numeric($numeric) && $numeric >= 0;
     });
     $registry = \PHPUnit_Framework_Assert::readAttribute($container, 'registry');
     $markedAsShared = \PHPUnit_Framework_Assert::readAttribute($registry['cashValidator'], 'shared');
     static::assertTrue($markedAsShared);
 }
Пример #3
0
 /**
  * Reset will clear the stored instance.
  * 
  * @dataProvider instanceNameDataProvider
  * @runInSeparateProcess
  */
 public function testResetWillClearTheStoredInstance($instanceName)
 {
     $default = new Container();
     $response = Container::getInstance($instanceName);
     $instances = \PHPUnit_Framework_Assert::readAttribute($response, 'instances');
     if (!isset($instances[$instanceName])) {
         $selectedInstance = $instances['default'];
     } else {
         $selectedInstance = $instances[$instanceName];
     }
     static::assertSame($response, $selectedInstance);
     Container::reset();
     static::assertNull(\PHPUnit_Framework_Assert::readAttribute($default, 'instances'));
 }
Пример #4
0
 /**
  * When called with an existing alias then overwrite the binding.
  */
 public function testWhenCalledWithAnExistingAliasThenOverwriteTheBinding()
 {
     $container = Container::getInstance();
     $object1 = new \stdClass();
     $object1->id = 1;
     $object2 = new \stdClass();
     $object2->id = 2;
     // first
     $container->register('version', $object1);
     // second
     $container->register('usage', function () {
         return PHP_OS;
     });
     // check the soon-to-be previous value
     $registry = \PHPUnit_Framework_Assert::readAttribute($container, 'registry');
     static::assertSame($object1, $registry['version']->execute());
     // overwrite first bind
     $container->register('version', $object2);
     $registry = \PHPUnit_Framework_Assert::readAttribute($container, 'registry');
     static::assertEquals(2, count($registry));
     static::assertSame($object2, $registry['version']->execute());
 }
Пример #5
0
 public function instance($name, $instance)
 {
     return $this->container->instance($name, $instance);
 }
date_default_timezone_set('UTC');
set_time_limit(0);
include_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Input\InputArgument;
use DatabaseInspect\Infrastructure\Services\SchemaService;
use DatabaseInspect\Persistence\Storage\PDOStorage;
use DatabaseInspect\Persistence\DataMappers\SchemaDataMapper;
use DatabaseInspect\Persistence\Gateways\MySQLGateway;
use DatabaseInspect\Persistence\Storage\StorageInterface;
use DatabaseInspect\Persistence\DataMappers\DataMapperInterface;
use DatabaseInspect\Persistence\Gateways\GatewayInterface;
use DatabaseInspect\Persistence\Repositories\SchemaRepository;
use DatabaseInspect\Domain\Mappers\SchemaMapper;
use DatabaseInspect\Domain\Mappers\MapperInterface;
use DatabaseInspect\Domain\Models\CredentialsInterface;
$container = \IoC\Container::getInstance('default');
$container->register('Persistence\\Storage\\PDO', function (CredentialsInterface $credentials) {
    $dsn = 'mysql:host=' . $credentials->getHost() . ';dbname=' . $credentials->getDatabase();
    $pdo = new \PDO($dsn, $credentials->getUsername(), $credentials->getPassword());
    $storage = new PDOStorage($pdo);
    return $storage;
});
$container->register('Persistence\\Gateway\\Schema\\MySQL', function (StorageInterface $storage) use($container) {
    /** @var DataMapperInterface $dataMapper */
    $dataMapper = $container->resolve('Persistence\\DataMapper\\Schema');
    $gateway = new MySQLGateway($storage, $dataMapper);
    return $gateway;
});
$container->register('Persistence\\DataMapper\\Schema', function () {
    $dataMapper = new SchemaDataMapper();
    return $dataMapper;
Пример #7
0
 public function testCallWithAtSignBasedClassReferences()
 {
     $container = new Container();
     $result = $container->call('ContainerTestCall:work', ['foo', 'bar']);
     $this->assertEquals(['foo', 'bar'], $result);
     $container = new Container();
     $result = $container->call('ContainerTestCall:inject');
     $this->assertInstanceOf('ContainerSomeClass', $result[0]);
     $this->assertEquals('jack', $result[1]);
 }
Пример #8
0
 /**
  * When a handle name is not registered then return false.
  */
 public function testWhenAHandleNameIsNotRegisteredThenReturnFalse()
 {
     $container = Container::getInstance();
     static::assertFalse($container->registered('missingComponentRegistered'));
 }
Пример #9
0
 /**
  * Returns the same instance of Container every time it is called.
  * 
  * @dataProvider instanceNameDataProvider
  */
 public function testReturnsTheSameInstanceOfContainerEveryTimeItIsCalled($instanceName)
 {
     $response1 = Container::getInstance($instanceName);
     $response2 = Container::getInstance($instanceName);
     static::assertSame($response1, $response2);
 }
 /**
  * @param $gateway
  * @param $mapper
  *
  * @return SchemaService
  */
 protected function getSchemaService($gateway, $mapper)
 {
     return $this->container->resolve('Infrastructure\\Services\\Schema', [$gateway, $mapper]);
 }