jay Mon Mar 3 11:44:38 2003 EDT Added files: /php4/tests/classes __call_001.phpt __clone_001.phpt __set__get_001.phpt constants_scope_001.phpt dereferencing_001.phpt factory_001.phpt object_reference_001.phpt singleton_001.phpt /php4/tests/lang error_2_exception_001.phpt namespace_001.phpt Log: Added some tests for ZE2 features and their functionality.
Index: php4/tests/classes/__call_001.phpt +++ php4/tests/classes/__call_001.phpt --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) } Index: php4/tests/classes/__clone_001.phpt +++ php4/tests/classes/__clone_001.phpt --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 Index: php4/tests/classes/__set__get_001.phpt +++ php4/tests/classes/__set__get_001.phpt --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) } } Index: php4/tests/classes/constants_scope_001.phpt +++ php4/tests/classes/constants_scope_001.phpt --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 Index: php4/tests/classes/dereferencing_001.phpt +++ php4/tests/classes/dereferencing_001.phpt --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 Index: php4/tests/classes/factory_001.phpt +++ php4/tests/classes/factory_001.phpt --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 Index: php4/tests/classes/object_reference_001.phpt +++ php4/tests/classes/object_reference_001.phpt --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! Index: php4/tests/classes/singleton_001.phpt +++ php4/tests/classes/singleton_001.phpt --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 Index: php4/tests/lang/error_2_exception_001.phpt +++ php4/tests/lang/error_2_exception_001.phpt --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' Index: php4/tests/lang/namespace_001.phpt +++ php4/tests/lang/namespace_001.phpt --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! -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php