Skip to content

Commit

Permalink
complete download method with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
milwad-dev committed Mar 10, 2024
1 parent 34bd68d commit 5d12e3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/LaravelStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ public function replaces(array $replaces): static
/**
* Download the stub file.
*/
public function download(): mixed
{// TODO: Add tests and complete this
return Response::download($this->to);
public function download()
{
$this->generate();

return Response::download($this->getPath());
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Feature/LaravelStubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,22 @@
\PHPUnit\Framework\assertFileDoesNotExist(__DIR__ . '/../App/new-test.php');
\PHPUnit\Framework\assertFileExists(__DIR__ . '/../App/test.stub');
})->expectExceptionMessage('The given folder path is not valid.');

test('download the stub file', function () {
$stub = __DIR__ . '/test.stub';

$downloadInstance = LaravelStub::from($stub)
->to(__DIR__ . '/../App')
->replaces([
'CLASS' => 'Milwad',
'NAMESPACE' => 'App\Models'
])
->replace('TRAIT', 'HasFactory')
->name('new-test')
->ext('php')
->download();

expect($downloadInstance)->toBeInstanceOf(\Symfony\Component\HttpFoundation\BinaryFileResponse::class);
\PHPUnit\Framework\assertFileExists(__DIR__ . '/../App/new-test.php');
\PHPUnit\Framework\assertFileDoesNotExist(__DIR__ . '/../App/test.stub');
});

0 comments on commit 5d12e3d

Please sign in to comment.