Skip to content

Commit

Permalink
Sort config values
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondfrancis committed Aug 4, 2021
1 parent ed4589d commit 5082ca5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.2.2 - 2021-08-04
- Fixed: Triggers are now sorted to provide more stability across machines.

## 0.2.1 - 2021-07-22
- Added `exclude_names` to both the FileTrigger and output config. This will let you ignore filenames, regardless of what folder they show up in. E.g. `.DS_Store`

Expand Down
7 changes: 6 additions & 1 deletion src/HashGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ public function asArray()
foreach ($this->triggers as $class => $config) {
$this->ensureContractImplemented($class);

$contents[$class] = app($class)->triggerBuildWhenChanged($config);
$values = app($class)->triggerBuildWhenChanged($config);
ksort($values);

$contents[$class] = $values;
}

ksort($contents);

return $contents;
}

Expand Down
38 changes: 38 additions & 0 deletions tests/HashCalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Hammerstone\Airdrop\Tests;

use Hammerstone\Airdrop\HashGenerator;
use Hammerstone\Airdrop\Triggers\ConfigTrigger;
use Hammerstone\Airdrop\Triggers\FileTrigger;

class HashCalculationTest extends BaseTest
Expand Down Expand Up @@ -33,4 +34,41 @@ public function it_tests_basic_file_hash()

$this->assertEquals('36eda7109ca99a5fb55cffefeca3c554', $hash);
}

/** @test */
public function it_gets_sorted()
{
config()->set('airdrop.triggers', [
ConfigTrigger::class => [
'a_key' => 'test',
'b_key' => 'test'
],
FileTrigger::class => [
'include' => [
base_path('tests/Support/primary-webpack.mix.example'),
base_path('tests/Support/secondary-webpack.mix.example'),
]
]
]);

$hash1 = (new HashGenerator)->generate();

config()->set('airdrop.triggers', [
FileTrigger::class => [
'include' => [
base_path('tests/Support/secondary-webpack.mix.example'),
base_path('tests/Support/primary-webpack.mix.example'),
]
],
ConfigTrigger::class => [
'b_key' => 'test',
'a_key' => 'test',
],
]);

$hash2 = (new HashGenerator)->generate();

$this->assertEquals($hash1, $hash2);

}
}

0 comments on commit 5082ca5

Please sign in to comment.