File tree Expand file tree Collapse file tree 3 files changed +42
-16
lines changed
Expand file tree Collapse file tree 3 files changed +42
-16
lines changed Original file line number Diff line number Diff line change 33
44namespace Deployer ;
55
6- use Deployer \Task \Task ;
76use IntegerNet \DeployerTimer \DecorateAllTasks ;
7+ use IntegerNet \DeployerTimer \ResultTaskFactory ;
88use IntegerNet \DeployerTimer \TimerTaskDecorator ;
99
10- function timerCsv ( string $ fileName )
10+ function timer (): ResultTaskFactory
1111{
1212 $ deployer = Deployer::get ();
1313 $ decorateAllTasks = new DecorateAllTasks ($ deployer );
1414 $ timer = new TimerTaskDecorator ();
1515 $ decorateAllTasks ->with ($ timer );
16- $ tasks = $ deployer ->tasks ->toArray ();
17- /** @var Task $lastTask */
18- $ lastTask = array_pop ($ tasks );
19- $ collectResultTask = uniqid ('timer_result- ' , true );
20- task (
21- $ collectResultTask , function () use ($ timer , $ fileName ) {
22- file_put_contents ($ fileName , $ timer ->resultsAsCsv ());
23- });
24- after ($ lastTask ->getName (), $ collectResultTask );
25- }
16+ return new ResultTaskFactory ($ deployer , $ timer );
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace IntegerNet \DeployerTimer ;
5+
6+ use Deployer \Deployer ;
7+ use Deployer \Task \Task ;
8+
9+ class ResultTaskFactory
10+ {
11+ /**
12+ * @var TimerTaskDecorator
13+ */
14+ private $ timer ;
15+ /**
16+ * @var Deployer
17+ */
18+ private $ deployer ;
19+
20+ public function __construct (Deployer $ deployer , TimerTaskDecorator $ timer )
21+ {
22+ $ this ->deployer = $ deployer ;
23+ $ this ->timer = $ timer ;
24+ }
25+
26+ public function createCsvResultTask ($ fileName ): string
27+ {
28+ $ taskName = uniqid ('timer_result- ' , true );
29+ $ taskBody = function () use ($ fileName ) {
30+ file_put_contents ($ fileName , $ this ->timer ->resultsAsCsv ());
31+ };
32+ $ this ->deployer ->tasks ->set ($ taskName , new Task ($ taskName , $ taskBody ));
33+
34+ return $ taskName ;
35+ }
36+ }
Original file line number Diff line number Diff line change 33
44namespace IntegerNet \DeployerTimer ;
55
6- use Deployer \Deployer ;
76use PHPUnit \Framework \TestCase ;
8- use Symfony \Component \Process \Process ;
97
108class RecipeTest extends TestCase
119{
@@ -31,7 +29,7 @@ protected function tearDown(): void
3129 }
3230 }
3331
34- public function testTimer ()
32+ public function testTimerWithCsvResult ()
3533 {
3634 $ recipeFile = __DIR__ . '/../recipe/timer.php ' ;
3735 $ csvFile = $ this ->createTmpFile ();
@@ -45,7 +43,7 @@ public function testTimer()
4543
4644task('test', function() { writeln('Test Output');});
4745
48- timerCsv(' {$ csvFile }');
46+ after('test', timer()->createCsvResultTask(' {$ csvFile }') );
4947PHP
5048 );
5149 exec ('vendor/bin/dep --file= ' . $ this ->deployFile . ' test ' , $ output );
You can’t perform that action at this time.
0 commit comments