Skip to content

Commit

Permalink
Add add_exclusion/remove_exclusion method to rsync installation manag…
Browse files Browse the repository at this point in the history
…er (#517)

* Switching to symfony/css-selector package

* Switch to symfony here too

* Add add_exclusion/remove_exclusion methods and remove .buddy-tests/.composer from default exclusions

* Break out default to a standalone function for reuse

* PHPCS fix

* Rector fix
  • Loading branch information
srtfisher committed Mar 15, 2024
1 parent 0d0343f commit 252c1c4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/mantle/testing/class-installation-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Installation_Manager {
* configure the installation.
*/
public function __construct() {
$this->with_default_exclusions();

if ( Utils::env_bool( 'MANTLE_INSTALL_VIP_MU_PLUGINS', false ) ) {
$this->with_vip_mu_plugins();
}
Expand Down
73 changes: 57 additions & 16 deletions src/mantle/testing/concerns/trait-rsync-installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,26 @@ trait Rsync_Installation {
*
* @var string[]
*/
protected array $rsync_exclusions = [
'.buddy-tests',
'.buddy',
'.composer',
'.git',
'.npm',
'.phpcs',
'.turbo',
'node_modules',
'phpstan.neon',
];
protected array $rsync_exclusions = [];

/**
* Add the default set of exclusions to the list of exclusions to be used when rsyncing the codebase.
*/
public function with_default_exclusions(): static {
return $this->exclusions(
[
'.buddy',
'.git',
'.github',
'.npm',
'.phpcs',
'.turbo',
'.phpunit.result.cache',
'node_modules',
'phpstan.neon',
]
);
}

/**
* Rsync the code base to be located under a valid WordPress installation.
Expand Down Expand Up @@ -151,7 +160,7 @@ public function with_vip_mu_plugins( bool $install = true ): static {
return $this;
}

$this->rsync_exclusions[] = 'mu-plugins';
$this->add_exclusion( 'mu-plugins' );

putenv( 'MANTLE_INSTALL_VIP_MU_PLUGINS=' . ( $install ? '1' : '0' ) );

Expand All @@ -178,7 +187,7 @@ public function with_object_cache( bool $install = true ): static {
return $this;
}

$this->rsync_exclusions[] = 'object-cache.php';
$this->add_exclusion( 'object-cache.php' );

putenv( 'MANTLE_INSTALL_OBJECT_CACHE=' . ( $install ? '1' : '0' ) );

Expand All @@ -201,8 +210,12 @@ public function with_sqlite( bool $install = true ): static {
putenv( 'MANTLE_USE_SQLITE=' . ( $install ? '1' : '0' ) );
putenv( 'WP_SKIP_DB_CREATE=1' );

$this->rsync_exclusions[] = 'db.php';
$this->rsync_exclusions[] = 'sqlite-database-integration';
$this->exclusions(
[
'db.php',
'sqlite-database-integration',
]
);

return $this;
}
Expand Down Expand Up @@ -271,7 +284,35 @@ public function maybe_rsync_theme( string $name = null, string $from = null ): s
* @param bool $merge Whether to merge the exclusions with the default exclusions.
*/
public function exclusions( array $exclusions, bool $merge = true ): static {
$this->rsync_exclusions = $merge ? array_merge( $this->rsync_exclusions, $exclusions ) : $exclusions;
$this->rsync_exclusions = collect( $merge ? $this->rsync_exclusions : [] )
->merge( $exclusions )
->unique()
->values()
->all();

return $this;
}

/**
* Add an exclusion to the list of exclusions to be used when rsyncing the codebase.
*
* @param string $exclusion Exclusion to add to the list of exclusions.
*/
public function add_exclusion( string $exclusion ): static {
return $this->exclusions( [ $exclusion ], true );
}

/**
* Remove an exclusion from the list of exclusions to be used when rsyncing the codebase.
*
* @param string $exclusion Exclusion to remove from the list of exclusions.
*/
public function remove_exclusion( string $exclusion ): static {
$this->rsync_exclusions = collect( $this->rsync_exclusions )
->filter( fn ( $item ) => $item !== $exclusion )
->unique()
->values()
->all();

return $this;
}
Expand Down

0 comments on commit 252c1c4

Please sign in to comment.