Skip to content

Commit

Permalink
Apply fixes from StyleCI (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
codedge authored Apr 21, 2020
1 parent 2592e7a commit f16f7d2
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 88 deletions.
12 changes: 6 additions & 6 deletions src/Models/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getRelease(): ?string
*
* @return Release
*/
public function setRelease(string $release): Release
public function setRelease(string $release): self
{
$this->release = $release;

Expand All @@ -98,7 +98,7 @@ public function getStoragePath(): ?string
*
* @return Release
*/
public function setStoragePath(string $storagePath): Release
public function setStoragePath(string $storagePath): self
{
$this->storagePath = $storagePath;

Expand All @@ -114,7 +114,7 @@ public function setStoragePath(string $storagePath): Release
*
* @return Release
*/
public function updateStoragePath(): Release
public function updateStoragePath(): self
{
if (! empty($this->getRelease())) {
$this->storagePath = Str::finish($this->storagePath, DIRECTORY_SEPARATOR).$this->getRelease();
Expand All @@ -139,7 +139,7 @@ public function getUpdatePath(): ?Finder
*
* @return Release
*/
public function setUpdatePath(string $updatePath, array $excluded = []): Release
public function setUpdatePath(string $updatePath, array $excluded = []): self
{
$this->updatePath = (new Finder())->in($updatePath)->exclude($excluded);

Expand All @@ -159,7 +159,7 @@ public function getVersion(): ?string
*
* @return Release
*/
public function setVersion(string $version): Release
public function setVersion(string $version): self
{
$this->version = $version;

Expand All @@ -179,7 +179,7 @@ public function getDownloadUrl(): ?string
*
* @return Release
*/
public function setDownloadUrl(string $downloadUrl): Release
public function setDownloadUrl(string $downloadUrl): self
{
$this->downloadUrl = $downloadUrl;

Expand Down
2 changes: 1 addition & 1 deletion src/Models/UpdateExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct()
*
* @return $this
*/
public function setBasePath(string $path): UpdateExecutor
public function setBasePath(string $path): self
{
$this->basePath = Str::finish($path, DIRECTORY_SEPARATOR);

Expand Down
6 changes: 4 additions & 2 deletions tests/Commands/CheckUpdateTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Codedge\Updater\Tests\Commands;

Expand All @@ -21,7 +23,7 @@ public function it_can_run_check_update_command_without_new_version_available():
{
$client = $this->getMockedClient([
$this->getResponse200Type('tag'),
$this->getResponse200ZipFile()
$this->getResponse200ZipFile(),
]);
$this->app->instance(Client::class, $client);

Expand Down
4 changes: 3 additions & 1 deletion tests/Hooks/BypassFinalHook.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Codedge\Updater\Tests\Hooks;

Expand Down
47 changes: 25 additions & 22 deletions tests/Models/ReleaseTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Codedge\Updater\Tests\Models;

use Codedge\Updater\Tests\TestCase;
use org\bovigo\vfs\vfsStream;
use Codedge\Updater\Models\Release;
use Codedge\Updater\Tests\TestCase;
use Illuminate\Support\Str;
use org\bovigo\vfs\vfsStream;

class ReleaseTest extends TestCase
{
Expand All @@ -22,51 +24,52 @@ class ReleaseTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->release = resolve( Release::class );
$this->release = resolve(Release::class);
$this->vfs = vfsStream::setup();

$this->resetDownloadDir();
}

/** @test */
public function it_can_get_release(): void {
public function it_can_get_release(): void
{
$releaseName = 'releaseName';
$this->release->setRelease( $releaseName );
$this->release->setRelease($releaseName);

$this->assertEquals( $releaseName, $this->release->getRelease() );
$this->assertEquals($releaseName, $this->release->getRelease());
}

/** @test */
public function it_can_get_storage_path(): void
{
$this->assertNull($this->release->getStoragePath());

$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . 'tmp/releaseName.zip';
$this->release->setStoragePath( $storagePath );
$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp/releaseName.zip';
$this->release->setStoragePath($storagePath);

$this->assertEquals( $storagePath, $this->release->getStoragePath() );
$this->assertEquals($storagePath, $this->release->getStoragePath());
}

/** @test */
public function it_can_update_storage_path_when_having_release_name(): void
{
$releaseName = 'releaseName';
$storagePathWithoutFilename = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . 'tmp';
$storagePathWithoutFilename = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp';

$this->release->setStoragePath($storagePathWithoutFilename);
$this->assertEquals($storagePathWithoutFilename, $this->release->getStoragePath());

$this->release->setRelease($releaseName)->updateStoragePath();
$this->assertEquals(
Str::finish($storagePathWithoutFilename, DIRECTORY_SEPARATOR) . $releaseName,
Str::finish($storagePathWithoutFilename, DIRECTORY_SEPARATOR).$releaseName,
$this->release->getStoragePath()
);
}

/** @test */
public function it_should_not_update_storage_path_when_not_having_release_name(): void
{
$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . 'tmp';
$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'tmp';

$this->release->setStoragePath($storagePath);
$this->assertEquals($storagePath, $this->release->getStoragePath());
Expand All @@ -87,11 +90,11 @@ public function it_can_set_update_path_without_exclude_dirs(): void
$mainDirectory = '/tmp';
$subDirectory = 'new-directory-inside';

vfsStream::newDirectory($mainDirectory . '/' . $subDirectory)->at($this->vfs);
$this->release->setUpdatePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . $mainDirectory);
vfsStream::newDirectory($mainDirectory.'/'.$subDirectory)->at($this->vfs);
$this->release->setUpdatePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).$mainDirectory);

foreach ($this->release->getUpdatePath()->directories() as $dir) {
$this->assertEquals($dir->getPath(), $this->vfs->url() . '/' . $mainDirectory);
$this->assertEquals($dir->getPath(), $this->vfs->url().'/'.$mainDirectory);
$this->assertEquals($subDirectory, $dir->getFilename());
$this->assertEquals($subDirectory, $dir->getBasename());
}
Expand Down Expand Up @@ -139,8 +142,8 @@ public function it_can_extract_zip_to_storage_path(): void
$zip = new \ZipArchive();
$res = $zip->open($this->release->getStoragePath(), \ZipArchive::CREATE);

if($res === true) {
$zip->addFile(__DIR__ . '/../Data/releases-branch.json');
if ($res === true) {
$zip->addFile(__DIR__.'/../Data/releases-branch.json');
$zip->close();

$this->assertTrue($this->release->extract());
Expand Down Expand Up @@ -183,7 +186,7 @@ public function it_can_download(): void
/** @test */
public function it_checks_source_is_not_fetched(): void
{
$this->release->setStoragePath($this->vfs->url() . 'release-1.2.zip');
$this->release->setStoragePath($this->vfs->url().'release-1.2.zip');

$this->assertFalse($this->release->isSourceAlreadyFetched());
}
Expand All @@ -192,7 +195,7 @@ public function it_checks_source_is_not_fetched(): void
public function it_checks_source_is_already_fetched_but_not_extracted(): void
{
$file = 'release-1.2.zip';
$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . $file;
$storagePath = Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).$file;
vfsStream::newFile($file)->at($this->vfs);

$this->release->setStoragePath($storagePath);
Expand All @@ -204,7 +207,7 @@ public function it_checks_source_is_already_fetched_but_not_extracted(): void
public function it_checks_source_is_already_extracted_and_directory_still_present(): void
{
vfsStream::newDirectory('release-1.2')->at($this->vfs);
$this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . 'release-1.2.zip');
$this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'release-1.2.zip');

$this->assertTrue($this->release->isSourceAlreadyFetched());
}
Expand All @@ -213,7 +216,7 @@ public function it_checks_source_is_already_extracted_and_directory_still_presen
public function it_checks_source_is_already_extracted_and_directory_deleted(): void
{
vfsStream::newDirectory('release-1.2')->at($this->vfs);
$this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR) . 'release-1.2.zip');
$this->release->setStoragePath(Str::finish($this->vfs->url(), DIRECTORY_SEPARATOR).'release-1.2.zip');
$this->vfs->getChild('release-1.2.zip')->rename('removed');

$this->assertTrue($this->release->isSourceAlreadyFetched());
Expand Down
32 changes: 17 additions & 15 deletions tests/Models/UpdateExecutorTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Codedge\Updater\Tests\Models;

Expand Down Expand Up @@ -36,7 +38,7 @@ protected function setUp(): void
/** @test */
public function it_can_run_successfully(): void
{
$dir = (string) config('self-update.repository_types.github.download_path') . '/update-dir';
$dir = (string) config('self-update.repository_types.github.download_path').'/update-dir';
File::makeDirectory($dir, 0775, true, true);

$client = $this->getMockedClient([
Expand All @@ -56,17 +58,17 @@ public function it_can_run_successfully(): void
Event::fake();

$this->assertTrue($updateExecutor->run($this->release));
$this->assertTrue(File::exists($dir . '/.some-hidden-file'));
$this->assertTrue(File::exists($dir . '/outer-file.txt'));
$this->assertTrue(File::exists($dir . '/folder1'));
$this->assertEmpty(File::allFiles($dir . '/folder1'));
$this->assertTrue(File::exists($dir . '/folder2'));
$this->assertTrue(File::exists($dir . '/folder2/samplefile-in-folder2.txt'));
$this->assertEquals(1, count(File::allFiles($dir . '/folder2')));
$this->assertFalse(File::exists($dir . '/node_modules'));
$this->assertFalse(File::exists($dir . '/__MACOSX'));
$this->assertFalse(File::exists($dir . '/release-1.2'));
$this->assertFalse(File::exists($dir . '/release-1.2.zip'));
$this->assertTrue(File::exists($dir.'/.some-hidden-file'));
$this->assertTrue(File::exists($dir.'/outer-file.txt'));
$this->assertTrue(File::exists($dir.'/folder1'));
$this->assertEmpty(File::allFiles($dir.'/folder1'));
$this->assertTrue(File::exists($dir.'/folder2'));
$this->assertTrue(File::exists($dir.'/folder2/samplefile-in-folder2.txt'));
$this->assertEquals(1, count(File::allFiles($dir.'/folder2')));
$this->assertFalse(File::exists($dir.'/node_modules'));
$this->assertFalse(File::exists($dir.'/__MACOSX'));
$this->assertFalse(File::exists($dir.'/release-1.2'));
$this->assertFalse(File::exists($dir.'/release-1.2.zip'));

Event::assertDispatched(UpdateSucceeded::class, 1);
Event::assertNotDispatched(UpdateFailed::class);
Expand All @@ -78,11 +80,11 @@ public function it_can_run_and_fail(): void
vfsStream::newDirectory('updateDirectory')->at($this->vfs);
vfsStream::newFile('sample-file', 0500)->at($this->vfs->getChild('updateDirectory'));

$this->release->setUpdatePath($this->vfs->url() . '/updateDirectory');
$this->release->setUpdatePath($this->vfs->url().'/updateDirectory');

Event::fake();

$this->assertFalse((new UpdateExecutor())->setBasePath($this->vfs->url() . '/updateDirectory')->run($this->release));
$this->assertFalse((new UpdateExecutor())->setBasePath($this->vfs->url().'/updateDirectory')->run($this->release));

Event::assertDispatched(UpdateFailed::class, 1);
Event::assertNotDispatched(UpdateSucceeded::class);
Expand Down
6 changes: 3 additions & 3 deletions tests/Notifications/EventHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php declare(strict_types=1);
<?php

namespace Codedge\Updater\Tests\Notifications;
declare(strict_types=1);

namespace Codedge\Updater\Tests\Notifications;

use Codedge\Updater\Events\UpdateFailed;
use Codedge\Updater\Models\Release;
Expand Down Expand Up @@ -59,5 +60,4 @@ protected function fireUpdateFailedEvent()

event(new UpdateFailed($release));
}

}
Loading

0 comments on commit f16f7d2

Please sign in to comment.