Skip to content

Commit 1ba315c

Browse files
author
Holger Lösken
committed
Reset download directory after each test
1 parent d998e94 commit 1ba315c

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

tests/Commands/CheckUpdateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
final class CheckUpdateTest extends TestCase
1212
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
$this->resetDownloadDir();
17+
}
18+
1319
/** @test */
1420
public function it_can_run_check_update_command_without_new_version_available(): void
1521
{

tests/Models/ReleaseTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ protected function setUp(): void
2424
parent::setUp();
2525
$this->release = resolve( Release::class );
2626
$this->vfs = vfsStream::setup();
27+
28+
$this->resetDownloadDir();
2729
}
2830

2931
/** @test */
@@ -132,7 +134,7 @@ public function it_cannot_extract_zip_and_fails_with_exception(): void
132134
/** @test */
133135
public function it_can_extract_zip_to_storage_path(): void
134136
{
135-
$this->release->setStoragePath('/tmp')->setRelease('release-test-1.2.zip')->updateStoragePath();
137+
$this->release->setStoragePath((string) config('self-update.repository_types.github.download_path'))->setRelease('release-test-1.2.zip')->updateStoragePath();
136138

137139
$zip = new \ZipArchive();
138140
$res = $zip->open($this->release->getStoragePath(), \ZipArchive::CREATE);
@@ -167,7 +169,7 @@ public function it_can_download(): void
167169
]);
168170

169171
$this->release->setDownloadUrl('url-to-download')
170-
->setStoragePath('/tmp')
172+
->setStoragePath((string) config('self-update.repository_types.github.download_path'))
171173
->setRelease('release-1.0.zip')
172174
->updateStoragePath();
173175

tests/Models/UpdateExecutorTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,25 @@ protected function setUp(): void
2626
$this->release = resolve(Release::class);
2727

2828
$this->vfs = vfsStream::setup('root');
29+
30+
$this->resetDownloadDir();
2931
}
3032

3133
/** @test */
3234
public function it_can_run_successfully(): void
3335
{
34-
File::makeDirectory('/tmp/update-dir', 0775, false, true);
36+
$dir = (string) config('self-update.repository_types.github.download_path') . '/update-dir';
37+
File::makeDirectory($dir, 0775, false, true);
3538

36-
$this->release->setStoragePath('/tmp')
39+
$this->release->setStoragePath((string) config('self-update.repository_types.github.download_path'))
3740
->setRelease('release-1.0.zip')
3841
->updateStoragePath()
3942
->setDownloadUrl('some-local-file')
4043
->download($this->getMockedDownloadZipFileClient());
4144
$this->release->extract();
4245

4346
$updateExecutor = new UpdateExecutor();
44-
$this->assertTrue($updateExecutor->setBasePath('/tmp/update-dir')->run($this->release));
47+
$this->assertTrue($updateExecutor->setBasePath($dir)->run($this->release));
4548

4649
}
4750

tests/TestCase.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes\GithubBranchType;
88
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes\GithubTagType;
99
use Codedge\Updater\SourceRepositoryTypes\HttpRepositoryType;
10-
use Codedge\Updater\Tests\Commands\SamplePostUpdate;
11-
use Codedge\Updater\Tests\Commands\SamplePreUpdate;
1210
use Codedge\Updater\UpdaterFacade;
1311
use Codedge\Updater\UpdaterServiceProvider;
1412
use GuzzleHttp\Client;
1513
use GuzzleHttp\Handler\MockHandler;
1614
use GuzzleHttp\HandlerStack;
1715
use GuzzleHttp\Psr7\Response;
16+
use Illuminate\Filesystem\Filesystem;
1817
use Illuminate\Foundation\Application;
1918
use Orchestra\Testbench\TestCase as Orchestra;
2019

2120
abstract class TestCase extends Orchestra
2221
{
22+
const DOWNLOAD_PATH = '/tmp/self-updater';
23+
2324
/**
2425
* @var array
2526
*/
@@ -47,7 +48,7 @@ protected function getEnvironmentSetUp($app)
4748
'repository_vendor' => 'laravel',
4849
'repository_name' => 'laravel',
4950
'repository_url' => '',
50-
'download_path' => '/tmp',
51+
'download_path' => self::DOWNLOAD_PATH,
5152
'private_access_token' => '',
5253
'use_branch' => '',
5354
],
@@ -104,7 +105,6 @@ protected function getEnvironmentSetUp($app)
104105
$app->make(UpdateExecutor::class)
105106
);
106107
});
107-
108108
}
109109

110110
protected function getMockedClient($responses): Client
@@ -147,6 +147,19 @@ protected function getResponseEmpty(): Response
147147
);
148148
}
149149

150+
protected function resetDownloadDir()
151+
{
152+
/** @var Filesystem $filesystem */
153+
$filesystem = $this->app->make(Filesystem::class);
154+
155+
if($filesystem->exists(self::DOWNLOAD_PATH)) {
156+
$filesystem->deleteDirectory(self::DOWNLOAD_PATH);
157+
$filesystem->makeDirectory(self::DOWNLOAD_PATH);
158+
} else {
159+
$filesystem->makeDirectory(self::DOWNLOAD_PATH);
160+
}
161+
}
162+
150163
/**
151164
* @param Application $app
152165
* @return array

0 commit comments

Comments
 (0)