diff options
author | Jay Smith <jay@php.net> | 2003-03-03 16:44:38 +0000 |
---|---|---|
committer | Jay Smith <jay@php.net> | 2003-03-03 16:44:38 +0000 |
commit | 243dd060d116609f763a78e533f399fd7dd30f37 (patch) | |
tree | 65d1cfb443aa455d4a5b9a6b9b34f0d7da9fbb33 | |
parent | cc52373c1002b9e99d590c7bba89ceadb15cc32c (diff) | |
download | php-git-243dd060d116609f763a78e533f399fd7dd30f37.tar.gz |
Added some tests for ZE2 features and their functionality.
-rw-r--r-- | tests/classes/__call_001.phpt | 42 | ||||
-rw-r--r-- | tests/classes/__clone_001.phpt | 40 | ||||
-rw-r--r-- | tests/classes/__set__get_001.phpt | 72 | ||||
-rw-r--r-- | tests/classes/constants_scope_001.phpt | 25 | ||||
-rw-r--r-- | tests/classes/dereferencing_001.phpt | 35 | ||||
-rw-r--r-- | tests/classes/factory_001.phpt | 35 | ||||
-rw-r--r-- | tests/classes/object_reference_001.phpt | 27 | ||||
-rw-r--r-- | tests/classes/singleton_001.phpt | 37 | ||||
-rw-r--r-- | tests/lang/error_2_exception_001.phpt | 45 | ||||
-rw-r--r-- | tests/lang/namespace_001.phpt | 31 |
10 files changed, 389 insertions, 0 deletions
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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Caller { + var $x = array(1, 2, 3); + + function __call($m, $a) { + echo "Method $m called:\n"; + var_dump($a); + return $this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class MyCloneable { + static $id = 0; + + function MyCloneable() { + $this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php +class Setter { + public $n; + public $x = array('a' => 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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class ErrorCodes { + const FATAL = "Fatal error\n"; + const WARNING = "Warning\n"; + const INFO = "Informational message\n"; + + static function print_fatal_error_codes() { + echo "FATAL = " . FATAL; + echo "self::FATAL = " . self::FATAL; + } +} + +/* Call the static function and move into the ErrorCodes scope */ +ErrorCodes::print_fatal_error_codes(); + +?> +--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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Name { + function Name($_name) { + $this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Circle { + function draw() { + echo "Circle\n"; + } +} + +class Square { + function draw() { + print "Square\n"; + } +} + +function ShapeFactoryMethod($shape) { + switch ($shape) { + case "Circle": + return new Circle(); + case "Square": + return new Square(); + } +} + +ShapeFactoryMethod("Circle")->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Foo { + var $name; + + function Foo() { + $this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class Counter { + private $counter = 0; + + function increment_and_print() { + echo ++$this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +class MyException { + function MyException($_errno, $_errmsg) { + $this->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-- +<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?> +--FILE-- +<?php + +namespace Foo { + var $bar; + + function SomeFunction() { + echo "I'm Foo::SomeFunction()! Foo::\$bar is set to: " . Foo::$bar; + } + + class SomeClass { + function __construct() { + echo "I'm Foo::SomeClass::__construct()!\n"; + echo Foo::$bar; + } + } +} + +Foo::$bar = "I'm Foo::\$bar!\n"; +Foo::SomeFunction(); +$someClass = new Foo::SomeClass; + +?> +--EXPECT-- +I'm Foo::SomeFunction()! Foo::$bar is set to: I'm Foo::$bar! +I'm Foo::SomeClass::__construct()! +I'm Foo::$bar! |