Mercurial > hg > isophonics-drupal-site
diff core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 7a779792577d |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php Mon Apr 23 09:46:53 2018 +0100 @@ -87,7 +87,13 @@ * @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); } @@ -104,7 +110,12 @@ * @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) @@ -242,7 +253,12 @@ * @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); } @@ -800,11 +816,28 @@ // 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 @@ -847,7 +880,13 @@ * @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(); }