Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
borkweb committed Jul 7, 2023
1 parent 17b2f39 commit 7744d5b
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 71 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
vendor/
*.phar

composer.lock
composer.lock
tests/_output
tests/_support/_generated
11 changes: 11 additions & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
actor: Tester
namespace: StellarWP\Pup\Tests
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
extensions:
enabled:
- Codeception\Extension\RunFailed
98 changes: 51 additions & 47 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
{
"name": "stellarwp/pup",
"description": "StellarWP's Project Utilities & Packager",
"authors": [
{
"name": "StellarWP",
"email": "dev@stellarwp.com"
}
],
"platform": {
"php": "7.2"
},
"bin": [
"pup"
],
"minimum-stability": "dev",
"prefer-stable": true,
"license": "MIT",
"require": {
"composer/composer": "*",
"php": "^7.2|^8.0",
"symfony/process": "^5.4",
"symfony/console": "^5.4",
"symfony/finder": "^5.4",
"symfony/filesystem": "^5.4"
},
"require-dev": {
"phpstan/phpstan": "^1.10.0"
},
"autoload": {
"psr-4": {
"StellarWP\\Pup\\": "src/"
}
},
"scripts": {
"build-phar" : [
"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"
],
"test:analysis": [
"phpstan analyse -c phpstan.neon.dist --memory-limit=512M"
]
},
"scripts-descriptions": {
"test:analysis": "Run PHPStan static code analysis"
}
}
{
"name": "stellarwp/pup",
"description": "StellarWP's Project Utilities & Packager",
"authors": [
{
"name": "StellarWP",
"email": "dev@stellarwp.com"
}
],
"platform": {
"php": "7.2"
},
"bin": [
"pup"
],
"minimum-stability": "dev",
"prefer-stable": true,
"license": "MIT",
"require": {
"composer/composer": "*",
"php": "^7.2|^8.0",
"symfony/process": "^5.4",
"symfony/console": "^5.4",
"symfony/finder": "^5.4",
"symfony/filesystem": "^5.4"
},
"require-dev": {
"phpstan/phpstan": "^1.10.0",
"codeception/codeception": "^4.2",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-cli": "^2.0"
},
"autoload": {
"psr-4": {
"StellarWP\\Pup\\": "src/"
}
},
"scripts": {
"build-phar": [
"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"
],
"test:analysis": [
"phpstan analyse -c phpstan.neon.dist --memory-limit=512M"
]
},
"scripts-descriptions": {
"test:analysis": "Run PHPStan static code analysis"
}
}
47 changes: 24 additions & 23 deletions pup
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
#!/usr/bin/env php
<?php

namespace StellarWP\Pup;

const PUP_VERSION = '0.0.3';
define( '__PUP_DIR__', __DIR__ );

call_user_func( function( $version ) {
if ( ! Phar::running() ) {
$local_dir_autoload = __PUP_DIR__ . '/vendor/autoload.php';
$autoload = getcwd() . '/vendor/autoload.php';
if ( ! \Phar::running() ) {
$local_dir_autoload = __PUP_DIR__ . '/vendor/autoload.php';
$autoload = getcwd() . '/vendor/autoload.php';

if ( ! empty( $GLOBALS['_composer_autoload_path'] ) ) {
require $GLOBALS['_composer_autoload_path'];
} elseif ( is_file( $local_dir_autoload ) ) {
require $local_dir_autoload;
} elseif ( is_file( $autoload ) ) {
require $autoload;
} else {
fwrite( STDERR,
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
exit( 1 );
}
if ( ! empty( $GLOBALS['_composer_autoload_path'] ) ) {
require $GLOBALS['_composer_autoload_path'];
} elseif ( is_file( $local_dir_autoload ) ) {
require $local_dir_autoload;
} elseif ( is_file( $autoload ) ) {
require $autoload;
} else {
require __PUP_DIR__ . '/vendor/autoload.php';
fwrite( STDERR,
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
exit( 1 );
}
} else {
require __PUP_DIR__ . '/vendor/autoload.php';
}

\StellarWP\Pup\App::getConfig();
$app = \StellarWP\Pup\App::instance();
$app->run();
}, PUP_VERSION );
App::getConfig();
$app = App::instance();
$app->run();
Empty file added tests/_data/.gitkeep
Empty file.
Empty file added tests/_support/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions tests/_support/CliTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace StellarWP\Pup\Tests;

/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class CliTester extends \Codeception\Actor
{
use _generated\CliTesterActions;

/**
* Define custom actions here
*/
}
10 changes: 10 additions & 0 deletions tests/_support/Helper/Cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace StellarWP\Pup\Tests\Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Cli extends \Codeception\Module
{

}
10 changes: 10 additions & 0 deletions tests/_support/Helper/Unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Helper;

// here you can define custom actions
// all public methods declared in helper class will be available in $I

class Unit extends \Codeception\Module
{

}
26 changes: 26 additions & 0 deletions tests/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
}
6 changes: 6 additions & 0 deletions tests/cli.suite.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
actor: CliTester
modules:
enabled:
- Asserts
- Cli
- \StellarWP\Pup\Tests\Helper\Cli
55 changes: 55 additions & 0 deletions tests/cli/HelpCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace StellarWP\Pup\Tests;

use Codeception\Example;
use StellarWP\Pup\Tests\CliTester;

class HelpCest {
protected $path_to_pup;

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

/**
* @test
*/
public function it_should_default_to_help( CliTester $I ) {
$I->runShellCommand( "php {$this->path_to_pup}" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'A CLI utility' );
}

/**
* @test
*/
public function it_should_run_help( CliTester $I ) {
$I->runShellCommand( "php {$this->path_to_pup} help" );
$I->seeResultCodeIs( 0 );
$I->seeInShellOutput( 'A CLI utility' );
}

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

protected function topicProvider(): array {
return [
[ 'topic' => 'build' ],
[ 'topic' => 'check' ],
[ 'topic' => 'check:tbd' ],
[ 'topic' => 'check:version-conflict' ],
[ 'topic' => 'help' ],
[ 'topic' => 'get-version' ],
[ 'topic' => 'package' ],
[ 'topic' => 'zip' ],
];
}
}
11 changes: 11 additions & 0 deletions tests/unit.suite.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Codeception Test Suite Configuration
#
# Suite for unit or integration tests.

actor: UnitTester
modules:
enabled:
- Asserts
- Cli
- \Helper\Unit
step_decorators: ~
21 changes: 21 additions & 0 deletions tests/unit/HelpTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace StellarWP\Pup\Tests;

use StellarWP\Pup\App;

class HelpTest extends \Codeception\Test\Unit {

protected function _before() {
}

protected function _after() {}

/**
* @test
*/
public function it_should_show_help() {

$this->assertTrue( true );
}
}

0 comments on commit 7744d5b

Please sign in to comment.