Browse Source

Test the new features in ObjectRegistry.

Robert Pustułka 9 years ago
parent
commit
a5dfca683b
1 changed files with 65 additions and 1 deletions
  1. 65 1
      tests/TestCase/Controller/ComponentRegistryTest.php

+ 65 - 1
tests/TestCase/Controller/ComponentRegistryTest.php

@@ -209,6 +209,22 @@ class ComponentRegistryTest extends TestCase
     }
 
     /**
+     * Test __unset.
+     *
+     * @return void
+     */
+    public function testUset()
+    {
+        $eventManager = $this->Components->getController()->getEventManager();
+
+        $result = $this->Components->load('Auth');
+        unset($this->Components->Auth);
+
+        $this->assertFalse(isset($this->Components->Auth), 'Should be gone');
+        $this->assertCount(0, $eventManager->listeners('Controller.startup'));
+    }
+
+    /**
      * Test that unloading a none existing component triggers an error.
      *
      * @expectedException \Cake\Controller\Exception\MissingComponentException
@@ -231,9 +247,57 @@ class ComponentRegistryTest extends TestCase
         $this->assertCount(0, $eventManager->listeners('Controller.startup'));
 
         $auth = new AuthComponent($this->Components);
-        $this->Components->set('Auth', $auth);
+        $result = $this->Components->set('Auth', $auth);
+
+        $this->assertSame($this->Components, $result);
+        $this->assertTrue(isset($this->Components->Auth), 'Should be gone');
+        $this->assertCount(1, $eventManager->listeners('Controller.startup'));
+    }
+
+    /**
+     * Test __set.
+     *
+     * @return void
+     */
+    public function testMagicSet()
+    {
+        $eventManager = $this->Components->getController()->getEventManager();
+        $this->assertCount(0, $eventManager->listeners('Controller.startup'));
+
+        $auth = new AuthComponent($this->Components);
+        $this->Components->Auth = $auth;
 
         $this->assertTrue(isset($this->Components->Auth), 'Should be gone');
         $this->assertCount(1, $eventManager->listeners('Controller.startup'));
     }
+
+    /**
+     * Test Countable.
+     *
+     * @return void
+     */
+    public function testCountable()
+    {
+        $this->Components->load('Auth');
+        $this->assertInstanceOf('\Countable', $this->Components);
+        $count = count($this->Components);
+        $this->assertEquals(1, $count);
+    }
+
+    /**
+     * Test Traversable.
+     *
+     * @return void
+     */
+    public function testTraversable()
+    {
+        $this->Components->load('Auth');
+        $this->assertInstanceOf('\Traversable', $this->Components);
+
+        $result = null;
+        foreach ($this->Components as $component) {
+            $result = $component;
+        }
+        $this->assertNotNull($result);
+    }
 }