Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Jul 7, 2023
1 parent 0aed5b8 commit 586d484
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor/

composer.lock
tests/_output
tests/_support/_generated
tests/_support/_generated
tests/_data/**/.puprc
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"test -f ./bin/box.phar || curl -o bin/box.phar -L -C - https://github.com/box-project/box/releases/download/3.16.0/box.phar",
"@php bin/box.phar build"
],
"cr": [
"vendor/bin/codecept run "
],
"test:analysis": [
"phpstan analyse -c phpstan.neon.dist --memory-limit=512M"
]
Expand Down
42 changes: 24 additions & 18 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ This is what you should add as a `paths.versions` entry:

```json
{
"paths": [
{
"file": "readme.txt",
"regex": "^(Stable tag: +)(.+)"
}
]
"paths": {
"versions": [
{
"file": "readme.txt",
"regex": "^(Stable tag: +)(.+)"
}
]
}
}
```

Expand All @@ -89,12 +91,14 @@ This is what you should add as a `paths.versions` entry:

```json
{
"paths": [
{
"file": "bootstrap.php",
"regex": "(define\\( +'MY_PLUGIN_VERSION', +')([^']+)"
}
]
"paths": {
"versions": [
{
"file": "bootstrap.php",
"regex": "(define\\( +['\"]MY_PLUGIN_VERSION['\"], +['\"])([^'\"]+)"
}
]
}
}
```

Expand Down Expand Up @@ -123,11 +127,13 @@ This is what you should add as a `paths.versions` entry:

```json
{
"paths": [
{
"file": "src/MyPlugin/Plugin.php",
"regex": "(const +VERSION += +')([^']+)"
}
]
"paths": {
"versions": [
{
"file": "src/MyPlugin/Plugin.php",
"regex": "(const +VERSION += +['\"])([^'\"]+)"
}
]
}
}
```
11 changes: 8 additions & 3 deletions pup
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ if ( ! \Phar::running() ) {
require __PUP_DIR__ . '/vendor/autoload.php';
}

App::getConfig();
$app = App::instance();
$app->run();
try {
App::getConfig();
$app = App::instance();
$app->run();
} catch ( \Exception $e ) {
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
exit( 1 );
}
6 changes: 4 additions & 2 deletions src/Commands/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use StellarWP\Pup\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use const StellarWP\Pup\PUP_VERSION;

class Help extends Command {
/**
Expand Down Expand Up @@ -111,6 +109,10 @@ protected function printCommandHelp( string $topic ): void {
$arguments_lines = [];

foreach ( (array) $docs as $doc_line ) {
if ( ! is_string( $doc_line ) ) {
continue;
}

if ( $start ) {
if ( preg_match( '/##+\s+`pup /', $doc_line ) ) {
break;
Expand Down
23 changes: 0 additions & 23 deletions tests/_data/fake-project/.puprc

This file was deleted.

54 changes: 54 additions & 0 deletions tests/cli/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,59 @@ class AbstractBase {

public function _before( CliTester $I ) {
$this->pup = dirname( dirname( __DIR__ ) ) . '/pup';
$this->rm_puprc( 'fake-project' );
}

/**
* @param array $data
*
* @return array
*/
protected function get_puprc( array $data = [] ) {
$defaults = [
'build' => [
"ls -al",
],
"paths" => [
"versions" => [
[
"file" => "bootstrap.php",
"regex" => "(define\\( +['\"]FAKE_PROJECT_VERSION['\"], +['\"])([^'\"]+)",
],
[
"file" => "bootstrap.php",
"regex" => "(Version: )(.+)",
],
[
"file" => "src/Plugin.php",
"regex" => "(const VERSION = ['\"])([^'\"]+)",
],
],
],
];

return array_merge( $defaults, $data );
}

/**
* Removes the .puprc from the provided project in _data.
*
* @param array $puprc
*
* @return void
*/
protected function rm_puprc( $project = 'fake-project' ): void {
@unlink( dirname( __DIR__ ) . '/_data/' . $project . '/.puprc' );
}

/**
* Writes the .puprc to the provided project in _data.
*
* @param array $puprc
*
* @return void
*/
protected function write_puprc( array $puprc, $project = 'fake-project' ): void {
file_put_contents( dirname( __DIR__ ) . '/_data/' . $project . '/.puprc', json_encode( $puprc ) );
}
}
35 changes: 34 additions & 1 deletion tests/cli/BuildCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,48 @@ public function _before( CliTester $I ) {
parent::_before( $I );
}


/**
* @test
*/
public function it_should_run_build( CliTester $I ) {
$puprc = $this->get_puprc();
$puprc['build'][] = 'echo "fake project, yo"';
$this->write_puprc( $puprc );

chdir( dirname( __DIR__ ) . '/_data/fake-project' );

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

/**
* @test
*/
public function it_should_run_no_build_steps_when_not_set_in_puprc( CliTester $I ) {
$puprc = $this->get_puprc();
unset( $puprc['build'] );
$this->write_puprc( $puprc );

chdir( dirname( __DIR__ ) . '/_data/fake-project' );

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

/**
* @test
*/
public function it_should_run_no_build_steps_when_missing_puprc( CliTester $I ) {
chdir( dirname( __DIR__ ) . '/_data/fake-project' );
$I->runShellCommand( "php {$this->pup} build" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'Build complete.' );
$I->dontSeeInShellOutput( 'drwxr-xr-x' );
$I->dontSeeInShellOutput( 'fake project, yo' );
}
}

0 comments on commit 586d484

Please sign in to comment.