From: Jay Smith Date: Mon, 3 Mar 2003 16:44:38 +0000 (+0000) Subject: Added some tests for ZE2 features and their functionality. X-Git-Tag: RELEASE_0_5~643 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=243dd060d116609f763a78e533f399fd7dd30f37;p=php Added some tests for ZE2 features and their functionality. --- diff --git a/tests/classes/__call_001.phpt b/tests/classes/__call_001.phpt new file mode 100644 index 0000000000..e8bcd8d58c --- /dev/null +++ b/tests/classes/__call_001.phpt @@ -0,0 +1,42 @@ +--TEST-- +ZE2 __call() +--SKIPIF-- + +--FILE-- +x; + } +} + +$foo = new Caller(); +$a = $foo->test(1, '2', 3.4, true); +var_dump($a); + +?> +--EXPECT-- +Method test called: +array(4) { + [0]=> + int(1) + [1]=> + string(1) "2" + [2]=> + float(000000002) + [3]=> + bool(true) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} diff --git a/tests/classes/__clone_001.phpt b/tests/classes/__clone_001.phpt new file mode 100644 index 0000000000..fe320df468 --- /dev/null +++ b/tests/classes/__clone_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +ZE2 __clone() +--SKIPIF-- + +--FILE-- +id = self::$id++; + } + + function __clone() { + $this->name = $that->name; + $this->address = "New York"; + $this->id = self::$id++; + } +} + +$original = new MyCloneable(); + +$original->name = "Hello"; +$original->address = "Tel-Aviv"; + +echo $original->id . "\n"; + +$clone = $original->__clone(); + +echo $clone->id . "\n"; +echo $clone->name . "\n"; +echo $clone->address . "\n"; + +?> +--EXPECT-- +0 +1 +Hello +New York diff --git a/tests/classes/__set__get_001.phpt b/tests/classes/__set__get_001.phpt new file mode 100644 index 0000000000..da0391ae4a --- /dev/null +++ b/tests/classes/__set__get_001.phpt @@ -0,0 +1,72 @@ +--TEST-- +ZE2 __set() and __get() +--SKIPIF-- + +--FILE-- + 1, 'b' => 2, 'c' => 3); + + function __get($nm) { + echo "Getting [$nm]\n"; + + if (isset($this->x[$nm])) { + $r = $this->x[$nm]; + echo "Returning: $r\n"; + return $r; + } + else { + echo "Nothing!\n"; + } + } + + function __set($nm, $val) { + echo "Setting [$nm] to $val\n"; + + if (isset($this->x[$nm])) { + $this->x[$nm] = $val; + echo "OK!\n"; + } + else { + echo "Not OK!\n"; + } + } +} + +$foo = new Setter(); + +// this doesn't go through __set()... should it? +$foo->n = 1; + +// the rest are fine... +$foo->a = 100; +$foo->a++; +$foo->z++; +var_dump($foo); + +?> +--EXPECT-- +Setting [a] to 100 +OK! +Getting [a] +Returning: 100 +Setting [a] to 101 +OK! +Getting [z] +Nothing! +Setting [z] to 1 +Not OK! +object(setter)(2) { + ["n"]=> + int(1) + ["x"]=> + array(3) { + ["a"]=> + int(101) + ["b"]=> + int(2) + ["c"]=> + int(3) + } +} diff --git a/tests/classes/constants_scope_001.phpt b/tests/classes/constants_scope_001.phpt new file mode 100644 index 0000000000..5dc874872e --- /dev/null +++ b/tests/classes/constants_scope_001.phpt @@ -0,0 +1,25 @@ +--TEST-- +ZE2 class constants and scope +--SKIPIF-- + +--FILE-- + +--EXPECT-- +FATAL = Fatal error +self::FATAL = Fatal error diff --git a/tests/classes/dereferencing_001.phpt b/tests/classes/dereferencing_001.phpt new file mode 100644 index 0000000000..202602f146 --- /dev/null +++ b/tests/classes/dereferencing_001.phpt @@ -0,0 +1,35 @@ +--TEST-- +ZE2 dereferencing of objects from methods +--SKIPIF-- + +--FILE-- +name = $_name; + } + + function display() { + echo $this->name . "\n"; + } +} + +class Person { + private $name; + + function Person($_name, $_address) { + $this->name = new Name($_name); + } + + function getName() { + return $this->name; + } +} + +$person = new Person("John", "New York"); +$person->getName()->display(); + +?> +--EXPECT-- +John diff --git a/tests/classes/factory_001.phpt b/tests/classes/factory_001.phpt new file mode 100644 index 0000000000..97b69c1b47 --- /dev/null +++ b/tests/classes/factory_001.phpt @@ -0,0 +1,35 @@ +--TEST-- +ZE2 factory objects +--SKIPIF-- + +--FILE-- +draw(); +ShapeFactoryMethod("Square")->draw(); + +?> +--EXPECT-- +Circle +Square diff --git a/tests/classes/object_reference_001.phpt b/tests/classes/object_reference_001.phpt new file mode 100644 index 0000000000..360d19e10b --- /dev/null +++ b/tests/classes/object_reference_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +ZE2 object references +--SKIPIF-- + +--FILE-- +name = "I'm Foo!\n"; + } +} + +$foo = new Foo; +echo $foo->name; +$bar = $foo; +$bar->name = "I'm Bar!\n"; + +// In ZE1, we would expect "I'm Foo!" +echo $foo->name; + +?> +--EXPECT-- +I'm Foo! +I'm Bar! diff --git a/tests/classes/singleton_001.phpt b/tests/classes/singleton_001.phpt new file mode 100644 index 0000000000..ee729b980c --- /dev/null +++ b/tests/classes/singleton_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +ZE2 singleton +--SKIPIF-- + +--FILE-- +counter; + echo "\n"; + } +} + + +class SingletonCounter { + private static $m_instance = NULL; + + static function Instance() { + if (self::$m_instance == NULL) { + self::$m_instance = new Counter(); + } + return self::$m_instance; + } +} + +SingletonCounter::Instance()->increment_and_print(); +SingletonCounter::Instance()->increment_and_print(); +SingletonCounter::Instance()->increment_and_print(); + +?> +--EXPECT-- +1 +2 +3 diff --git a/tests/lang/error_2_exception_001.phpt b/tests/lang/error_2_exception_001.phpt new file mode 100644 index 0000000000..e3d1217f42 --- /dev/null +++ b/tests/lang/error_2_exception_001.phpt @@ -0,0 +1,45 @@ +--TEST-- +ZE2 errors caught as exceptions +--SKIPIF-- + +--FILE-- +errno = $_errno; + $this->errmsg = $_errmsg; + } + + function getErrno() { + return $this->errno; + } + + function getErrmsg() { + return $this->errmsg; + } +} + +function ErrorsToExceptions($errno, $errmsg) { + throw new MyException($errno, $errmsg); +} + +set_error_handler("ErrorsToExceptions"); + +// make sure it isn't catching exceptions that weren't +// thrown... + +try { +} catch (MyException $exception) { + echo "There was an exception: " . $exception->getErrno() . ", '" . $exception->getErrmsg() . "'\n"; +} + +try { + trigger_error("I will become an exception", E_USER_ERROR); +} catch (MyException $exception) { + echo "There was an exception: " . $exception->getErrno() . ", '" . $exception->getErrmsg() . "'\n"; +} + +?> +--EXPECT-- +There was an exception: 256, 'I will become an exception' diff --git a/tests/lang/namespace_001.phpt b/tests/lang/namespace_001.phpt new file mode 100644 index 0000000000..4d42ecf377 --- /dev/null +++ b/tests/lang/namespace_001.phpt @@ -0,0 +1,31 @@ +--TEST-- +ZE2 namespaces +--SKIPIF-- + +--FILE-- + +--EXPECT-- +I'm Foo::SomeFunction()! Foo::$bar is set to: I'm Foo::$bar! +I'm Foo::SomeClass::__construct()! +I'm Foo::$bar!