Permalink
Browse files

100% test coverage

  • Loading branch information...
1 parent 8790054 commit 7010922da43c9ee40bdb5eec63d9f2576621cefc @pmjones pmjones committed Feb 21, 2013
Showing with 62 additions and 0 deletions.
  1. +62 −0 tests/Aura/Di/FactoryTest.php
@@ -0,0 +1,62 @@
+<?php
+namespace Aura\Di;
+
+/**
+ * Test class for Forge.
+ */
+class FactoryTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Forge
+ */
+ protected $forge;
+
+ protected $config;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->config = new Config;
+ $this->forge = new Forge($this->config);
+ }
+
+ protected function newFactory(
+ $class,
+ array $params = [],
+ array $setter = []
+ ) {
+ return new Factory($this->forge, $class, $params, $setter);
+ }
+
+ public function test__invoke()
+ {
+ $other = $this->forge->newInstance('Aura\Di\MockOtherClass');
+
+ $factory = $this->newFactory(
+ 'Aura\Di\MockChildClass',
+ [
+ 'foo' => 'foofoo',
+ 'zim' => $other,
+ ],
+ [
+ 'setFake' => 'fakefake',
+ ]
+ );
+
+ $actual = $factory();
+
+ $this->assertInstanceOf('Aura\Di\MockChildClass', $actual);
+ $this->assertInstanceOf('Aura\Di\MockOtherClass', $actual->getZim());
+ $this->assertSame('foofoo', $actual->getFoo());
+ $this->assertSame('fakefake', $actual->getFake());
+
+
+ // create another one, should not be the same
+ $extra = $factory();
+ $this->assertNotSame($actual, $extra);
+ }
+}

0 comments on commit 7010922

Please sign in to comment.