File tree Expand file tree Collapse file tree 11 files changed +99
-12
lines changed
Expand file tree Collapse file tree 11 files changed +99
-12
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ tests/temp
55.idea
66.phpunit.result.cache
77.php-cs-fixer.cache
8+ migrations
Original file line number Diff line number Diff line change 22
33[ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/programic/laravel-task.svg?style=flat-square )] ( https://packagist.org/packages/programic/laravel-task )
44![ ] ( https://github.com/programic/laravel-task/workflows/Run%20Tests/badge.svg?branch=master )
5- ![ GitHub Workflow Status ] ( https://img.shields.io/github/workflow/status/ programic/laravel-task/run-php- tests?label=Tests )
5+ [ ![ Tests ] ( https://github.com/ programic/laravel-task/actions/workflows/ run-tests.yml/badge.svg?branch=master )] ( https://github.com/programic/laravel-task/actions/workflows/tests.yml )
66[ ![ Total Downloads] ( https://img.shields.io/packagist/dt/programic/laravel-task.svg?style=flat-square )] ( https://packagist.org/packages/programic/laravel-task )
77
88This package allows you to automate tasks as in migrations
Original file line number Diff line number Diff line change 1212 "role" : " Developer"
1313 }
1414 ],
15- "require" : {
16-
17- },
1815 "require-dev" : {
19-
16+ "ext-pdo_sqlite" : " *" ,
17+ "orchestra/testbench" : " ^7.1" ,
18+ "nunomaduro/collision" : " ^6.1"
2019 },
2120 "autoload" : {
2221 "psr-4" : {
2322 "Programic\\ Tasks\\ " : " src/"
2423 }
2524 },
25+ "autoload-dev" : {
26+ "psr-4" : {
27+ "Programic\\ Tasks\\ Tests\\ " : " tests"
28+ }
29+ },
2630 "extra" : {
2731 "laravel" : {
2832 "providers" : [
Original file line number Diff line number Diff line change @@ -28,8 +28,7 @@ class MakeTaskCommand extends Command
2828 /**
2929 * Execute the console command.
3030 *
31- * @return mixed
32- * @throws Exception
31+ * @return void
3332 */
3433 public function handle ()
3534 {
@@ -40,7 +39,7 @@ public function handle()
4039 $ stub = File::get (__DIR__ . '/../../stubs/task.php.stub ' );
4140 $ stub = str_replace ('TASK_NAME ' , $ className , $ stub );
4241
43- File::put (base_path () . ' /tasks/ ' . $ fileName , $ stub );
42+ File::put (Task:: getDirectory () . $ fileName , $ stub );
4443
4544 $ this ->line ('<info>Task created:</info> ' . $ fileName );
4645 }
Original file line number Diff line number Diff line change 99 * @method static \Programic\Tasks\Tasks when(bool|\Closure $bool, \Closure $callback)
1010 * @method static \Programic\Tasks\Tasks fresh(\Closure $callback)
1111 * @method static \Programic\Tasks\Tasks noFresh(\Closure $callback)
12- *
12+ * @method static \Programic\Tasks\Tasks getDirectory(): string
1313 *
1414 * @see \Illuminate\Database\Schema\Builder
1515 */
Original file line number Diff line number Diff line change 33namespace Programic \Tasks ;
44
55use Illuminate \Contracts \Foundation \Application ;
6+ use Programic \Tasks \Traits \Helpers ;
67use Symfony \Component \Console \Input \ArgvInput ;
78use Symfony \Component \Console \Output \ConsoleOutput ;
89
910class Tasks
1011{
12+ use Helpers;
13+
1114 protected Application $ app ;
1215
1316 public function __construct (Application $ app )
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Programic \Tasks \Traits ;
4+
5+ use Illuminate \Support \Facades \App ;
6+
7+ trait Helpers {
8+
9+ /**
10+ * @return string
11+ */
12+ public function getDirectory ()
13+ {
14+ if (App::runningUnitTests ()) {
15+ return __DIR__ . '/../../migrations/ ' ;
16+ }
17+
18+ return base_path () . '/tasks/ ' ;
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Programic \Tasks \Tests ;
4+
5+ use Carbon \Carbon ;
6+ use Illuminate \Support \Str ;
7+ use Programic \Tasks \Facades \Task ;
8+
9+ use function PHPUnit \Framework \assertFileExists ;
10+
11+ class CommandTest extends TestCase
12+ {
13+ /** @test */
14+ public function it_can_create_task_migration ()
15+ {
16+ $ taskName = 'runTask ' ;
17+ $ this ->artisan ('make:task ' . $ taskName )
18+ ->assertSuccessful ()
19+ ->expectsOutputToContain ('Task created: ' );
20+
21+ $ taskName = Str::snake ($ taskName );
22+ $ fileName = Carbon::now ()->format ('Y_m_d_His ' ) . '_ ' . $ taskName . '.php ' ;
23+
24+ assertFileExists (Task::getDirectory () . $ fileName );
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments