Skip to content

Commit

Permalink
- New tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed May 12, 2008
1 parent 7416b0c commit c065d7e
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Zend/tests/class_alias_001.phpt
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions Zend/tests/class_alias_002.phpt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions Zend/tests/class_alias_003.phpt
Original file line number Diff line number Diff line change
@@ -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) {
}
15 changes: 15 additions & 0 deletions Zend/tests/class_alias_004.phpt
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions Zend/tests/class_alias_005.phpt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions Zend/tests/class_alias_006.phpt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Zend/tests/class_alias_007.phpt
Original file line number Diff line number Diff line change
@@ -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) {
}
16 changes: 16 additions & 0 deletions Zend/tests/class_alias_008.phpt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions Zend/tests/class_alias_009.phpt
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions Zend/tests/class_alias_010.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c065d7e

Please sign in to comment.