Changed Container to Illuminate/Container
@see https://laravel.com/docs/5.5/container @see https://davejamesmiller.com/2017/06/15/laravel-illuminate-container-in-depthmain
parent
945fcb079a
commit
212760d4c9
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Engelsystem\Container;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
|
||||||
|
|
||||||
class ContainerException extends Exception implements ContainerExceptionInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Engelsystem\Container;
|
|
||||||
|
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
|
||||||
|
|
||||||
class NotFoundException extends ContainerException implements NotFoundExceptionInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Engelsystem\Test\Config;
|
|
||||||
|
|
||||||
use Engelsystem\Container\Container;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class ContainerTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::get
|
|
||||||
*/
|
|
||||||
public function testGet()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$class = new class
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
$container->instance('foo', $class);
|
|
||||||
$this->assertSame($class, $container->get('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::get
|
|
||||||
* @expectedException \Engelsystem\Container\NotFoundException
|
|
||||||
*/
|
|
||||||
public function testGetException()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
|
|
||||||
$container->get('not.registered.service');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::instance
|
|
||||||
* @covers \Engelsystem\Container\Container::resolve
|
|
||||||
*/
|
|
||||||
public function testInstance()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$class = new class
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
$container->instance('foo', $class);
|
|
||||||
$this->assertSame($class, $container->get('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::has
|
|
||||||
*/
|
|
||||||
public function testHas()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
|
|
||||||
$this->assertFalse($container->has('test'));
|
|
||||||
|
|
||||||
$class = new class
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
$container->instance('test', $class);
|
|
||||||
$this->assertTrue($container->has('test'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::singleton
|
|
||||||
*/
|
|
||||||
public function testSingleton()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$class = new class
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
$container->singleton('foo', $class);
|
|
||||||
$this->assertSame($class, $container->get('foo'));
|
|
||||||
$this->assertSame($class, $container->get('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Engelsystem\Container\Container::setInstance
|
|
||||||
* @covers \Engelsystem\Container\Container::getInstance
|
|
||||||
*/
|
|
||||||
public function testContainerSingleton()
|
|
||||||
{
|
|
||||||
// Ensure that no container has been initialized
|
|
||||||
$reflection = new \ReflectionProperty(Container::class, 'instance');
|
|
||||||
$reflection->setAccessible(true);
|
|
||||||
$reflection->setValue(null, null);
|
|
||||||
$reflection->setAccessible(false);
|
|
||||||
|
|
||||||
$container0 = new Container();
|
|
||||||
$container = Container::getInstance();
|
|
||||||
|
|
||||||
$this->assertNotSame($container0, $container);
|
|
||||||
|
|
||||||
$container1 = new Container;
|
|
||||||
Container::setInstance($container1);
|
|
||||||
|
|
||||||
$this->assertSame($container1, Container::getInstance());
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue