Skip to content

Commit 5fa2a41

Browse files
committed
tests
1 parent 36cc5a4 commit 5fa2a41

File tree

10 files changed

+178
-0
lines changed

10 files changed

+178
-0
lines changed

Zend/tests/return_hint/001.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Basic return hints at compilation
3+
--FILE--
4+
<?php
5+
function test1() : array {
6+
7+
}
8+
/* this is bad ... */
9+
?>
10+
--EXPECT--

Zend/tests/return_hint/002.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Basic return hints at execution
3+
--FILE--
4+
<?php
5+
function test1() : array {
6+
return null;
7+
}
8+
9+
test1();
10+
?>
11+
--EXPECTF--
12+
Fatal error: the function test1 was expected to return array and returned null in %s on line %d
13+

Zend/tests/return_hint/003.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Basic return hints at execution allowing null
3+
--FILE--
4+
<?php
5+
function test1() : ?array {
6+
return null;
7+
}
8+
9+
var_dump(test1());
10+
?>
11+
--EXPECT--
12+
NULL
13+

Zend/tests/return_hint/004.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Basic return hints at execution mismatched basic type
3+
--FILE--
4+
<?php
5+
function test1() : array {
6+
return "hello";
7+
}
8+
9+
test1()
10+
?>
11+
--EXPECTF--
12+
Fatal error: the function test1 was expected to return array and returned string in %s on line %d

Zend/tests/return_hint/005.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Basic return hints methods
3+
--FILE--
4+
<?php
5+
class foo {}
6+
class bar {}
7+
class baz {}
8+
9+
class qux extends baz {
10+
public function foo() : foo {
11+
return new baz();
12+
}
13+
}
14+
15+
$qux = new qux();
16+
$qux->foo();
17+
?>
18+
--EXPECTF--
19+
Fatal error: the function foo was expected to return foo and returned baz in %s on line %d
20+

Zend/tests/return_hint/006.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Basic return hints covariance
3+
--FILE--
4+
<?php
5+
class foo {}
6+
class bar extends foo {}
7+
class baz {}
8+
9+
class qux extends baz {
10+
public function foo() : foo {
11+
return new bar();
12+
}
13+
}
14+
15+
$qux = new qux();
16+
var_dump($qux->foo());
17+
?>
18+
--EXPECTF--
19+
object(bar)#%d (%d) {
20+
}
21+
22+

Zend/tests/return_hint/007.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Basic return hints covariance
3+
--FILE--
4+
<?php
5+
class foo {}
6+
class bar extends foo {}
7+
class baz {}
8+
9+
class qux extends baz {
10+
public function foo() : foo {
11+
return new bar();
12+
}
13+
}
14+
15+
$qux = new qux();
16+
var_dump($qux->foo());
17+
?>
18+
--EXPECTF--
19+
object(bar)#%d (%d) {
20+
}
21+
22+

Zend/tests/return_hint/008.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Basic return hints covariance interfaces
3+
--FILE--
4+
<?php
5+
interface foo {}
6+
interface bar extends foo {
7+
public function foo() : foo;
8+
}
9+
10+
11+
class qux implements bar {
12+
public function foo() : bar {
13+
return new qux();
14+
}
15+
}
16+
17+
$qux = new qux();
18+
var_dump($qux->foo());
19+
?>
20+
--EXPECTF--
21+
object(qux)#%d (%d) {
22+
}
23+
24+

Zend/tests/return_hint/009.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Basic return hints covariance interfaces errors
3+
--FILE--
4+
<?php
5+
interface foo {}
6+
interface bar {
7+
public function foo() : foo;
8+
}
9+
10+
class qux implements bar {
11+
public function foo() : array {
12+
return new qux();
13+
}
14+
}
15+
16+
$qux = new qux();
17+
var_dump($qux->foo());
18+
?>
19+
--EXPECTF--
20+
Fatal error: Delcaration of qux::foo should be compatible with bar::foo() : foo, return type mismatch in /usr/src/php-src/Zend/tests/return_hint/009.php on line 7
21+
22+

Zend/tests/return_hint/010.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Basic return hints covariance interfaces nulls
3+
--FILE--
4+
<?php
5+
interface foo {}
6+
interface bar extends foo {
7+
public function foo() : foo;
8+
}
9+
10+
class qux implements bar {
11+
public function foo() : ?foo {
12+
return null;
13+
}
14+
}
15+
16+
$qux = new qux();
17+
var_dump($qux->foo());
18+
?>
19+
--EXPECT--
20+
NULL

0 commit comments

Comments
 (0)