* @dataProvider providerTestInvalidDateDiff
*/
public function testInvalidDateDiff($input1, $input2, $absolute) {
- $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\BadMethodCallException::class);
+ $this->expectExceptionMessage('Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+ }
+ else {
+ $this->setExpectedException(\BadMethodCallException::class, 'Method Drupal\Component\Datetime\DateTimePlus::diff expects parameter 1 to be a \DateTime or \Drupal\Component\Datetime\DateTimePlus object');
+ }
$interval = $input1->diff($input2, $absolute);
}
* @dataProvider providerTestInvalidDateArrays
*/
public function testInvalidDateArrays($input, $timezone, $class) {
- $this->setExpectedException($class);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException($class);
+ }
+ else {
+ $this->setExpectedException($class);
+ }
$this->assertInstanceOf(
'\Drupal\Component\DateTimePlus',
DateTimePlus::createFromArray($input, $timezone)
* @dataProvider providerTestInvalidDates
*/
public function testInvalidDates($input, $timezone, $format, $message, $class) {
- $this->setExpectedException($class);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException($class);
+ }
+ else {
+ $this->setExpectedException($class);
+ }
DateTimePlus::createFromFormat($format, $input, $timezone);
}
// Parse the same date with ['validate_format' => TRUE] and make sure we
// get the expected exception.
- $this->setExpectedException(\UnexpectedValueException::class);
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\UnexpectedValueException::class);
+ }
+ else {
+ $this->setExpectedException(\UnexpectedValueException::class);
+ }
$date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '11-03-31 17:44:00', 'UTC', ['validate_format' => TRUE]);
}
+ /**
+ * Tests setting the default time for date-only objects.
+ */
+ public function testDefaultDateTime() {
+ $utc = new \DateTimeZone('UTC');
+
+ $date = DateTimePlus::createFromFormat('Y-m-d H:i:s', '2017-05-23 22:58:00', $utc);
+ $this->assertEquals('22:58:00', $date->format('H:i:s'));
+ $date->setDefaultDateTime();
+ $this->assertEquals('12:00:00', $date->format('H:i:s'));
+ }
+
/**
* Tests that object methods are chainable.
*
* @covers ::__call
*/
public function testChainableNonCallable() {
- $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException(\BadMethodCallException::class);
+ $this->expectExceptionMessage('Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+ }
+ else {
+ $this->setExpectedException(\BadMethodCallException::class, 'Call to undefined method Drupal\Component\Datetime\DateTimePlus::nonexistent()');
+ }
$date = new DateTimePlus('now', 'Australia/Sydney');
$date->setTimezone(new \DateTimeZone('America/New_York'))->nonexistent();
}