summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2017-09-19 21:50:22 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2017-09-19 21:50:22 +0200
commit2cb636b651c889243919d99eda8fa724d5c08392 (patch)
treec997d1ffbe1e3a0a84db8a0e9e72d39c954f19c4 /tests
parentabb99bf36c6c09f395c49ca34eb49d2ba6ff224d (diff)
Added Container unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Container/ContainerTest.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/Unit/Container/ContainerTest.php b/tests/Unit/Container/ContainerTest.php
new file mode 100644
index 00000000..f0ba24e7
--- /dev/null
+++ b/tests/Unit/Container/ContainerTest.php
@@ -0,0 +1,98 @@
+<?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()
+ {
+ $container0 = new Container();
+ $container = Container::getInstance();
+
+ $this->assertNotSame($container0, $container);
+
+ $container1 = new Container;
+ Container::setInstance($container1);
+
+ $this->assertSame($container1, Container::getInstance());
+ }
+}