Skip to content

Commit

Permalink
adjust mock
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Jan 5, 2024
1 parent 5f9acb4 commit 5bd2163
Showing 1 changed file with 65 additions and 60 deletions.
125 changes: 65 additions & 60 deletions tests/Git/GitEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public function setUp(): void
Storage::fake('test');

Git::shouldReceive('statuses');
Git::shouldReceive('as')->with($this->user);
}

/** @test */
public function it_doesnt_commit_when_git_is_disabled()
{
Git::shouldReceive('dispatchCommit')->with('Collection saved', $this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted', $this->user)->never();
Git::shouldReceive('as')->with($this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection saved')->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted')->never();

Config::set('statamic.git.enabled', false);

Expand All @@ -68,8 +70,9 @@ public function it_doesnt_commit_when_git_is_disabled()
/** @test */
public function it_doesnt_commit_when_automatic_is_disabled()
{
Git::shouldReceive('dispatchCommit')->with('Collection saved', $this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted', $this->user)->never();
Git::shouldReceive('as')->with($this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection saved')->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted')->never();

Config::set('statamic.git.automatic', false);

Expand All @@ -82,8 +85,9 @@ public function it_doesnt_commit_when_automatic_is_disabled()
/** @test */
public function it_doesnt_commit_ignored_events()
{
Git::shouldReceive('dispatchCommit')->with('Collection saved', $this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted', $this->user)->once();
Git::shouldReceive('as')->with($this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection saved')->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted')->once();

Config::set('statamic.git.ignored_events', [
\Statamic\Events\CollectionSaved::class,
Expand All @@ -98,8 +102,9 @@ public function it_doesnt_commit_ignored_events()
/** @test */
public function it_doesnt_commit_when_event_subscriber_is_disabled()
{
Git::shouldReceive('dispatchCommit')->with('Collection saved', $this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted', $this->user)->once();
Git::shouldReceive('as')->with($this->user)->never();
Git::shouldReceive('dispatchCommit')->with('Collection saved')->never();
Git::shouldReceive('dispatchCommit')->with('Collection deleted')->once();

$collection = Facades\Collection::make('pages');

Expand All @@ -113,7 +118,7 @@ public function it_doesnt_commit_when_event_subscriber_is_disabled()
/** @test */
public function it_commits_when_custom_addon_events_are_registered()
{
Git::shouldReceive('dispatchCommit')->with('Pun saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Pun saved')->once();
Git::makePartial();

Git::listen(PunSaved::class);
Expand All @@ -128,8 +133,8 @@ public function it_commits_when_custom_addon_events_are_registered()
/** @test */
public function it_commits_when_blueprint_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Blueprint saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Blueprint deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Blueprint saved')->once();
Git::shouldReceive('dispatchCommit')->with('Blueprint deleted')->once();

$blueprint = Facades\Blueprint::make('post');

Expand All @@ -140,8 +145,8 @@ public function it_commits_when_blueprint_is_saved_and_deleted()
/** @test */
public function it_commits_when_fieldset_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Fieldset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Fieldset deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Fieldset saved')->once();
Git::shouldReceive('dispatchCommit')->with('Fieldset deleted')->once();

$fieldset = Facades\Fieldset::make('address');

Expand All @@ -152,8 +157,8 @@ public function it_commits_when_fieldset_is_saved_and_deleted()
/** @test */
public function it_commits_when_collection_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Collection saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Collection deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Collection saved')->once();
Git::shouldReceive('dispatchCommit')->with('Collection deleted')->once();

$collection = Facades\Collection::make('pages');

Expand All @@ -168,8 +173,8 @@ public function it_commits_when_entry_is_saved_and_deleted()
Events\CollectionSaved::class,
]);

Git::shouldReceive('dispatchCommit')->with('Entry saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Entry deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Entry saved')->once();
Git::shouldReceive('dispatchCommit')->with('Entry deleted')->once();

$collection = Facades\Collection::make('pages');
$collection->save();
Expand All @@ -191,8 +196,8 @@ public function it_commits_when_tracked_revisions_are_saved_and_deleted()

Config::set('statamic.revisions.path', base_path('content/revisions'));

Git::shouldReceive('dispatchCommit')->with('Revision saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Revision deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Revision saved')->once();
Git::shouldReceive('dispatchCommit')->with('Revision deleted')->once();

$collection = Facades\Collection::make('pages');
$collection->save();
Expand All @@ -208,8 +213,8 @@ public function it_commits_when_tracked_revisions_are_saved_and_deleted()
/** @test */
public function it_commits_when_navigation_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Navigation saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Navigation deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Navigation saved')->once();
Git::shouldReceive('dispatchCommit')->with('Navigation deleted')->once();

$nav = Facades\Nav::make()->handle('footer');

Expand All @@ -220,8 +225,8 @@ public function it_commits_when_navigation_is_saved_and_deleted()
/** @test */
public function it_commits_when_a_navigation_tree_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Navigation tree saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Navigation tree deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Navigation tree saved')->once();
Git::shouldReceive('dispatchCommit')->with('Navigation tree deleted')->once();

$nav = Facades\Nav::make()->handle('footer');
$tree = $nav->makeTree('en');
Expand All @@ -237,8 +242,8 @@ public function it_commits_when_a_collection_tree_is_saved_and_deleted()
Events\CollectionSaved::class,
]);

Git::shouldReceive('dispatchCommit')->with('Collection tree saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Collection tree deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Collection tree saved')->once();
Git::shouldReceive('dispatchCommit')->with('Collection tree deleted')->once();

$collection = Facades\Collection::make('pages')->structureContents(['max_depth' => 10])->save();
$tree = $collection->structure()->makeTree('en');
Expand All @@ -250,8 +255,8 @@ public function it_commits_when_a_collection_tree_is_saved_and_deleted()
/** @test */
public function it_commits_when_taxonomy_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Taxonomy saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Taxonomy deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Taxonomy saved')->once();
Git::shouldReceive('dispatchCommit')->with('Taxonomy deleted')->once();

$taxonomy = Facades\Taxonomy::make('topics');

Expand All @@ -266,8 +271,8 @@ public function it_commits_when_term_is_saved_and_deleted()
Events\TaxonomySaved::class,
]);

Git::shouldReceive('dispatchCommit')->with('Term saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Term deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Term saved')->once();
Git::shouldReceive('dispatchCommit')->with('Term deleted')->once();

$taxonomy = Facades\Taxonomy::make('topics');
$taxonomy->save();
Expand All @@ -284,8 +289,8 @@ public function it_commits_when_term_is_saved_and_deleted()
/** @test */
public function it_commits_when_global_set_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Global Set saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Global Set deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Global Set saved')->once();
Git::shouldReceive('dispatchCommit')->with('Global Set deleted')->once();

$set = Facades\GlobalSet::make('main');
$set->addLocalization($set->makeLocalization(Facades\Site::default()->handle()));
Expand All @@ -297,8 +302,8 @@ public function it_commits_when_global_set_is_saved_and_deleted()
/** @test */
public function it_commits_when_form_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Form saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Form deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Form saved')->once();
Git::shouldReceive('dispatchCommit')->with('Form deleted')->once();

$form = Facades\Form::make('main');

Expand All @@ -313,8 +318,8 @@ public function it_commits_when_form_submission_is_saved_and_deleted()
Events\FormSaved::class,
]);

Git::shouldReceive('dispatchCommit')->with('Submission saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Submission deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Submission saved')->once();
Git::shouldReceive('dispatchCommit')->with('Submission deleted')->once();

$form = Facades\Form::make('contact');

Expand All @@ -329,8 +334,8 @@ public function it_commits_when_form_submission_is_saved_and_deleted()
/** @test */
public function it_commits_when_user_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('User saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('User deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('User saved')->once();
Git::shouldReceive('dispatchCommit')->with('User deleted')->once();

$user = Facades\User::make();

Expand All @@ -341,8 +346,8 @@ public function it_commits_when_user_is_saved_and_deleted()
/** @test */
public function it_commits_when_user_role_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Role saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Role deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Role saved')->once();
Git::shouldReceive('dispatchCommit')->with('Role deleted')->once();

$role = Facades\Role::make()->handle('author');

Expand All @@ -353,8 +358,8 @@ public function it_commits_when_user_role_is_saved_and_deleted()
/** @test */
public function it_commits_when_user_group_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('User group saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('User group deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('User group saved')->once();
Git::shouldReceive('dispatchCommit')->with('User group deleted')->once();

$group = Facades\UserGroup::make()->handle('admin');

Expand All @@ -365,7 +370,7 @@ public function it_commits_when_user_group_is_saved_and_deleted()
/** @test */
public function it_commits_when_default_user_preferences_are_saved()
{
Git::shouldReceive('dispatchCommit')->with('Default preferences saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Default preferences saved')->once();

Facades\Preference::default()->set('foo', 'bar')->save();

Expand All @@ -375,8 +380,8 @@ public function it_commits_when_default_user_preferences_are_saved()
/** @test */
public function it_commits_when_asset_container_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Asset container saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset container deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset container saved')->once();
Git::shouldReceive('dispatchCommit')->with('Asset container deleted')->once();

$container = Facades\AssetContainer::make()->handle('assets');

Expand All @@ -387,8 +392,8 @@ public function it_commits_when_asset_container_is_saved_and_deleted()
/** @test */
public function it_commits_when_asset_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();
Git::shouldReceive('dispatchCommit')->with('Asset deleted')->once();

$asset = $this->makeAsset()->data(['bar' => 'baz']);

Expand All @@ -399,7 +404,7 @@ public function it_commits_when_asset_is_saved_and_deleted()
/** @test */
public function it_commits_when_asset_is_uploaded()
{
Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();

$this->makeAsset()->upload(
UploadedFile::fake()->create('asset.txt')
Expand All @@ -409,7 +414,7 @@ public function it_commits_when_asset_is_uploaded()
/** @test */
public function it_commits_when_asset_is_reuploaded()
{
Git::shouldReceive('dispatchCommit')->with('Asset reuploaded', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset reuploaded')->once();

$file = Mockery::mock(ReplacementFile::class);
$file->shouldReceive('extension')->andReturn('txt');
Expand All @@ -421,7 +426,7 @@ public function it_commits_when_asset_is_reuploaded()
/** @test */
public function it_commits_when_asset_is_moved()
{
Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();

$asset = tap($this->makeAsset()->data(['bar' => 'baz']))->saveQuietly();

Expand All @@ -431,7 +436,7 @@ public function it_commits_when_asset_is_moved()
/** @test */
public function it_commits_when_asset_is_renamed()
{
Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();

$asset = tap($this->makeAsset()->data(['bar' => 'baz']))->saveQuietly();

Expand All @@ -443,7 +448,7 @@ public function it_commits_only_once_when_asset_is_replaced()
{
$originalAsset = tap($this->makeAsset())->saveQuietly();

Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();

$newAsset = $this->makeAsset()->upload(
UploadedFile::fake()->create('asset.txt')
Expand All @@ -457,13 +462,13 @@ public function it_commits_when_replaced_asset_is_deleted()
{
$originalAsset = tap($this->makeAsset())->saveQuietly();

Git::shouldReceive('dispatchCommit')->with('Asset saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset saved')->once();

$newAsset = $this->makeAsset()->upload(
UploadedFile::fake()->create('asset.txt')
);

Git::shouldReceive('dispatchCommit')->with('Asset deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset deleted')->once();

// Replace with `$deleteOriginal = true`
$newAsset->replace($originalAsset, true);
Expand All @@ -472,8 +477,8 @@ public function it_commits_when_replaced_asset_is_deleted()
/** @test */
public function it_commits_when_asset_folder_is_saved_and_deleted()
{
Git::shouldReceive('dispatchCommit')->with('Asset folder saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset folder deleted', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset folder saved')->once();
Git::shouldReceive('dispatchCommit')->with('Asset folder deleted')->once();

$folder = $this
->makeAsset()
Expand Down Expand Up @@ -532,8 +537,8 @@ public function it_batches_term_references_changes_into_one_commit()
->saveQuietly();
}

Git::shouldReceive('dispatchCommit')->with('Term references updated', $this->user)->once(); // Ensure references updated event gets fired
Git::shouldReceive('dispatchCommit')->with('Entry saved', $this->user)->never(); // Ensure individual entry saved events do not get fired
Git::shouldReceive('dispatchCommit')->with('Term references updated')->once(); // Ensure references updated event gets fired
Git::shouldReceive('dispatchCommit')->with('Entry saved')->never(); // Ensure individual entry saved events do not get fired

$term->slug('leia-updated')->save();
}
Expand Down Expand Up @@ -580,15 +585,15 @@ public function it_batches_asset_references_changes_into_one_commit()
->saveQuietly();
}

Git::shouldReceive('dispatchCommit')->with('Asset references updated', $this->user)->once(); // Ensure references updated event gets fired
Git::shouldReceive('dispatchCommit')->with('Entry saved', $this->user)->never(); // Ensure individual entry saved events do not get fired
Git::shouldReceive('dispatchCommit')->with('Asset references updated')->once(); // Ensure references updated event gets fired
Git::shouldReceive('dispatchCommit')->with('Entry saved')->never(); // Ensure individual entry saved events do not get fired

$newAsset->replace($originalAsset);
}

private function makeAsset($path = 'asset.txt')
{
Git::shouldReceive('dispatchCommit')->with('Asset container saved', $this->user)->once();
Git::shouldReceive('dispatchCommit')->with('Asset container saved')->once();

$container = Facades\AssetContainer::make()->handle('assets')->disk('test');
$container->save();
Expand Down

0 comments on commit 5bd2163

Please sign in to comment.