Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
  • Loading branch information
jamielsharief committed Feb 23, 2021
2 parents d466003 + b69dc5e commit 8adde90
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class GenerateCommand extends Command
'repository' => 'Generates a Repository for a Model',
'scaffold' => 'Generates a MVC using the database',
'service' => 'Generates a Service Object class',
'task' => 'Generates a Task for Scheduling'
];

public function initialize(): void
Expand Down Expand Up @@ -412,6 +413,23 @@ protected function repository(array $data)
);
}

protected function task(array $data)
{
$data['custom'] = Inflector::human($data['underscored']);

$this->generate(
$this->getTemplateFilename('task'),
$this->getBaseFolder($data['name'], self::SRC). DS .'Task'. DS ."{$data['class']}Task.php",
$data
);

$this->generate(
$this->getTemplateFilename('task_test'),
$this->getBaseFolder($data['name'], self::TEST). DS .'Task'. DS ."{$data['class']}TaskTest.php",
$data
);
}

protected function record(array $data)
{
$this->generate(
Expand Down
26 changes: 26 additions & 0 deletions templates/generator/task.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types = 1);
namespace %namespace%\Task;

use Origin\Schedule\Task;
use Origin\Schedule\Schedule;

class BackupTask extends Task
{
protected $name = '%custom%';
protected $description = '';
protected function startup(): void
{
}

protected function handle(Schedule $schedule): void
{
$event = $schedule->command('ls -la')
->everyMinute();
}

protected function shutdown(): void
{
}
}
17 changes: 17 additions & 0 deletions templates/generator/task_test.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types = 1);
namespace %namespace%\Test\TestCase\Task;

use Origin\TestSuite\OriginTestCase;
use %namespace%\Task\%class%Task;

class %class%TaskTest extends OriginTestCase
{
public function testExecute()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
(new %class%Task())->dispatch();
}
}
20 changes: 20 additions & 0 deletions tests/TestCase/Console/Command/GenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,26 @@ public function testPlugin()
$this->recursiveDelete(PLUGINS . DS . 'dummy');
}

public function testGenerateTask()
{
$this->exec('generate --force task Dummy');

$this->assertExitSuccess();
$filename = APP . DS . 'Task' . DS . 'DummyTask.php';
$this->assertOutputContains('src/Task/DummyTask.php');
$this->assertFileExists($filename);

$this->assertFileHash('d7c26db6ab2efa5134e642cc71455812', $filename);
unlink($filename);

$filename = TESTS . DS . 'TestCase' . DS . 'Task' . DS . 'DummyTaskTest.php';

$this->assertOutputContains('TestCase/Task/DummyTaskTest.php');
$this->assertFileExists($filename);
$this->assertFileHash('721d6a783b06f1aae788035566e00f03', $filename);
unlink($filename);
}

/*
'plugin' => 'Generates a plugin skeleton',
Expand Down

0 comments on commit 8adde90

Please sign in to comment.