Skip to content

Commit 5903a87

Browse files
authored
Merge pull request #17 from Jeckel-Lab/feature/codeception-helper
Add helper for codeception
2 parents 48a3bed + 4bcef42 commit 5903a87

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"squizlabs/php_codesniffer": "^3.5",
3232
"mikey179/vfsstream": "^1.6",
3333
"vimeo/psalm": "^4.3",
34-
"phpro/grumphp": "^0.19 || ^1.2.0"
34+
"phpro/grumphp": "^0.19 || ^1.2.0",
35+
"codeception/codeception": "^4.1"
36+
},
37+
"suggest": {
38+
"codeception/codeception": "Use helper to handle clock with your codeception tests"
3539
}
3640
}

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<include>
66
<directory suffix=".php">src</directory>
77
</include>
8+
<exclude>
9+
<directory suffix=".php">src/CodeceptionHelper</directory>
10+
</exclude>
811
</coverage>
912
<testsuites>
1013
<testsuite name="Project Test Suite">

src/CodeceptionHelper/Clock.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* @author: Julien Mercier-Rojas <[email protected]>
5+
* Created at: 25/03/2021
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace JeckelLab\Clock\CodeceptionHelper;
11+
12+
use Codeception\Configuration;
13+
use Codeception\Module;
14+
use RuntimeException;
15+
16+
/**
17+
* Class Clock
18+
* @package JeckelLab\Clock\CodeceptionHelper
19+
*/
20+
class Clock extends Module
21+
{
22+
/**
23+
* @var array
24+
*/
25+
protected $requiredFields = ['fake_time_path'];
26+
27+
/**
28+
* Expected format 'Y-m-d H:i:s'
29+
* @Given current date and time is :currentDate
30+
* @param string $currentDate
31+
*/
32+
public function currentDateAndTimeIs(string $currentDate): void
33+
{
34+
/** @psalm-suppress MixedArrayAccess */
35+
$fullPath = Configuration::projectDir() . ((string) $this->config['fake_time_path']);
36+
37+
$dir = dirname($fullPath);
38+
if (!is_dir($dir) && !mkdir($dir) && !is_dir($dir)) {
39+
throw new RuntimeException(sprintf('Directory "%s" was not created', $dir));
40+
}
41+
file_put_contents($fullPath, $currentDate);
42+
}
43+
}

0 commit comments

Comments
 (0)