From f8b4c669063b49acd658b1d85194632b57350e68 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 1 Nov 2008 07:55:48 +0000 Subject: Set up unit test framework. Tweak configuration so that it only runs in command line mode, and expects to put data into test/var. Create a module to wrap it that generates a nice text-only view of the output. --- modules/unit_test/tests/Example_Test.php | 103 +++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 modules/unit_test/tests/Example_Test.php (limited to 'modules/unit_test/tests/Example_Test.php') diff --git a/modules/unit_test/tests/Example_Test.php b/modules/unit_test/tests/Example_Test.php new file mode 100644 index 00000000..4abaf0cd --- /dev/null +++ b/modules/unit_test/tests/Example_Test.php @@ -0,0 +1,103 @@ +setup_has_run = TRUE; + } + + public function setup_test() + { + $this->assert_true_strict($this->setup_has_run); + } + + public function true_false_test() + { + $var = TRUE; + $this + ->assert_true($var) + ->assert_true_strict($var) + ->assert_false( ! $var) + ->assert_false_strict( ! $var); + } + + public function equal_same_test() + { + $var = '5'; + $this + ->assert_equal($var, 5) + ->assert_not_equal($var, 6) + ->assert_same($var, '5') + ->assert_not_same($var, 5); + } + + public function type_test() + { + $this + ->assert_boolean(TRUE) + ->assert_not_boolean('TRUE') + ->assert_integer(123) + ->assert_not_integer('123') + ->assert_float(1.23) + ->assert_not_float(123) + ->assert_array(array(1, 2, 3)) + ->assert_not_array('array()') + ->assert_object(new stdClass) + ->assert_not_object('X') + ->assert_null(NULL) + ->assert_not_null(0) + ->assert_empty('0') + ->assert_not_empty('1'); + } + + public function pattern_test() + { + $var = "Kohana\n"; + $this + ->assert_pattern($var, '/^Kohana$/') + ->assert_not_pattern($var, '/^Kohana$/D'); + } + + public function array_key_test() + { + $array = array('a' => 'A', 'b' => 'B'); + $this->assert_array_key('a', $array); + } + + public function in_array_test() + { + $array = array('X', 'Y', 'Z'); + $this->assert_in_array('X', $array); + } + + public function debug_example_test() + { + foreach (array(1, 5, 6, 12, 65, 128, 9562) as $var) + { + // By supplying $var in the debug parameter, + // we can see on which number this test fails. + $this->assert_true($var < 100, $var); + } + } + + public function error_test() + { + throw new Exception; + } + +} -- cgit v1.2.3