Skip to content

Commit

Permalink
update sync tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arubacao committed Mar 4, 2018
1 parent 71ebe2e commit 53133d8
Showing 1 changed file with 83 additions and 30 deletions.
113 changes: 83 additions & 30 deletions tests/Commands/SyncCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SyncCommandTest extends TestCase
/** @test */
public function command_syncs_all_js_paths_and_deletes_css_files_to_cdn()
{
$this->seedLocalCdnFilesystem([
$this->seedCdnFilesystem([
[
'path' => 'js',
'filename' => 'back.app.js',
Expand Down Expand Up @@ -47,15 +47,12 @@ public function command_syncs_all_js_paths_and_deletes_css_files_to_cdn()
}

/** @test */
public function command_syncs_files_with_different_modified_timestamps_but_same_size()
public function command_does_not_sync_identical_sync_files()
{
$time = Carbon::createFromFormat('Y-m-d', '2017-01-01')->timestamp;

$this->seedLocalCdnFilesystem([
$this->seedCdnFilesystem([
[
'path' => 'css',
'filename' => 'front.css',
'last_modified' => $time,
],
]);

Expand All @@ -71,26 +68,38 @@ public function command_syncs_files_with_different_modified_timestamps_but_same_
'css/front.css',
];

$modifiedBeforeSync = Storage::disk('test_filesystem')
->lastModified('css/front.css');

Artisan::call('asset-cdn:sync');

$this->assertFilesExistOnCdnFilesystem($expectedFiles);

$modified = Storage::disk('test_filesystem')
$modifiedAfterSync = Storage::disk('test_filesystem')
->lastModified('css/front.css');

$this->assertNotEquals($time, $modified);
$this->assertEquals($modifiedBeforeSync, $modifiedAfterSync);
}

/** @test */
public function command_does_not_sync_files_with_same_timestamps_and_same_size()
public function command_syncs_files_with_different_size()
{
$this->seedLocalCdnFilesystem([
$src = public_path('css/front.css');
$expectedFileSize = filesize($src);

$this->seedCdnFilesystem([
[
'path' => 'css',
'filename' => 'front.css',
'base' => __DIR__.'/../testfiles/dummy',
],
]);

$this->assertNotEquals($expectedFileSize,
Storage::disk('test_filesystem')
->size('css/front.css')
);

$this->setFilesInConfig([
'include' => [
'files' => [
Expand All @@ -107,52 +116,96 @@ public function command_does_not_sync_files_with_same_timestamps_and_same_size()

$this->assertFilesExistOnCdnFilesystem($expectedFiles);

$modified = Storage::disk('test_filesystem')
->lastModified('css/front.css');
$this->assertEquals($expectedFileSize,
Storage::disk('test_filesystem')
->size('css/front.css')
);
}

/** @test */
public function command_syncs_js_file_with_same_size_but_different_hash()
{
$src = public_path('js/front.app.js');
$expectedHash = md5_file($src);

$this->seedCdnFilesystem([
[
'path' => 'js',
'filename' => 'front.app.js',
'base' => __DIR__.'/../testfiles/dummy',
],
]);

$this->assertNotEquals($expectedHash,
md5(Storage::disk('test_filesystem')
->get('js/front.app.js'))
);

$this->setFilesInConfig([
'include' => [
'files' => [
'js/front.app.js',
],
],
]);

$this->assertEquals(filemtime(public_path('css/front.css')), $modified);
$expectedFiles = [
'js/front.app.js',
];

Artisan::call('asset-cdn:sync');

$this->assertFilesExistOnCdnFilesystem($expectedFiles);

$this->assertEquals($expectedHash,
md5(Storage::disk('test_filesystem')
->get('js/front.app.js'))
);
}

/** @test */
public function command_syncs_files_with_same_modified_timestamps_but_different_size()
public function command_syncs_img_file_with_same_size_but_different_hash()
{
$src = public_path('css/front.css');
$expectedFileSize = filesize($src);
$expectedFileMTime = filemtime($src);
$src = public_path('img/layout/ph3x2.png');
$dummySrc = __DIR__.'/../testfiles/dummy/img/layout/ph3x2.png';
$expectedHash = md5_file($src);
$dummyHash = md5_file($dummySrc);

$this->seedLocalCdnFilesystem([
$this->assertEquals(filesize($src), filesize($dummySrc));
$this->assertNotEquals($expectedHash, $dummyHash);

$this->seedCdnFilesystem([
[
'path' => 'css',
'filename' => 'front.css',
'path' => 'img/layout',
'filename' => 'ph3x2.png',
'base' => __DIR__.'/../testfiles/dummy',
'last_modified' => $expectedFileMTime,
],
]);

$this->assertNotEquals($expectedFileSize,
Storage::disk('test_filesystem')
->size('css/front.css')
);
$this->assertNotEquals($expectedHash,
md5(Storage::disk('test_filesystem')
->get('img/layout/ph3x2.png'))
);

$this->setFilesInConfig([
'include' => [
'files' => [
'css/front.css',
'img/layout/ph3x2.png',
],
],
]);

$expectedFiles = [
'css/front.css',
'img/layout/ph3x2.png',
];

Artisan::call('asset-cdn:sync');

$this->assertFilesExistOnCdnFilesystem($expectedFiles);

$this->assertEquals($expectedFileSize,
Storage::disk('test_filesystem')
->size('css/front.css')
$this->assertEquals($expectedHash,
md5(Storage::disk('test_filesystem')
->get('img/layout/ph3x2.png'))
);
}

Expand Down

0 comments on commit 53133d8

Please sign in to comment.