Skip to content

Commit

Permalink
Test the new features in ObjectRegistry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Pustułka committed May 9, 2017
1 parent cbe805e commit a5dfca6
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion tests/TestCase/Controller/ComponentRegistryTest.php
Expand Up @@ -208,6 +208,22 @@ public function testUnload()
$this->assertCount(0, $eventManager->listeners('Controller.startup'));
}

/**
* 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.
*
Expand All @@ -231,9 +247,57 @@ public function testSet()
$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);
}
}

0 comments on commit a5dfca6

Please sign in to comment.