com php-src: Fix generator test; add covariance tests: Zend/tests/return_types/generators002.phpt Zend/tes ts/type_declarations/iterable_004.phpt
Zend/tests /type_declarations/iterable_005.phpt
| From: | Aaron Piotrowski | Date: | Sat, 04 Jun 2016 15:08:44 +0000 |
| Subject: | com php-src: Fix generator test; add covariance tests: Zend/tests/return_types/generators002.phpt Zend/tes ts/type_declarations/iterable_004.phpt Zend/tests /type_declarations/iterable_005.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92297@lists.php.net to get a copy of this message | ||
Commit: c2266c382acf8a16c18bd7df013fe40348cd478d
Author: Aaron Piotrowski <aaron@trowski.com> Sat, 4 Jun 2016 10:08:44 -0500
Parents: 4da3e77b4ce4beb1735a679c58cb2bce3fdfece1
Branches: iterable
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c2266c382acf8a16c18bd7df013fe40348cd478d
Log:
Fix generator test; add covariance tests
Changed paths:
M Zend/tests/return_types/generators002.phpt
A Zend/tests/type_declarations/iterable_004.phpt
A Zend/tests/type_declarations/iterable_005.phpt
Diff:
diff --git a/Zend/tests/return_types/generators002.phpt b/Zend/tests/return_types/generators002.phpt
index f7dbfda..519c97a 100644
--- a/Zend/tests/return_types/generators002.phpt
+++ b/Zend/tests/return_types/generators002.phpt
@@ -8,4 +8,4 @@ function test1() : StdClass {
}
--EXPECTF--
-Fatal error: Generators may only declare a return type of Generator, Iterator or Traversable,
StdClass is not permitted in %s on line %d
+Fatal error: Generators may only declare a return type of Generator, Iterator, Traversable, or
iterable, StdClass is not permitted in %s on line %d
diff --git a/Zend/tests/type_declarations/iterable_004.phpt
b/Zend/tests/type_declarations/iterable_004.phpt
new file mode 100644
index 0000000..8215dd6
--- /dev/null
+++ b/Zend/tests/type_declarations/iterable_004.phpt
@@ -0,0 +1,29 @@
+--TEST--
+iterable type#004 - Parameter covariance
+--FILE--
+<?php
+
+class Foo {
+ function testArray(array $array) {}
+
+ function testTraversable(Traversable $traversable) {}
+
+ function testGenerator(Generator $generator) {}
+
+ function testScalar(int $int) {}
+}
+
+class Bar extends Foo {
+ function testArray(iterable $iterable) {}
+
+ function testTraversable(iterable $iterable) {}
+
+ function testGenerator(iterable $iterable) {}
+
+ function testScalar(iterable $iterable) {}
+}
+
+?>
+--EXPECTF--
+
+Warning: Declaration of Bar::testScalar(iterable $iterable) should be compatible with
Foo::testScalar(int $int) in %s on line %d
diff --git a/Zend/tests/type_declarations/iterable_005.phpt
b/Zend/tests/type_declarations/iterable_005.phpt
new file mode 100644
index 0000000..cfb5551
--- /dev/null
+++ b/Zend/tests/type_declarations/iterable_005.phpt
@@ -0,0 +1,45 @@
+--TEST--
+iterable type#005 - Return type covariance
+--FILE--
+<?php
+
+class Test {
+ function method(): iterable {
+ return [];
+ }
+}
+
+class TestArray extends Test {
+ function method(): array {
+ return [];
+ }
+}
+
+class TestTraversable extends Test {
+ function method(): Traversable {
+ return new ArrayIterator([]);
+ }
+}
+
+class TestIterator extends Test {
+ function method(): Iterator {
+ return new ArrayIterator([]);
+ }
+}
+
+class TestGenerator extends Test {
+ function method(): Generator {
+ return (function () { yield; })();
+ }
+}
+
+class TestScalar extends Test {
+ function method(): int {
+ return 1;
+ }
+}
+
+?>
+--EXPECTF--
+
+Fatal error: Declaration of TestScalar::method(): int must be compatible with Test::method():
iterable in %s on line %d