This repository was archived by the owner on Apr 23, 2024. It is now read-only.
File tree 4 files changed +155
-5
lines changed
4 files changed +155
-5
lines changed Original file line number Diff line number Diff line change 21
21
}
22
22
},
23
23
"require" : {
24
- "php" : " >=7.0 " ,
24
+ "php" : " >=7.1 " ,
25
25
"codeception/codeception" : " ^2.5" ,
26
26
"behat/behat" : " ^3.5"
27
27
},
28
28
"require-dev" : {
29
29
"phpstan/phpstan" : " ^0.11.5" ,
30
30
"squizlabs/php_codesniffer" : " ^3.4" ,
31
- "phpmd/phpmd" : " ^2.6"
31
+ "phpmd/phpmd" : " ^2.6" ,
32
+ "mikey179/vfsStream" : " ^1.6"
32
33
},
33
34
"suggest" : {
34
35
"edno/codeception-gherkin-param" : " The Codeception extension for supporting parameter notation in Gherkin scenario." ,
35
- "flow/jsonpath" : " Json path parser"
36
+ "flow/jsonpath" : " Json path parser" ,
37
+ "jeckel/clock" : " Clock service with mock capability"
36
38
}
37
39
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ namespace Jeckel \Gherkin ;
3
+
4
+ use Codeception \Lib \Interfaces \RequiresPackage ;
5
+ use Codeception \Configuration ;
6
+
7
+ /**
8
+ * Class Clock
9
+ * @package Jeckel\Gherkin
10
+ * @SuppressWarnings(PHPMD.LongVariable)
11
+ */
12
+ class Clock extends ContextAbstract
13
+ {
14
+ /** @var array */
15
+ protected $ requiredFields = ['clock_path ' ];
16
+
17
+ // disable all inherited actions
18
+ public static $ includeInheritedActions = false ;
19
+
20
+ /** @var string */
21
+ protected $ projectDir = null ;
22
+
23
+ /**
24
+ * @return string
25
+ * @SuppressWarnings(PHPMD.StaticAccess)
26
+ */
27
+ public function getProjectDir (): string
28
+ {
29
+ if (empty ($ this ->projectDir )) {
30
+ return Configuration::projectDir ();
31
+ }
32
+ return $ this ->projectDir ;
33
+ }
34
+
35
+ /**
36
+ * @param string $projectDir
37
+ * @return Clock
38
+ */
39
+ public function setProjectDir (string $ projectDir ): Clock
40
+ {
41
+ $ this ->projectDir = $ projectDir ;
42
+ return $ this ;
43
+ }
44
+
45
+ /**
46
+ * @Given I set fake clock to :clock
47
+ * @param string $clock
48
+ */
49
+ public function setFakeClockTo (string $ clock )
50
+ {
51
+ file_put_contents ($ this ->projectDir . $ this ->config ['clock_path ' ], $ clock );
52
+ }
53
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * User: jeckel
4
+ * Date: 21/04/19
5
+ * Time: 15:45
6
+ */
7
+
8
+ namespace Test \Jeckel \Gherkin ;
9
+
10
+ use Codeception \Lib \ModuleContainer ;
11
+ use Jeckel \Gherkin \Clock ;
12
+ use org \bovigo \vfs \vfsStream ;
13
+ use org \bovigo \vfs \vfsStreamDirectory ;
14
+ use org \bovigo \vfs \vfsStreamWrapper ;
15
+ use PHPUnit \Framework \MockObject \MockObject ;
16
+
17
+ class ClockTest extends \Codeception \Test \Unit
18
+ {
19
+ /** @var Clock */
20
+ protected $ helper ;
21
+
22
+ public function setUp ()
23
+ {
24
+ /** @var MockObject | ModuleContainer $moduleContainer */
25
+ $ moduleContainer = $ this ->createMock (ModuleContainer::class);
26
+
27
+ $ this ->helper = new Clock ($ moduleContainer );
28
+
29
+ vfsStreamWrapper::register ();
30
+ vfsStreamWrapper::setRoot (new vfsStreamDirectory ('clockDir ' ));
31
+ $ this ->helper ->setProjectDir (vfsStream::url ('clockDir ' ));
32
+
33
+ return parent ::setUp (); // TODO: Change the autogenerated stub
34
+ }
35
+
36
+ public function testSetFakeClockTo ()
37
+ {
38
+ $ clock = '2018-01-01 10:10:00 ' ;
39
+ $ clockFile = '/clock ' ;
40
+
41
+ $ this ->helper ->_setConfig (['clock_path ' => $ clockFile ]);
42
+
43
+ $ this ->helper ->setFakeClockTo ($ clock );
44
+ $ this ->assertTrue (vfsStreamWrapper::getRoot ()->hasChild ('clock ' ));
45
+ $ this ->assertEquals ($ clock , file_get_contents (vfsStream::url ('clockDir ' ) . $ clockFile ));
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments