Code Duplication    Length = 14-14 lines in 2 locations

src/SilverStripe/BehatExtension/Context/SilverStripeContext.php 2 locations

@@ 393-406 (lines=14) @@
390
	 *
391
	 * @Given /^the current date is "([^"]*)"$/
392
	 */
393
	public function givenTheCurrentDateIs($date) {
394
		$newDatetime = \DateTime::createFromFormat('Y-m-d', $date);
395
		if(!$newDatetime) {
396
			throw new InvalidArgumentException(sprintf('Invalid date format: %s (requires "Y-m-d")', $date));
397
		}
398
399
		$state = $this->testSessionEnvironment->getState();
400
		$oldDatetime = \DateTime::createFromFormat('Y-m-d H:i:s', isset($state->datetime) ? $state->datetime : null);
401
		if($oldDatetime) {
402
			$newDatetime->setTime($oldDatetime->format('H'), $oldDatetime->format('i'), $oldDatetime->format('s'));
403
		}
404
		$state->datetime = $newDatetime->format('Y-m-d H:i:s');
405
		$this->testSessionEnvironment->applyState($state);
406
	}
407
408
	/**
409
	 * Sets the current time. Relies on the underlying functionality using
@@ 416-429 (lines=14) @@
413
	 *
414
	 * @Given /^the current time is "([^"]*)"$/
415
	 */
416
	public function givenTheCurrentTimeIs($time) {
417
		$newDatetime = \DateTime::createFromFormat('H:i:s', $date);
418
		if(!$newDatetime) {
419
			throw new InvalidArgumentException(sprintf('Invalid date format: %s (requires "H:i:s")', $date));
420
		}
421
422
		$state = $this->testSessionEnvironment->getState();
423
		$oldDatetime = \DateTime::createFromFormat('Y-m-d H:i:s', isset($state->datetime) ? $state->datetime : null);
424
		if($oldDatetime) {
425
			$newDatetime->setDate($oldDatetime->format('Y'), $oldDatetime->format('m'), $oldDatetime->format('d'));
426
		}
427
		$state->datetime = $newDatetime->format('Y-m-d H:i:s');
428
		$this->testSessionEnvironment->applyState($state);
429
	}
430
431
	/**
432
	 * Selects option in select field with specified id|name|label|value.