Skip to content

Commit

Permalink
Adding snapshots for help commands
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Jul 7, 2023
1 parent 586d484 commit 598ecbf
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 9 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"codeception/codeception": "^4.2",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-cli": "^2.0"
"codeception/module-cli": "^2.0",
"lucatume/codeception-snapshot-assertions": "^0.2.4"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* [`pup zip`](/docs/commands.md#pup-zip)

## `pup build`
Runs the `build` commands from the `puprc` file.
Runs the `build` commands from the `.puprc` file.

If you want your dev builds to build differently, you can add a `build_dev` property to your `.puprc` file.

Expand Down
4 changes: 3 additions & 1 deletion tests/cli/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use StellarWP\Pup\Tests\CliTester;

class AbstractBase {
use \tad\Codeception\SnapshotAssertions\SnapshotAssertions;

protected $pup;

public function _before( CliTester $I ) {
Expand All @@ -20,7 +22,7 @@ public function _before( CliTester $I ) {
protected function get_puprc( array $data = [] ) {
$defaults = [
'build' => [
"ls -al",
"ls -a",
],
"paths" => [
"versions" => [
Expand Down
18 changes: 15 additions & 3 deletions tests/cli/BuildCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ public function it_should_run_build( CliTester $I ) {

$I->runShellCommand( "php {$this->pup} build" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'drwxr-xr-x' );
$I->seeInShellOutput( '.puprc' );
$I->seeInShellOutput( 'bootstrap.php' );
$I->seeInShellOutput( 'fake project, yo' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

/**
Expand All @@ -38,8 +42,12 @@ public function it_should_run_no_build_steps_when_not_set_in_puprc( CliTester $I
$I->runShellCommand( "php {$this->pup} build" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'Build complete.' );
$I->dontSeeInShellOutput( 'drwxr-xr-x' );
$I->dontSeeInShellOutput( '.puprc' );
$I->dontSeeInShellOutput( 'bootstrap.php' );
$I->dontSeeInShellOutput( 'fake project, yo' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

/**
Expand All @@ -50,7 +58,11 @@ public function it_should_run_no_build_steps_when_missing_puprc( CliTester $I )
$I->runShellCommand( "php {$this->pup} build" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'Build complete.' );
$I->dontSeeInShellOutput( 'drwxr-xr-x' );
$I->dontSeeInShellOutput( '.puprc' );
$I->dontSeeInShellOutput( 'bootstrap.php' );
$I->dontSeeInShellOutput( 'fake project, yo' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}
}
14 changes: 11 additions & 3 deletions tests/cli/HelpCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public function it_should_default_to_help( CliTester $I ) {
$I->runShellCommand( "php {$this->pup}" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'A CLI utility' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

/**
Expand All @@ -27,16 +30,21 @@ public function it_should_run_help( CliTester $I ) {
$I->runShellCommand( "php {$this->pup} help" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'A CLI utility' );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

/**
* @test
* @dataProvider topicProvider
*/
public function it_should_show_build_docs( CliTester $I, Example $example ) {
$I->runShellCommand( "php {$this->pup} help {$example['topic']}" );
public function it_should_show_topic_docs( CliTester $I, Example $example ) {
$I->runShellCommand( "php {$this->pup} help build" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'pup ' . $example['topic'] );

$output = $I->grabShellOutput();
$this->assertMatchesStringSnapshot( $output );
}

protected function topicProvider(): array {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Running build steps...

> ls -a
-------

.
..
.puprc
bootstrap.php
src

> echo "fake project, yo"
-------------------------

fake project, yo

Build complete.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Running build steps...
Build complete.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Running build steps...
Build complete.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
********************************************************************************
*
* Product Utility & Packager
* ------------------------------------------------------------------------------
* A CLI utility by StellarWP
*
********************************************************************************

Run pup help <topic> for more information on a specific command.

------------------------ -------------------------------------------------------------------------------
Command Description
------------------------ -------------------------------------------------------------------------------
build Runs the build commands from the .puprc file.
check:tbd Scans your files for tbd (case-insensitive) and tells you where to find them.
check:version-conflict Verifies that all of your version numbers match.
check Runs all registered check commands.
clean This command cleans up any directories that pup creates.
get-version Gets your project's version number.
help Shows the help menu.
package Packages your project into a zip file with the passed in version number.
zip Runs the full pup set of commands to create a zip file.
------------------------ -------------------------------------------------------------------------------


For more documentation, head over to https://github.com/stellarwp/pup
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
********************************************************************************
*
* Product Utility & Packager
* ------------------------------------------------------------------------------
* A CLI utility by StellarWP
*
********************************************************************************

Run pup help <topic> for more information on a specific command.

------------------------ -------------------------------------------------------------------------------
Command Description
------------------------ -------------------------------------------------------------------------------
build Runs the build commands from the .puprc file.
check:tbd Scans your files for tbd (case-insensitive) and tells you where to find them.
check:version-conflict Verifies that all of your version numbers match.
check Runs all registered check commands.
clean This command cleans up any directories that pup creates.
get-version Gets your project's version number.
help Shows the help menu.
package Packages your project into a zip file with the passed in version number.
zip Runs the full pup set of commands to create a zip file.
------------------------ -------------------------------------------------------------------------------


For more documentation, head over to https://github.com/stellarwp/pup
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

Help: pup build
===============

Runs the build commands from the .puprc file.


If you want your dev builds to build differently, you can add a build_dev property to your .puprc file.

> Usage:
--------

..................................................
pup build [--dev]
# or
composer pup build [--dev]
..................................................

> Arguments:
------------

---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
Argument Description
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
--dev Optional. Whether or not this is a dev build. Using this option will run the build_dev commands from your .puprc file if they exist, otherwise it will run build commands.
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --


> Specifying build commands:
----------------------------

You can specify build commands within your .puprc file by adding to either the build or build_dev properties. These
commands will be run in the order they are specified. By default, if any command fails, the build will fail. You can,
however, prepend your commands with @ and that will tell pup to ignore failures for that step. Here's an example:

..................................................
{
"build": [
"npm ci",
"npm run build",
"@composer run some-script"
]
}
..................................................

In the above example, npm ci and npm run build will need to complete successfully for the build to succeed, but the
composer run some-script is prepended by @ so if it fails, the build will continue forward.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

Help: pup build
===============

Runs the build commands from the .puprc file.


If you want your dev builds to build differently, you can add a build_dev property to your .puprc file.

> Usage:
--------

..................................................
pup build [--dev]
# or
composer pup build [--dev]
..................................................

> Arguments:
------------

---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
Argument Description
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
--dev Optional. Whether or not this is a dev build. Using this option will run the build_dev commands from your .puprc file if they exist, otherwise it will run build commands.
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --


> Specifying build commands:
----------------------------

You can specify build commands within your .puprc file by adding to either the build or build_dev properties. These
commands will be run in the order they are specified. By default, if any command fails, the build will fail. You can,
however, prepend your commands with @ and that will tell pup to ignore failures for that step. Here's an example:

..................................................
{
"build": [
"npm ci",
"npm run build",
"@composer run some-script"
]
}
..................................................

In the above example, npm ci and npm run build will need to complete successfully for the build to succeed, but the
composer run some-script is prepended by @ so if it fails, the build will continue forward.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

Help: pup build
===============

Runs the build commands from the .puprc file.


If you want your dev builds to build differently, you can add a build_dev property to your .puprc file.

> Usage:
--------

..................................................
pup build [--dev]
# or
composer pup build [--dev]
..................................................

> Arguments:
------------

---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
Argument Description
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
--dev Optional. Whether or not this is a dev build. Using this option will run the build_dev commands from your .puprc file if they exist, otherwise it will run build commands.
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --


> Specifying build commands:
----------------------------

You can specify build commands within your .puprc file by adding to either the build or build_dev properties. These
commands will be run in the order they are specified. By default, if any command fails, the build will fail. You can,
however, prepend your commands with @ and that will tell pup to ignore failures for that step. Here's an example:

..................................................
{
"build": [
"npm ci",
"npm run build",
"@composer run some-script"
]
}
..................................................

In the above example, npm ci and npm run build will need to complete successfully for the build to succeed, but the
composer run some-script is prepended by @ so if it fails, the build will continue forward.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

Help: pup build
===============

Runs the build commands from the .puprc file.


If you want your dev builds to build differently, you can add a build_dev property to your .puprc file.

> Usage:
--------

..................................................
pup build [--dev]
# or
composer pup build [--dev]
..................................................

> Arguments:
------------

---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
Argument Description
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
--dev Optional. Whether or not this is a dev build. Using this option will run the build_dev commands from your .puprc file if they exist, otherwise it will run build commands.
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --


> Specifying build commands:
----------------------------

You can specify build commands within your .puprc file by adding to either the build or build_dev properties. These
commands will be run in the order they are specified. By default, if any command fails, the build will fail. You can,
however, prepend your commands with @ and that will tell pup to ignore failures for that step. Here's an example:

..................................................
{
"build": [
"npm ci",
"npm run build",
"@composer run some-script"
]
}
..................................................

In the above example, npm ci and npm run build will need to complete successfully for the build to succeed, but the
composer run some-script is prepended by @ so if it fails, the build will continue forward.
Loading

0 comments on commit 598ecbf

Please sign in to comment.