]> granicus.if.org Git - php/commitdiff
Add tests for DatePeriod properties
authorCraig Duncan <git@duncanc.co.uk>
Tue, 28 May 2019 19:49:14 +0000 (20:49 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 29 May 2019 07:47:10 +0000 (09:47 +0200)
ext/date/tests/DatePeriod_properties1.phpt [new file with mode: 0644]
ext/date/tests/DatePeriod_properties2.phpt [new file with mode: 0644]

diff --git a/ext/date/tests/DatePeriod_properties1.phpt b/ext/date/tests/DatePeriod_properties1.phpt
new file mode 100644 (file)
index 0000000..32ede7d
--- /dev/null
@@ -0,0 +1,37 @@
+--TEST--
+DatePeriod: Test read only properties
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+$start = new DateTime;
+$interval = new DateInterval('P1D');
+$end = new DateTime;
+$period = new DatePeriod($start, $interval, $end);
+
+echo "recurrences: ";
+var_dump($period->recurrences);
+
+echo "include_start_date: ";
+var_dump($period->include_start_date);
+
+echo "start: ";
+var_dump($period->start == $start);
+
+echo "current: ";
+var_dump($period->current);
+
+echo "end: ";
+var_dump($period->end == $end);
+
+echo "interval: ";
+var_dump($period->interval->format("%R%d"));
+?>
+--EXPECT--
+recurrences: int(1)
+include_start_date: bool(true)
+start: bool(true)
+current: NULL
+end: bool(true)
+interval: string(2) "+1"
diff --git a/ext/date/tests/DatePeriod_properties2.phpt b/ext/date/tests/DatePeriod_properties2.phpt
new file mode 100644 (file)
index 0000000..01858e6
--- /dev/null
@@ -0,0 +1,46 @@
+--TEST--
+DatePeriod: Test cannot modify read only properties
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+$period = new DatePeriod(new DateTime, new DateInterval('P1D'), new DateTime);
+
+$properties = [
+    "recurrences",
+    "include_start_date",
+    "start",
+    "current",
+    "end",
+    "interval",
+];
+
+foreach ($properties as $property) {
+    try {
+        $period->$property = "new";
+    } catch (Error $e) {
+        echo $e->getMessage() . "\n";
+    }
+
+    try {
+        $period->$property[] = "extra";
+    } catch (Error $e) {
+        echo $e->getMessage() . "\n";
+    }
+}
+
+?>
+--EXPECT--
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported