Skip to content

Commit

Permalink
Merge pull request #17 from Jeckel-Lab/feature/codeception-helper
Browse files Browse the repository at this point in the history
Add helper for codeception
  • Loading branch information
jeckel authored Mar 25, 2021
2 parents 48a3bed + 4bcef42 commit 5903a87
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"squizlabs/php_codesniffer": "^3.5",
"mikey179/vfsstream": "^1.6",
"vimeo/psalm": "^4.3",
"phpro/grumphp": "^0.19 || ^1.2.0"
"phpro/grumphp": "^0.19 || ^1.2.0",
"codeception/codeception": "^4.1"
},
"suggest": {
"codeception/codeception": "Use helper to handle clock with your codeception tests"
}
}
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<directory suffix=".php">src/CodeceptionHelper</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Project Test Suite">
Expand Down
43 changes: 43 additions & 0 deletions src/CodeceptionHelper/Clock.php
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);
}
}

0 comments on commit 5903a87

Please sign in to comment.