Permalink
Browse files

tests were reorganized

  • Loading branch information...
1 parent 69147a1 commit ac12383ace9b6fe62c13274ec95d9e21f79ce9ea @ppadron committed Nov 18, 2009
Showing with 54 additions and 57 deletions.
  1. +33 −0 tests/AugeasGetTest.php
  2. +12 −11 tests/AugeasInsertTest.php
  3. +9 −6 tests/AugeasMatchTest.php
  4. +0 −40 tests/AugeasTest.php
@@ -0,0 +1,33 @@
+<?php
+
+require_once "PHPUnit/Framework/TestCase.php";
+
+class AugeasGetTest extends PHPUnit_Framework_TestCase
+{
+
+ public function setUp()
+ {
+ $this->augeas = new Augeas(dirname(__FILE__) . "/root");
+ }
+
+ public function testShouldReturnStringIfFound()
+ {
+ $this->assertEquals("127.0.0.1", $this->augeas->get("/files/etc/hosts/1/ipaddr"));
+ $this->assertEquals("localhost", $this->augeas->get("/files/etc/hosts/1/canonical"));
+ $this->assertEquals("localhost.localdomain", $this->augeas->get("/files/etc/hosts/1/alias"));
+ }
+
+ public function testShouldReturnNullIfNotFound()
+ {
+ $this->assertEquals(null, $this->augeas->get("/files/etc/hosts/1/non_existent_property"));
+ }
+
+ public function testShouldThrowAugeasExceptionIfPathIsInvalid()
+ {
+ $this->expectedException = "AugeasException";
+ $this->assertEquals(null, $this->augeas->get("OMG TOTALLY INVALID PATH"));
+ }
+
+}
+
+?>
@@ -5,19 +5,22 @@
class AugeasInsertTest extends PHPUnit_Framework_TestCase
{
+ public function setUp()
+ {
+ $this->augeas = new Augeas(dirname(__FILE__) . "/root", dirname(__FILE__) . "/lenses");
+ }
+
public function testShouldBeAbleToInsertNodesBefore()
{
$beforeFirstComment = "comment inserted before the first comment";
$firstComment = "first comment";
- $augeas = new Augeas("root");
-
// inserting before the first comment
- $augeas->insert("/files/etc/hosts/comment[1]", "comment", Augeas::AUGEAS_INSERT_BEFORE);
- $augeas->set("/files/etc/hosts/comment[1]", $beforeFirstComment);
+ $this->augeas->insert("/files/etc/hosts/#comment", "#comment", Augeas::AUGEAS_INSERT_BEFORE);
+ $this->augeas->set("/files/etc/hosts/#comment[1]", $beforeFirstComment);
- $this->assertEquals($beforeFirstComment, $augeas->get("/files/etc/hosts/comment[1]"));
- $this->assertEquals($firstComment, $augeas->get("/files/etc/hosts/comment[2]"));
+ $this->assertEquals($beforeFirstComment, $this->augeas->get("/files/etc/hosts/#comment[1]"));
+ $this->assertEquals($firstComment, $this->augeas->get("/files/etc/hosts/#comment[2]"));
}
@@ -26,13 +29,11 @@ public function testShouldBeAbleToInsertNodesAfter()
$afterFirstComment = "comment inserted after the first comment";
$firstComment = "first comment";
- $augeas = new Augeas("root");
-
// inserting after the NEW first comment
- $augeas->insert("/files/etc/hosts/comment[1]", "comment", Augeas::AUGEAS_INSERT_AFTER);
- $augeas->set("/files/etc/hosts/comment[2]", $afterFirstComment);
+ $this->augeas->insert("/files/etc/hosts/#comment[1]", "#comment", Augeas::AUGEAS_INSERT_AFTER);
+ $this->augeas->set("/files/etc/hosts/#comment[2]", $afterFirstComment);
- $this->assertEquals($afterFirstComment, $augeas->get("/files/etc/hosts/comment[2]"));
+ $this->assertEquals($afterFirstComment, $this->augeas->get("/files/etc/hosts/#comment[2]"));
}
}
@@ -5,23 +5,26 @@
class AugeasMatchTest extends PHPUnit_Framework_TestCase
{
+ public function setUp()
+ {
+ $this->augeas = new Augeas(dirname(__FILE__) . "/root");
+ }
+
public function testShouldReturnEmptyArrayIfNoMatch()
{
- $augeas = new Augeas("root");
- $this->assertEquals(array(), $augeas->match("/files/non_existent_directory"));
+ $this->assertEquals(array(), $this->augeas->match("/files/non_existent_directory"));
}
public function testShoulReturnArrayWithMatches()
{
- $augeas = new Augeas("root");
$expectedArray = array("/files/etc/hosts");
- $this->assertEquals($expectedArray, $augeas->match("/files/etc/*"));
+ $this->assertEquals($expectedArray, $this->augeas->match("/files/etc/*"));
}
public function testShouldThrowExceptionIfPathIsInvalid()
{
- $augeas = new Augeas("root");
- $this->assertEquals(array(), $augeas->match("OMG TOTALLY INVALID PATH"));
+ $this->expectedException = "AugeasException";
+ $this->augeas->match("OMG TOTALLY INVALID PATH");
}
}
View
@@ -13,14 +13,6 @@ public function testShouldSetAugeasRoot()
$this->assertEquals($root, $augeas->get("/augeas/root"));
}
- public function testShouldParseHostsFile()
- {
- $augeas = new Augeas("root");
- $this->assertEquals("127.0.0.1", $augeas->get("/files/etc/hosts/1/ipaddr"));
- $this->assertEquals("localhost", $augeas->get("/files/etc/hosts/1/canonical"));
- $this->assertEquals("localhost.localdomain", $augeas->get("/files/etc/hosts/1/alias"));
- }
-
public function testShouldSetSaveFlags()
{
$augeas = new Augeas("root", "", Augeas::AUGEAS_NONE);
@@ -33,38 +25,6 @@ public function testShouldSetSaveFlags()
$this->assertEquals("backup", $augeas->get("/augeas/save"));
}
- public function testShouldBeAbleToInsertNodesBefore()
- {
- $beforeFirstComment = "comment inserted before the first comment";
- $firstComment = "first comment";
-
- $augeas = new Augeas("root");
-
- // inserting before the first comment
- $augeas->insert("/files/etc/hosts/comment[1]", "comment", Augeas::AUGEAS_INSERT_BEFORE);
- $augeas->set("/files/etc/hosts/comment[1]", $beforeFirstComment);
-
- $this->assertEquals($beforeFirstComment, $augeas->get("/files/etc/hosts/comment[1]"));
- $this->assertEquals($firstComment, $augeas->get("/files/etc/hosts/comment[2]"));
-
- }
-
- public function testShouldBeAbleToInsertNodesAfter()
- {
- $afterFirstComment = "comment inserted after the first comment";
- $firstComment = "first comment";
-
- $augeas = new Augeas("root");
-
- // inserting after the NEW first comment
- $augeas->insert("/files/etc/hosts/comment[1]", "comment", Augeas::AUGEAS_INSERT_AFTER);
- $augeas->set("/files/etc/hosts/comment[2]", $afterFirstComment);
-
- $this->assertEquals($afterFirstComment, $augeas->get("/files/etc/hosts/comment[2]"));
- }
-
-
-
}
?>

0 comments on commit ac12383

Please sign in to comment.