Skip to content
Browse files

Changing JPathwayTest to use fixtures. Moved inspector class to it's …

…own file.
  • Loading branch information...
1 parent 3d21b02 commit a1a33ec42b929d2fd6cf78d6e19eb83363911dc3 @dongilbert committed Nov 8, 2012
Showing with 98 additions and 76 deletions.
  1. +66 −0 tests/suites/legacy/pathway/JPathwayInspector.php
  2. +32 −76 tests/suites/legacy/pathway/JPathwayTest.php
View
66 tests/suites/legacy/pathway/JPathwayInspector.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Pathway
+ *
+ * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+/**
+ * General inspector class for JPathway.
+ *
+ * @package Joomla.UnitTest
+ * @subpackage Pathway
+ *
+ * @since 12.3
+ */
+class JPathwayInspector extends JPathway
+{
+ /**
+ * Method for inspecting protected variables.
+ *
+ * @param string $name The name of the class property.
+ *
+ * @return mixed The value of the class variable.
+ */
+ public function __get($name)
+ {
+ if (property_exists($this, $name))
+ {
+ return $this->$name;
+ }
+ else
+ {
+ trigger_error('Undefined or private property: ' . __CLASS__ . '::' . $name, E_USER_ERROR);
+
+ return null;
+ }
+ }
+
+ /**
+ * Sets any property from the class.
+ *
+ * @param string $property The name of the class property.
+ * @param string $value The value of the class property.
+ *
+ * @return void
+ */
+ public function __set($property, $value)
+ {
+ $this->$property = $value;
+ }
+
+ /**
+ * Calls any inaccessible method from the class.
+ *
+ * @param string $name Name of the method to invoke
+ * @param array $parameters Parameters to be handed over to the original method
+ *
+ * @return mixed The return value of the method
+ */
+ public function __call($name, $parameters = false)
+ {
+ return call_user_func_array(array($this, $name), $parameters);
+ }
+}
View
108 tests/suites/legacy/pathway/JPathwayTest.php
@@ -7,84 +7,51 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/
+require_once __DIR__ . '/JPathwayInspector.php';
+
/**
- * General inspector class for JPathway.
+ * Test class for JPathway.
*
* @package Joomla.UnitTest
* @subpackage Pathway
*
* @since 12.3
*/
-class JPathwayInspector extends JPathway
+class JPathwayTest extends TestCase
{
/**
- * Method for inspecting protected variables.
- *
- * @param string $name The name of the class property.
+ * Set up the tests
*
- * @return mixed The value of the class variable.
+ * @return void
*/
- public function __get($name)
+ protected function setUp()
{
- if (property_exists($this, $name))
- {
- return $this->$name;
- }
- else
- {
- trigger_error('Undefined or private property: ' . __CLASS__ . '::' . $name, E_USER_ERROR);
+ $this->fixture = new JPathwayInspector;
- return null;
- }
+ parent::setUp();
}
/**
- * Sets any property from the class.
- *
- * @param string $property The name of the class property.
- * @param string $value The value of the class property.
+ * Tear down the tests
*
* @return void
*/
- public function __set($property, $value)
+ protected function tearDown()
{
- $this->$property = $value;
- }
+ unset($this->fixture);
- /**
- * Calls any inaccessible method from the class.
- *
- * @param string $name Name of the method to invoke
- * @param array $parameters Parameters to be handed over to the original method
- *
- * @return mixed The return value of the method
- */
- public function __call($name, $parameters = false)
- {
- return call_user_func_array(array($this, $name), $parameters);
+ parent::tearDown();
}
-}
-/**
- * Test class for JPathway.
- *
- * @package Joomla.UnitTest
- * @subpackage Pathway
- *
- * @since 12.3
- */
-class JPathwayTest extends TestCase
-{
/**
* Test JPathway::__construct().
*
* @return void
*/
public function test__construct()
{
- $class = new JPathwayInspector;
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo(array())
);
}
@@ -154,9 +121,8 @@ public function testGetInstance()
*/
public function testGetPathway()
{
- $class = new JPathwayInspector;
- $class->addItem('Item1', 'index.php?key=item1');
- $class->addItem('Item2', 'index.php?key=item2');
+ $this->fixture->addItem('Item1', 'index.php?key=item1');
+ $this->fixture->addItem('Item2', 'index.php?key=item2');
$pathway = array();
$object1 = new stdClass;
@@ -169,7 +135,7 @@ public function testGetPathway()
$pathway[] = $object2;
$this->assertThat(
- $class->getPathway(),
+ $this->fixture->getPathway(),
$this->equalTo($pathway)
);
}
@@ -181,8 +147,6 @@ public function testGetPathway()
*/
public function testSetPathway()
{
- $class = new JPathwayInspector;
-
$pathway = array();
$object1 = new stdClass;
$object1->name = 'Item1';
@@ -194,22 +158,22 @@ public function testSetPathway()
$pathway[4] = $object2;
$this->assertThat(
- $class->setPathway($pathway),
+ $this->fixture->setPathway($pathway),
$this->equalTo(array())
);
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo(array_values($pathway))
);
$this->assertThat(
- $class->setPathway(array()),
+ $this->fixture->setPathway(array()),
$this->equalTo(array_values($pathway))
);
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo(array())
);
}
@@ -221,8 +185,6 @@ public function testSetPathway()
*/
public function testGetPathwayNames()
{
- $class = new JPathwayInspector;
-
$pathway = array();
$object1 = new stdClass;
$object1->name = 'Item1';
@@ -233,10 +195,10 @@ public function testGetPathwayNames()
$object2->link = 'index.php?key=item2';
$pathway[] = $object2;
- $class->_pathway = $pathway;
+ $this->fixture->_pathway = $pathway;
$this->assertThat(
- $class->getPathwayNames(),
+ $this->fixture->getPathwayNames(),
$this->equalTo(array('Item1', 'Item2'))
);
}
@@ -248,8 +210,6 @@ public function testGetPathwayNames()
*/
public function testAddItem()
{
- $class = new JPathwayInspector;
-
$pathway = array();
$object1 = new stdClass;
$object1->name = 'Item1';
@@ -260,11 +220,11 @@ public function testAddItem()
$object2->link = 'index.php?key=item2';
$pathway[] = $object2;
- $class->addItem('Item1', 'index.php?key=item1');
- $class->addItem('Item2', 'index.php?key=item2');
+ $this->fixture->addItem('Item1', 'index.php?key=item1');
+ $this->fixture->addItem('Item2', 'index.php?key=item2');
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo($pathway)
);
}
@@ -276,8 +236,6 @@ public function testAddItem()
*/
public function testSetItemName()
{
- $class = new JPathwayInspector;
-
$pathway = array();
$object1 = new stdClass;
$object1->name = 'Item1';
@@ -288,24 +246,24 @@ public function testSetItemName()
$object2->link = 'index.php?key=item2';
$pathway[] = $object2;
- $class->_pathway = $pathway;
+ $this->fixture->_pathway = $pathway;
$this->assertTrue(
- $class->setItemName(1, 'Item3')
+ $this->fixture->setItemName(1, 'Item3')
);
$pathway[1]->name = 'Item3';
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo($pathway)
);
$this->assertFalse(
- $class->setItemName(3, 'False')
+ $this->fixture->setItemName(3, 'False')
);
$this->assertThat(
- $class->_pathway,
+ $this->fixture->_pathway,
$this->equalTo($pathway)
);
}
@@ -317,14 +275,12 @@ public function testSetItemName()
*/
public function test_makeItem()
{
- $class = new JPathwayInspector;
-
$object = new stdClass;
$object->link = 'index.php?key=value1';
$object->name = 'Value1';
$this->assertThat(
- $class->_makeItem('Value1', 'index.php?key=value1'),
+ $this->fixture->_makeItem('Value1', 'index.php?key=value1'),
$this->equalTo($object)
);
}

0 comments on commit a1a33ec

Please sign in to comment.
Something went wrong with that request. Please try again.