Skip to content

Commit 163be72

Browse files
committed
fixes all tests
1 parent 20b07ae commit 163be72

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/Updater.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace nullthoughts\LaravelDataSync;
44

5+
use Illuminate\Support\Collection;
6+
use Illuminate\Support\Facades\File;
57
use Illuminate\Support\Facades\Storage;
8+
use Illuminate\Support\Str;
69
use nullthoughts\LaravelDataSync\Exceptions\ErrorUpdatingModelException;
710
use nullthoughts\LaravelDataSync\Exceptions\FileDirectoryNotFoundException;
811
use nullthoughts\LaravelDataSync\Exceptions\NoCriteriaException;
912
use nullthoughts\LaravelDataSync\Exceptions\NoRecordsInvalidJSONException;
10-
use Illuminate\Support\Collection;
11-
use Illuminate\Support\Facades\File;
12-
use Illuminate\Support\Str;
1313
use stdClass;
1414

1515
class Updater
@@ -116,7 +116,7 @@ protected function getDirectory($path)
116116
{
117117
$directory = $path ?? config('data-sync.path', base_path('sync'));
118118

119-
if (!file_exists($directory) && !$this->remote) {
119+
if ($this->directoryMissingLocally($directory) || $this->directoryMissingRemotely($directory)) {
120120
throw new FileDirectoryNotFoundException();
121121
}
122122

@@ -309,4 +309,24 @@ protected function resolveObjects(Collection $record)
309309
return [$key => $value];
310310
})->toArray();
311311
}
312+
313+
/**
314+
* @param \Illuminate\Config\Repository $directory
315+
*
316+
* @return bool
317+
*/
318+
protected function directoryMissingLocally($directory)
319+
{
320+
return !$this->remote && !file_exists($directory);
321+
}
322+
323+
/**
324+
* @param \Illuminate\Config\Repository $directory
325+
*
326+
* @return bool
327+
*/
328+
protected function directoryMissingRemotely($directory)
329+
{
330+
return $this->remote && !Storage::disk($this->disk)->exists($directory);
331+
}
312332
}

tests/Unit/UpdaterRemoteTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,20 @@ public function it_can_update_the_relationship()
7979
$this->assertTrue($supervisor->is(Roles::first()->supervisor));
8080
}
8181

82-
// /**
83-
// * @test
84-
// * @group current
85-
// */
86-
// public function exception_is_thrown_if_the_directory_does_not_exists()
87-
// {
88-
// try {
89-
// new UpdaterFake(null, null, true, 's3');
90-
//
91-
// $this->fail('exception was thrown');
92-
// } catch (Exception $e) {
93-
// $this->assertEquals('Specified sync file directory does not exist', $e->getMessage());
94-
// }
95-
// }
82+
/**
83+
* @test
84+
* @group current
85+
*/
86+
public function exception_is_thrown_if_the_directory_does_not_exists()
87+
{
88+
try {
89+
new UpdaterFake(null, null, true, 's3');
90+
91+
$this->fail('exception was thrown');
92+
} catch (Exception $e) {
93+
$this->assertEquals('Specified sync file directory does not exist', $e->getMessage());
94+
}
95+
}
9696

9797
/** @test */
9898
public function invalid_json_throws_an_exception()

0 commit comments

Comments
 (0)