Skip to content

Commit

Permalink
Release/5.2.0 (#79)
Browse files Browse the repository at this point in the history
* Add ability to pass a custom tests directory path

* Bump to 5.2.0

* Add so share <custom-wp-content-dir-name> to support custom wp-content directories.

* update autocompletion

* update so share to use the --content-dir option

* Update autocompletion
  • Loading branch information
defunctl authored Aug 17, 2021
1 parent df2189c commit fca733f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 16 deletions.
19 changes: 17 additions & 2 deletions app/Commands/LocalDocker/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Share extends BaseLocalDocker {
*
* @var string
*/
protected $signature = 'share';
protected $signature = 'share {--c|content-dir=wp-content : The name of the wp-content directory, if renamed}';

/**
* The description of the command.
Expand Down Expand Up @@ -80,7 +80,22 @@ public function handle( Config $config, Runner $runner, Filesystem $filesystem,

$source = storage_path( sprintf( 'wordpress/mu-plugins/%s', self::MU_PLUGIN ) );
$content = $filesystem->get( $source );
$target = sprintf( '%s/%s', $config->getProjectRoot(), sprintf( 'wp-content/mu-plugins/%s', self::MU_PLUGIN ) );
$target = sprintf( '%s/%s', $config->getProjectRoot(),
sprintf( '%s/mu-plugins/%s',
basename( $this->option( 'content-dir' ) ),
self::MU_PLUGIN
)
);

$targetDir = dirname( $target );

if ( ! $filesystem->exists( $targetDir ) ) {
$this->error(
sprintf( 'The directory "%s" does not exist! Does this project have a renamed wp-content folder? try "so share -c <directory-name>"', $targetDir )
);

return self::EXIT_ERROR;
}

$filesystem->replace( $target, $content );

Expand Down
15 changes: 8 additions & 7 deletions app/Commands/LocalDocker/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Commands\LocalDocker;

use App\Commands\DockerCompose;
use App\Services\Docker\Local\Config;
use App\Services\XdebugValidator;
use App\Traits\XdebugWarningTrait;
use App\Services\Docker\Local\Config;
use Illuminate\Support\Facades\Artisan;

/**
Expand All @@ -22,11 +22,12 @@ class Test extends BaseLocalDocker {
*
* @var string
*/
protected $signature = 'test {args* : arguments passed to the wp binary}
{--x|xdebug : Enable xdebug}
{--c|container=php-tests : Set the docker container to run the tests on}
{--noclean : Do not run the codecept clean command first}
{--notty : Disable interactive/tty to capture output}';
protected $signature = 'test {args* : arguments passed to the wp binary}
{--x|xdebug : Enable xdebug}
{--c|container=php-tests : Set the docker container to run the tests on}
{--p|path=/application/www/dev/tests : The path to the tests directory in the container}
{--noclean : Do not run the codecept clean command first}
{--notty : Disable interactive/tty to capture output}';

/**
* The description of the command.
Expand Down Expand Up @@ -97,7 +98,7 @@ public function handle( Config $config, XdebugValidator $xdebugValidator ): void
'php',
'/application/www/vendor/bin/codecept',
'-c',
'/application/www/dev/tests',
$this->option( 'path' ),
];

chdir( $config->getDockerDir() );
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/

//'version' => app('git.version'),
'version' => '5.1.1',
'version' => '5.2.0',

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions squareone.autocompletion
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _so()
;;

share)
opts="${opts} "
opts="${opts} --content-dir"
;;

shell)
Expand All @@ -82,7 +82,7 @@ _so()
;;

test)
opts="${opts} --xdebug --container --noclean --notty"
opts="${opts} --xdebug --container --path --noclean --notty"
;;

wp)
Expand Down
2 changes: 2 additions & 0 deletions squareone.autocompletion.fish
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ complete -c so -A -n '__fish_seen_subcommand_from list' -l short -d 'To skip des
# restart

# share
complete -c so -A -n '__fish_seen_subcommand_from share' -l content-dir -d 'The name of the wp-content directory, if renamed'

# shell
complete -c so -A -n '__fish_seen_subcommand_from shell' -l user -d 'The username or UID of the account to use'
Expand All @@ -99,6 +100,7 @@ complete -c so -A -n '__fish_seen_subcommand_from stop' -l remove-orphans -d 'Re
# test
complete -c so -A -n '__fish_seen_subcommand_from test' -l xdebug -d 'Enable xdebug'
complete -c so -A -n '__fish_seen_subcommand_from test' -l container -d 'Set the docker container to run the tests on'
complete -c so -A -n '__fish_seen_subcommand_from test' -l path -d 'The path to the tests directory in the container'
complete -c so -A -n '__fish_seen_subcommand_from test' -l noclean -d 'Do not run the codecept clean command first'
complete -c so -A -n '__fish_seen_subcommand_from test' -l notty -d 'Disable interactive/tty to capture output'

Expand Down
4 changes: 2 additions & 2 deletions squareone.autocompletion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _so()
;;

share)
opts+=()
opts+=("--content-dir:The name of the wp-content directory, if renamed")
;;

shell)
Expand All @@ -86,7 +86,7 @@ _so()
;;

test)
opts+=("--xdebug:Enable xdebug" "--container:Set the docker container to run the tests on" "--noclean:Do not run the codecept clean command first" "--notty:Disable interactive/tty to capture output")
opts+=("--xdebug:Enable xdebug" "--container:Set the docker container to run the tests on" "--path:The path to the tests directory in the container" "--noclean:Do not run the codecept clean command first" "--notty:Disable interactive/tty to capture output")
;;

wp)
Expand Down
51 changes: 51 additions & 0 deletions tests/Feature/Commands/LocalDocker/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,39 @@ public function test_it_shares_with_a_saved_ngrok_token() {
$this->assertStringNotContainsString( 'Ngrok requires a free user account to proxy to https domains.', $tester->getDisplay() );
}

public function test_it_shares_with_a_custom_content_folder_and_a_saved_ngrok_token() {
Storage::disk( 'local' )->makeDirectory( 'tests/share-test-custom-content-dir/content/mu-plugins' );

$document = new Document( $this->settings );
$document->ngrok_token = 'savedtoken';

$this->settings->shouldReceive( 'get' )->with( 'user_secrets' )->once()->andReturn( $document );

$this->config->shouldReceive( 'getProjectRoot' )->andReturn( storage_path( 'tests/share-test-custom-content-dir' ) );
$this->config->shouldReceive( 'getProjectDomain' )->andReturn( 'squareone.tribe' );

$this->runner->shouldReceive( 'run' )
->with( 'docker run --rm -it --net global_proxy --link tribe-proxy wernight/ngrok ngrok http --authtoken {{ $token }} -host-header={{ $domain }} tribe-proxy:443' )
->andReturnSelf();

$this->runner->shouldReceive( 'with' )->with( [
'domain' => 'squareone.tribe',
'token' => 'savedtoken',
] )->andReturnSelf();

$this->runner->shouldReceive( 'tty' )->with( true )->andReturnSelf();

$this->runner->shouldReceive( 'throw' )->andReturnSelf();

$command = new Share( $this->settings );
$tester = $this->runCommand( $command, [
'--content-dir' => 'content'
] );

$this->assertSame( 0, $tester->getStatusCode() );
$this->assertStringNotContainsString( 'Ngrok requires a free user account to proxy to https domains.', $tester->getDisplay() );
}

public function test_it_adds_mu_plugin_to_gitignore() {
Storage::disk( 'local' )->put( 'tests/share-test/.gitignore', '*.sql' );

Expand Down Expand Up @@ -205,4 +238,22 @@ public function test_it_bypass_git_ignore_functionality_when_it_already_exists()
$this->assertStringContainsString( '*.local.php', $contents );
}

public function test_it_shows_error_if_custom_wp_content_folder() {
Storage::disk( 'local' )->makeDirectory( 'tests/share-test-custom-content-dir/content/mu-plugins' );

$document = new Document( $this->settings );
$document->ngrok_token = 'savedtoken';

$this->settings->shouldReceive( 'get' )->with( 'user_secrets' )->once()->andReturn( $document );

$this->config->shouldReceive( 'getProjectRoot' )->andReturn( storage_path( 'tests/share-test-custom-content-dir' ) );
$this->config->shouldReceive( 'getProjectDomain' )->andReturn( 'squareone.tribe' );

$command = new Share( $this->settings );
$tester = $this->runCommand( $command );

$this->assertSame( 1, $tester->getStatusCode() );
$this->assertStringContainsString( 'try "so share -c <directory-name>"', $tester->getDisplay() );
}

}
5 changes: 3 additions & 2 deletions tests/Feature/Commands/LocalDocker/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function test_it_calls_local_test_command_with_options() {
'php',
'/application/www/vendor/bin/codecept',
'-c',
'/application/www/dev/tests',
'/application/www/other/tests',
'clean',
] );

Expand All @@ -99,7 +99,7 @@ public function test_it_calls_local_test_command_with_options() {
'php',
'/application/www/vendor/bin/codecept',
'-c',
'/application/www/dev/tests',
'/application/www/other/tests',
'run',
'integration',
] );
Expand All @@ -112,6 +112,7 @@ public function test_it_calls_local_test_command_with_options() {
'--xdebug' => true,
'--container' => 'php-fpm',
'--notty' => true,
'--path' => '/application/www/other/tests',
'args' => [
'run',
'integration',
Expand Down

0 comments on commit fca733f

Please sign in to comment.