]> granicus.if.org Git - php/commitdiff
- New tests
authorFelipe Pena <felipe@php.net>
Mon, 12 May 2008 13:30:50 +0000 (13:30 +0000)
committerFelipe Pena <felipe@php.net>
Mon, 12 May 2008 13:30:50 +0000 (13:30 +0000)
Zend/tests/class_alias_001.phpt [new file with mode: 0644]
Zend/tests/class_alias_002.phpt [new file with mode: 0644]
Zend/tests/class_alias_003.phpt [new file with mode: 0644]
Zend/tests/class_alias_004.phpt [new file with mode: 0644]
Zend/tests/class_alias_005.phpt [new file with mode: 0644]
Zend/tests/class_alias_006.phpt [new file with mode: 0644]
Zend/tests/class_alias_007.phpt [new file with mode: 0644]
Zend/tests/class_alias_008.phpt [new file with mode: 0644]
Zend/tests/class_alias_009.phpt [new file with mode: 0644]
Zend/tests/class_alias_010.phpt [new file with mode: 0644]

diff --git a/Zend/tests/class_alias_001.phpt b/Zend/tests/class_alias_001.phpt
new file mode 100644 (file)
index 0000000..371f08f
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Testing class_alias()
+--FILE--
+<?php
+
+class foo { }
+
+class_alias('foo', 'bar');
+
+$a = new foo;
+$b = new bar;
+
+var_dump($a == $b, $a === $b);
+var_dump($a instanceof $b);
+
+var_dump($a instanceof foo);
+var_dump($a instanceof bar);
+
+var_dump($b instanceof foo);
+var_dump($b instanceof bar);
+
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
diff --git a/Zend/tests/class_alias_002.phpt b/Zend/tests/class_alias_002.phpt
new file mode 100644 (file)
index 0000000..9601cb2
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Trying redeclare class with class_alias()
+--FILE--
+<?php
+
+class foo { }
+
+class_alias('foo', 'FOO');
+
+?>
+--EXPECTF--
+Warning: Cannot redeclare class FOO in %s on line %d
diff --git a/Zend/tests/class_alias_003.phpt b/Zend/tests/class_alias_003.phpt
new file mode 100644 (file)
index 0000000..57e2fd5
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Testing declaration of alias to 'static'
+--FILE--
+<?php
+
+class bar {
+}
+
+class foo { 
+       public function test() {
+               class_alias('bar', 'static');
+               return new static;
+       }
+}
+
+$a = new foo;
+var_dump($a->test());
+
+?>
+--EXPECTF--
+object(foo)#%d (0) {
+}
diff --git a/Zend/tests/class_alias_004.phpt b/Zend/tests/class_alias_004.phpt
new file mode 100644 (file)
index 0000000..b7dbabd
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Testing creation of alias using an existing interface name
+--FILE--
+<?php
+
+class foo { }
+
+interface test { }
+
+
+class_alias('foo', 'test');
+
+?>
+--EXPECTF--
+Warning: Cannot redeclare class test in %s on line %d
diff --git a/Zend/tests/class_alias_005.phpt b/Zend/tests/class_alias_005.phpt
new file mode 100644 (file)
index 0000000..47c825b
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Testing static call method using the original class name
+--FILE--
+<?php
+
+class foo { 
+       static public function msg() {
+               print "hello\n";
+       }
+}
+
+interface test { }
+
+
+class_alias('foo', 'baz');
+
+class bar extends baz { 
+       public function __construct() {
+               foo::msg();
+       }       
+}
+
+new bar;
+
+?>
+--EXPECT--
+hello
diff --git a/Zend/tests/class_alias_006.phpt b/Zend/tests/class_alias_006.phpt
new file mode 100644 (file)
index 0000000..d14ad7c
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Testing creation of alias to an internal class
+--FILE--
+<?php
+
+class_alias('stdclass', 'foo');
+
+?>
+--EXPECTF--
+Warning: First argument of class_alias() must be a name of user defined class in %s on line %d
diff --git a/Zend/tests/class_alias_007.phpt b/Zend/tests/class_alias_007.phpt
new file mode 100644 (file)
index 0000000..247398e
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Testing class_alias() using autoload
+--FILE--
+<?php
+
+function __autoload($a) {
+       class foo { }
+}
+
+class_alias('foo', 'bar', 1);
+
+var_dump(new foo, new bar);
+
+?>
+--EXPECTF--
+object(foo)#%d (0) {
+}
+object(foo)#%d (0) {
+}
diff --git a/Zend/tests/class_alias_008.phpt b/Zend/tests/class_alias_008.phpt
new file mode 100644 (file)
index 0000000..8ee8fa0
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Testing class_alias() with abstract class using an arbitrary class name as alias
+--FILE--
+<?php
+
+abstract class foo { }
+
+class_alias('foo', "\0");
+
+$a = "\0";
+
+new $a;
+
+?>
+--EXPECTF--
+Fatal error: Cannot instantiate abstract class foo in %s on line %d
diff --git a/Zend/tests/class_alias_009.phpt b/Zend/tests/class_alias_009.phpt
new file mode 100644 (file)
index 0000000..f17769e
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Testing interface declaration using the original and alias class name
+--FILE--
+<?php
+
+interface a { }
+
+class_alias('a', 'b');
+
+interface c extends a, b { }
+
+?>
+--EXPECTF--
+Fatal error: Class c cannot implement previously implemented interface a in %s on line %d
diff --git a/Zend/tests/class_alias_010.phpt b/Zend/tests/class_alias_010.phpt
new file mode 100644 (file)
index 0000000..38590b6
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Trying use an existing alias name in class declaration
+--FILE--
+<?php
+
+interface a { }
+
+class_alias('a', 'b');
+
+class b { }
+
+?>
+--EXPECTF--
+Warning: Cannot redeclare class b in %s on line %d