]> granicus.if.org Git - php/commitdiff
- New tests
authorFelipe Pena <felipe@php.net>
Mon, 12 May 2008 17:57:21 +0000 (17:57 +0000)
committerFelipe Pena <felipe@php.net>
Mon, 12 May 2008 17:57:21 +0000 (17:57 +0000)
25 files changed:
Zend/tests/035.phpt [new file with mode: 0644]
Zend/tests/class_alias_021.phpt [new file with mode: 0644]
Zend/tests/class_exists_001.phpt [new file with mode: 0644]
Zend/tests/class_exists_002.phpt [new file with mode: 0644]
Zend/tests/class_exists_003.phpt [new file with mode: 0644]
Zend/tests/constants_001.phpt [new file with mode: 0644]
Zend/tests/constants_002.phpt [new file with mode: 0644]
Zend/tests/constants_003.phpt [new file with mode: 0644]
Zend/tests/constants_004.phpt [new file with mode: 0644]
Zend/tests/each_001.phpt [new file with mode: 0644]
Zend/tests/each_002.phpt [new file with mode: 0644]
Zend/tests/each_003.phpt [new file with mode: 0644]
Zend/tests/exception_005.phpt [new file with mode: 0644]
Zend/tests/exception_006.phpt [new file with mode: 0644]
Zend/tests/get_called_class_001.phpt [new file with mode: 0644]
Zend/tests/get_parent_class_001.phpt [new file with mode: 0644]
Zend/tests/heredoc_018.phpt [new file with mode: 0644]
Zend/tests/inter_05.phpt [new file with mode: 0644]
Zend/tests/inter_06.phpt [new file with mode: 0644]
Zend/tests/interface_exists_001.phpt [new file with mode: 0644]
Zend/tests/interface_exists_002.phpt [new file with mode: 0644]
Zend/tests/list_006.phpt [new file with mode: 0644]
Zend/tests/objects_028.phpt [new file with mode: 0644]
Zend/tests/objects_029.phpt [new file with mode: 0644]
Zend/tests/objects_030.phpt [new file with mode: 0644]

diff --git a/Zend/tests/035.phpt b/Zend/tests/035.phpt
new file mode 100644 (file)
index 0000000..75df786
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Using 'static' and 'global' in global scope
+--FILE--
+<?php
+
+static $var, $var, $var = -1;
+var_dump($var);
+
+global $var, $var, $var;
+var_dump($var);
+
+var_dump($GLOBALS['var']);
+
+?>
+--EXPECT--
+int(-1)
+int(-1)
+int(-1)
diff --git a/Zend/tests/class_alias_021.phpt b/Zend/tests/class_alias_021.phpt
new file mode 100644 (file)
index 0000000..7904962
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Overriding internal class with class alias
+--FILE--
+<?php
+
+namespace foo;
+
+class bar { }
+
+class_alias('foo::bar', 'baz');
+
+use ::baz as stdClass;
+
+var_dump(new foo::bar);
+var_dump(new stdClass);
+var_dump(new ::baz);
+
+?>
+--EXPECTF--
+object(foo::bar)#%d (0) {
+}
+object(foo::bar)#%d (0) {
+}
+object(foo::bar)#%d (0) {
+}
diff --git a/Zend/tests/class_exists_001.phpt b/Zend/tests/class_exists_001.phpt
new file mode 100644 (file)
index 0000000..4ee1ee2
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Testing class_exists() inside namespace
+--FILE--
+<?php
+
+namespace foo;
+
+class foo {
+       
+}
+
+class_alias(__NAMESPACE__ .'::foo', 'bar');
+
+
+var_dump(class_exists('::bar'));
+var_dump(class_exists('bar'));
+var_dump(class_exists('foo::bar'));
+var_dump(class_exists('foo::foo'));
+var_dump(class_exists('foo'));
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
diff --git a/Zend/tests/class_exists_002.phpt b/Zend/tests/class_exists_002.phpt
new file mode 100644 (file)
index 0000000..d326f06
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Testing several valid and invalid parameters
+--FILE--
+<?php
+
+class foo {
+       
+}
+
+var_dump(class_exists(''));
+var_dump(class_exists(NULL));
+var_dump(class_exists('FOO'));
+var_dump(class_exists('bar'));
+var_dump(class_exists(1));
+var_dump(class_exists(new stdClass));
+
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+
+Warning: class_exists() expects parameter 1 to be string, object given in %s on line %d
+NULL
diff --git a/Zend/tests/class_exists_003.phpt b/Zend/tests/class_exists_003.phpt
new file mode 100644 (file)
index 0000000..ad7bafa
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Checking if exists interface, abstract and final class
+--FILE--
+<?php
+
+interface a { }
+
+abstract class b { }
+
+final class c { }
+
+var_dump(class_exists('a'));
+var_dump(class_exists('b'));
+var_dump(class_exists('c'));
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(true)
diff --git a/Zend/tests/constants_001.phpt b/Zend/tests/constants_001.phpt
new file mode 100644 (file)
index 0000000..8419eb6
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Defining and using constants
+--FILE--
+<?php
+
+define('foo',  2);
+define('1',    2);
+define(1,              2);
+define('',             1);
+define('1foo', 3);
+
+var_dump(constant('foo'));
+var_dump(constant('1'));
+var_dump(constant(1));
+var_dump(constant(''));
+var_dump(constant('1foo'));
+
+?>
+--EXPECTF--
+Notice: Constant 1 already defined in %s on line %d
+int(2)
+int(2)
+int(2)
+int(1)
+int(3)
diff --git a/Zend/tests/constants_002.phpt b/Zend/tests/constants_002.phpt
new file mode 100644 (file)
index 0000000..2e769f5
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Defining constants with non-scalar values
+--FILE--
+<?php
+
+define('foo', new stdClass);
+var_dump(foo);
+
+define('foo', fopen(__FILE__, 'r'));
+var_dump(foo);
+
+?>
+--EXPECTF--
+Warning: Constants may only evaluate to scalar values in %s on line %d
+
+Notice: Use of undefined constant foo - assumed 'foo' in %s on line %d
+string(%d) "foo"
+resource(%d) of type (stream)
+--UEXPECTF--
+Warning: Constants may only evaluate to scalar values in %s on line %d
+
+Notice: Use of undefined constant foo - assumed 'foo' in %s on line %d
+unicode(%d) "foo"
+resource(%d) of type (stream)
diff --git a/Zend/tests/constants_003.phpt b/Zend/tests/constants_003.phpt
new file mode 100644 (file)
index 0000000..ec3eb6d
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Using namespace constants and constants of global scope
+--FILE--
+<?php
+
+namespace foo;
+
+const foo = 1;
+
+define('foo', 2);
+
+var_dump(foo, namespace::foo, foo::foo, ::foo, constant('foo'), constant('foo::foo'));
+
+?>
+--EXPECT--
+int(1)
+int(1)
+int(1)
+int(2)
+int(2)
+int(1)
diff --git a/Zend/tests/constants_004.phpt b/Zend/tests/constants_004.phpt
new file mode 100644 (file)
index 0000000..787ec26
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Trying to redeclare constant inside namespace
+--FILE--
+<?php
+
+namespace foo;
+
+const foo = 1;
+const foo = 2;
+
+?>
+--EXPECTF--
+Notice: Constant foo::foo already defined in %s on line %d
diff --git a/Zend/tests/each_001.phpt b/Zend/tests/each_001.phpt
new file mode 100644 (file)
index 0000000..06ab52a
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Testing each() with an undefined variable
+--FILE--
+<?php
+
+each($foo);
+
+?>
+--EXPECTF--
+Warning: Variable passed to each() is not an array or object in %s on line %d
diff --git a/Zend/tests/each_002.phpt b/Zend/tests/each_002.phpt
new file mode 100644 (file)
index 0000000..59ff7a7
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+Testing each() with array and object
+--FILE--
+<?php
+
+$foo = each(new stdClass);
+var_dump($foo);
+
+var_dump(each(new stdClass));
+
+$a = array(new stdClass);
+var_dump(each($a));
+
+
+?>
+--EXPECTF--
+bool(false)
+bool(false)
+array(4) {
+  [1]=>
+  object(stdClass)#1 (0) {
+  }
+  ["value"]=>
+  object(stdClass)#1 (0) {
+  }
+  [0]=>
+  int(0)
+  ["key"]=>
+  int(0)
+}
+--UEXPECTF--
+bool(false)
+bool(false)
+array(4) {
+  [1]=>
+  object(stdClass)#1 (0) {
+  }
+  [u"value"]=>
+  object(stdClass)#1 (0) {
+  }
+  [0]=>
+  int(0)
+  [u"key"]=>
+  int(0)
+}
diff --git a/Zend/tests/each_003.phpt b/Zend/tests/each_003.phpt
new file mode 100644 (file)
index 0000000..8c0c32a
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+Testing each() with recursion
+--FILE--
+<?php
+
+$a = array(array());
+$a[] =& $a;
+
+var_dump(each($a[1]));
+
+?>
+--EXPECTF--
+array(4) {
+  [1]=>
+  array(0) {
+  }
+  ["value"]=>
+  array(0) {
+  }
+  [0]=>
+  int(0)
+  ["key"]=>
+  int(0)
+}
+--UEXPECTF--
+array(4) {
+  [1]=>
+  array(0) {
+  }
+  [u"value"]=>
+  array(0) {
+  }
+  [0]=>
+  int(0)
+  [u"key"]=>
+  int(0)
+}
diff --git a/Zend/tests/exception_005.phpt b/Zend/tests/exception_005.phpt
new file mode 100644 (file)
index 0000000..45a9269
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Trying to throw exception of an interface
+--FILE--
+<?php
+
+interface a { }
+
+throw new a();
+
+?>
+--EXPECTF--
+Fatal error: Cannot instantiate interface a in %s on line %d
diff --git a/Zend/tests/exception_006.phpt b/Zend/tests/exception_006.phpt
new file mode 100644 (file)
index 0000000..5c981fc
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Trying to throw a non-object
+--FILE--
+<?php
+
+throw 1;
+
+?>
+--EXPECTF--
+Fatal error: Can only throw objects in %s on line %d
diff --git a/Zend/tests/get_called_class_001.phpt b/Zend/tests/get_called_class_001.phpt
new file mode 100644 (file)
index 0000000..7012ae8
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Calling get_called_class() outside a class
+--FILE--
+<?php
+
+var_dump(get_called_class());
+
+?>
+--EXPECTF--
+Warning: get_called_class() called from outside a class in %s on line %d
+bool(false)
diff --git a/Zend/tests/get_parent_class_001.phpt b/Zend/tests/get_parent_class_001.phpt
new file mode 100644 (file)
index 0000000..5115fe1
--- /dev/null
@@ -0,0 +1,31 @@
+--TEST--
+Testing get_parent_class()
+--FILE--
+<?php
+
+interface ITest {
+       function foo(); 
+}
+
+abstract class bar implements ITest {
+       public function foo() {
+               var_dump(get_parent_class());
+       }
+}
+
+class foo extends bar {
+       public function __construct() {
+               var_dump(get_parent_class());
+       }
+}
+
+$a = new foo;
+$a->foo();
+
+?>
+--EXPECT--
+string(3) "bar"
+bool(false)
+--UEXPECT--
+unicode(3) "bar"
+bool(false)
diff --git a/Zend/tests/heredoc_018.phpt b/Zend/tests/heredoc_018.phpt
new file mode 100644 (file)
index 0000000..c10e9c1
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Testing heredoc with tabs before identifier
+--FILE--
+<?php
+
+$heredoc = <<< A
+
+foo
+
+       A;
+A;
+
+var_dump(strlen($heredoc) == 9);
+
+?>
+--EXPECT--
+bool(true)
diff --git a/Zend/tests/inter_05.phpt b/Zend/tests/inter_05.phpt
new file mode 100644 (file)
index 0000000..7d5d13e
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Trying to inherit a class in an interface
+--FILE--
+<?php
+
+interface a extends Exception { }
+
+?>
+--EXPECTF--
+Fatal error: a cannot implement Exception - it is not an interface in %s on line %d
diff --git a/Zend/tests/inter_06.phpt b/Zend/tests/inter_06.phpt
new file mode 100644 (file)
index 0000000..1987c24
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Trying use name of an internal class as interface name
+--FILE--
+<?php
+
+interface stdClass { }
+
+?>
+--EXPECTF--
+Fatal error: Cannot redeclare class stdClass in %s on line %d
diff --git a/Zend/tests/interface_exists_001.phpt b/Zend/tests/interface_exists_001.phpt
new file mode 100644 (file)
index 0000000..ab20dd2
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+Testing interface_exists()
+--FILE--
+<?php
+
+interface foo {
+}
+
+var_dump(interface_exists('foo'));
+var_dump(interface_exists(1));
+var_dump(interface_exists(NULL));
+var_dump(interface_exists(new stdClass));
+
+?>
+--EXPECTF--
+bool(true)
+bool(false)
+bool(false)
+
+Warning: interface_exists() expects parameter 1 to be string, object given in %s on line %d
+NULL
diff --git a/Zend/tests/interface_exists_002.phpt b/Zend/tests/interface_exists_002.phpt
new file mode 100644 (file)
index 0000000..f4d8a03
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Testing interface_exists() inside a namespace
+--FILE--
+<?php
+
+namespace foo;
+
+interface IFoo { }
+
+interface ITest extends IFoo { }
+
+interface IBar extends IFoo { }
+
+
+var_dump(interface_exists('IFoo'));
+var_dump(interface_exists('foo::IFoo'));
+var_dump(interface_exists('FOO::ITEST'));
+
+?>
+--EXPECT--
+bool(false)
+bool(true)
+bool(true)
diff --git a/Zend/tests/list_006.phpt b/Zend/tests/list_006.phpt
new file mode 100644 (file)
index 0000000..f5f5970
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Testing nested list() with empty array
+--FILE--
+<?php
+
+list($a, list($b, list(list($d)))) = array();
+
+?>
+--EXPECTF--
+Notice: Undefined offset: 1 in %s on line %d
+
+Notice: Undefined offset: 1 in %s on line %d
+
+Notice: Undefined offset: 0 in %s on line %d
diff --git a/Zend/tests/objects_028.phpt b/Zend/tests/objects_028.phpt
new file mode 100644 (file)
index 0000000..5c76612
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Testing 'static::' and 'parent::' in calls
+--FILE--
+<?php
+
+class bar {
+       public function __call($a, $b) {
+               print "hello\n";
+       }
+}
+
+class foo extends bar {
+       public function __construct() {
+               static::bar();
+               parent::bar();
+       }
+}
+
+
+new foo;
+
+?>
+--EXPECT--
+hello
+hello
diff --git a/Zend/tests/objects_029.phpt b/Zend/tests/objects_029.phpt
new file mode 100644 (file)
index 0000000..5e8de18
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Trying to access undeclared static property
+--FILE--
+<?php
+
+class bar {
+       public function __set($a, $b) {
+               print "hello\n";
+       }
+}
+
+class foo extends bar {
+       public function __construct() {
+               static::$f = 1;
+       }
+       public function __set($a, $b) {
+               print "foo\n";
+       }
+}
+
+
+new foo;
+
+?>
+--EXPECTF--
+Fatal error: Access to undeclared static property: foo::$f in %s on line %d
diff --git a/Zend/tests/objects_030.phpt b/Zend/tests/objects_030.phpt
new file mode 100644 (file)
index 0000000..8b7cfe3
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Trying to access undeclared parent property
+--FILE--
+<?php
+
+class bar {
+       public function __set($a, $b) {
+               print "hello\n";
+       }
+}
+
+class foo extends bar {
+       public function __construct() {
+               parent::$f = 1;
+       }
+       public function __set($a, $b) {
+               print "foo\n";
+       }
+}
+
+
+new foo;
+
+?>
+--EXPECTF--
+Fatal error: Access to undeclared static property: bar::$f in %s on line %d