-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Jeckel-Lab/feature/codeception-helper
Add helper for codeception
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Julien Mercier-Rojas <[email protected]> | ||
* Created at: 25/03/2021 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeckelLab\Clock\CodeceptionHelper; | ||
|
||
use Codeception\Configuration; | ||
use Codeception\Module; | ||
use RuntimeException; | ||
|
||
/** | ||
* Class Clock | ||
* @package JeckelLab\Clock\CodeceptionHelper | ||
*/ | ||
class Clock extends Module | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $requiredFields = ['fake_time_path']; | ||
|
||
/** | ||
* Expected format 'Y-m-d H:i:s' | ||
* @Given current date and time is :currentDate | ||
* @param string $currentDate | ||
*/ | ||
public function currentDateAndTimeIs(string $currentDate): void | ||
{ | ||
/** @psalm-suppress MixedArrayAccess */ | ||
$fullPath = Configuration::projectDir() . ((string) $this->config['fake_time_path']); | ||
|
||
$dir = dirname($fullPath); | ||
if (!is_dir($dir) && !mkdir($dir) && !is_dir($dir)) { | ||
throw new RuntimeException(sprintf('Directory "%s" was not created', $dir)); | ||
} | ||
file_put_contents($fullPath, $currentDate); | ||
} | ||
} |