Skip to content

Commit e3b30dc

Browse files
authored
Merge pull request #1 from wirecli/dev
Dev
2 parents 43c61d5 + 9be02fb commit e3b30dc

File tree

84 files changed

+16218
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+16218
-2
lines changed

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
5+
root = true
6+
7+
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
14+
[*.{php,inc,module,json}]
15+
indent_style = space
16+
trim_trailing_whitespace = false
17+
insert_final_newline = true
18+
19+
20+
[*.js]
21+
indent_style = space
22+
trim_trailing_whitespace = false
23+
insert_final_newline = true
24+
25+
26+
[*.{css,less,scss}]
27+
indent_style = space
28+
trim_trailing_whitespace = false
29+
insert_final_newline = true

.github/workflows/releases.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Releases
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
changelog:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: conventional Changelog Action
14+
id: changelog
15+
uses: TriPSs/[email protected]
16+
with:
17+
github-token: ${{ secrets.github_token }}
18+
19+
- name: create release
20+
uses: actions/create-release@v1
21+
if: ${{ steps.changelog.outputs.skipped == 'false' }}
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.github_token }}
24+
with:
25+
tag_name: ${{ steps.changelog.outputs.tag }}
26+
release_name: ${{ steps.changelog.outputs.tag }}
27+
body: ${{ steps.changelog.outputs.clean_changelog }}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Composer
2+
vendor
3+
4+
# Binaries
5+
composer.phar
6+
7+
# Node modules
8+
node_modules
9+
10+
# Tests
11+
phpunit.xml
12+
13+
# Directories etc.
14+
ProcessWire
15+
Tests/processwire.zip
16+

LICENCE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) <year> <copyright holders>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# wirecli
2-
An extendable CLI tool for ProcessWire developers. Automate common tasks and manage your ProcessWire projects effortlessly.
1+
# wire-cli
2+
3+
wire-cli is a CLI (Command-Line Interface) tool designed to provide ease of use and efficiency for ProcessWire developers. With wire-cli, you can automate common tasks, manage ProcessWire projects effortlessly, and enhance your development workflow.
4+
5+
## Features
6+
7+
- Create new ProcessWire projects
8+
- Serve ProcessWire via built-in PHP webserver
9+
- Perform database backup and restoration
10+
- Manage fields, templates, roles, users, and modules
11+
- Generate boilerplate modules
12+
- Check for core upgrades
13+
- And more...
14+
15+
wire-cli is based on the defunct wireshell, built using the [Symfony Console](https://symfony.com/doc/current/components/console.html) Component, offering a powerful and intuitive command-line interface for interacting with ProcessWire projects and adding new commands. It is compatible with PHP 8.1.
16+
17+
Please note that wire-cli and another tool called [rockshell](https://github.com/baumrock/rockshell) share similar goals and functionality. In the future, the features of wire-cli and rockshell will be merged to provide a unified and comprehensive CLI tool for ProcessWire developers.
18+
19+
## Installation
20+
21+
To install wire-cli, you need to have Composer installed. Run the following command to install wire-cli globally:
22+
23+
```
24+
composer global require wirecli/wire-cli
25+
```
26+
27+
## Usage
28+
29+
Run `wire-cli` followed by the desired command to execute various tasks. For example:
30+
31+
```
32+
wire-cli new myproject
33+
```
34+
35+
For a complete list of available commands and options, use the `help` command:
36+
37+
## Documentation
38+
39+
For detailed documentation and usage examples, please refer to the [official documentation](https://github.com/wirecli/wire-cli).
40+
41+
## Contributing
42+
43+
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please submit an issue or a pull request on the [GitHub repository](https://github.com/wirecli/wire-cli).
44+
45+
## Available commands
46+
47+
![](./docs/capture-cmd.jpg)
48+
49+
## Credits
50+
51+
wire-cli is inspired by the work of the following authors of the initial developers/contributors of wireshell:
52+
53+
- Marcus Herrmann
54+
- Hari K T
55+
- Bea David
56+
- Camilo Castro
57+
- Horst Nogajski
58+
59+
## License
60+
61+
This project is licensed under the [MIT License](LICENSE.md).

Tests/BaseTestCase.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php namespace Wirecli\Tests;
2+
3+
use GuzzleHttp\Client;
4+
use \PHPUnit\Framework\TestCase as TestCase;
5+
use Symfony\Component\Console\Application;
6+
use Symfony\Component\Filesystem\Filesystem;
7+
8+
abstract class BaseTestCase extends TestCase {
9+
10+
const INSTALLATION_FOLDER = 'ProcessWire';
11+
const INSTALLATION_ARCHIVE = 'Tests/processwire.zip';
12+
13+
/**
14+
* @var Filesystem
15+
*/
16+
public $fs;
17+
18+
/**
19+
* @var Application
20+
*/
21+
public $app = null;
22+
23+
public $tester = null;
24+
public $command = null;
25+
26+
public function __construct($name = null, array $data = [], $dataName = '') {
27+
parent::__construct($name, $data, $dataName);
28+
$this->fs = new Filesystem();
29+
$this->app = new Application();
30+
$this->app->setAutoExit(false);
31+
}
32+
33+
public function checkInstallation() {
34+
if ($this->fs->exists(self::INSTALLATION_FOLDER)) $this->fs->remove(self::INSTALLATION_FOLDER);
35+
36+
// if installation exists and zip file is older than 24h remove it
37+
if ($this->fs->exists(self::INSTALLATION_ARCHIVE) && (time() - filemtime(self::INSTALLATION_ARCHIVE)) > 86400) {
38+
$this->fs->remove(self::INSTALLATION_ARCHIVE);
39+
}
40+
41+
if (!$this->fs->exists(self::INSTALLATION_ARCHIVE)) $this->downloadArchive();
42+
}
43+
44+
public function downloadArchive() {
45+
$client = new Client();
46+
$client->request('GET', 'https://github.com/processwire/processwire/archive/master.zip', ['sink' => 'Tests/processwire.zip']);
47+
}
48+
49+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php namespace Wirecli\Tests\Commands\Common;
2+
3+
use Symfony\Component\Console\Tester\CommandTester;
4+
use Symfony\Component\Console\Question\Question;
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Question\ConfirmationQuestion;
8+
use Ofbeaton\Console\Tester\UnhandledQuestionException;
9+
use Wirecli\Tests\BaseTestCase as Base;
10+
use Wirecli\Commands\Common\NewCommand;
11+
12+
class NewCommandTest extends Base {
13+
/**
14+
* @field array default config values
15+
*/
16+
protected $defaults = array(
17+
'--timezone' => 'Europe\Berlin',
18+
'--httpHosts' => 'wirecli.sek',
19+
'--username' => 'admin',
20+
'--userpass' => 'password',
21+
'--useremail' => '[email protected]'
22+
);
23+
24+
/**
25+
* @before
26+
*/
27+
public function setupCommand() {
28+
$this->app->add(new NewCommand());
29+
$this->command = $this->app->find('new');
30+
$this->tester = new CommandTester($this->command);
31+
32+
$credentials = array(
33+
'--dbUser' => $GLOBALS['DB_USER'],
34+
'--dbPass' => $GLOBALS['DB_PASSWD'],
35+
'--dbName' => $GLOBALS['DB_DBNAME']
36+
);
37+
38+
$this->extends = array(
39+
'command' => $this->command->getName(),
40+
'directory' => Base::INSTALLATION_FOLDER,
41+
);
42+
43+
$this->defaults = array_merge($this->defaults, $credentials, $this->extends);
44+
}
45+
46+
public function testDownload() {
47+
$this->checkInstallation();
48+
$options = array('--no-install' => true, '--src' => Base::INSTALLATION_ARCHIVE);
49+
$this->tester->execute(array_merge($this->defaults, $options));
50+
51+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER);
52+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/wire');
53+
$this->assertDirectoryNotExists(Base::INSTALLATION_FOLDER . '/site');
54+
}
55+
56+
/**
57+
* @depends testDownload
58+
* @expectedException RuntimeException
59+
* @expectedExceptionMessageRegExp /(Database connection information did not work)./
60+
*/
61+
public function testInstallWrongPassword() {
62+
// check ProcessWire has not been installed yet
63+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
64+
65+
// return the input you want to answer the question with
66+
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) {
67+
if (strpos($text, 'database user name') !== false) return 'whatever';
68+
if (strpos($text, 'database password') !== false) return 'wrong';
69+
70+
throw new UnhandledQuestionException();
71+
});
72+
73+
$options = array(
74+
'--src' => Base::INSTALLATION_ARCHIVE,
75+
'--dbPass' => 'wrong'
76+
);
77+
78+
$this->tester->execute(array_merge($this->defaults, $options));
79+
}
80+
81+
/**
82+
* @depends testDownload
83+
* @expectedExceptionMessageRegExp /(enter a valid email address)/
84+
*/
85+
public function testInstallInvalidEmailAddress() {
86+
// check ProcessWire has not been installed yet
87+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
88+
89+
// return the input you want to answer the question with
90+
$this->mockQuestionHelper($this->command, function($text, $order, Question $question) {
91+
if (strpos($text, 'admin email address') !== false) return 'whatever';
92+
93+
throw new UnhandledQuestionException();
94+
});
95+
96+
$options = array(
97+
'--src' => Base::INSTALLATION_ARCHIVE,
98+
'--useremail' => 'invalid'
99+
);
100+
101+
$this->tester->execute(array_merge($this->defaults, $options));
102+
}
103+
104+
/**
105+
* @depends testDownload
106+
*/
107+
public function testInstall() {
108+
// check ProcessWire has not been installed yet
109+
if ($this->fs->exists(Base::INSTALLATION_FOLDER . '/site/config.php')) return;
110+
111+
$this->tester->execute($this->defaults);
112+
$output = $this->tester->getDisplay();
113+
114+
$this->assertDirectoryExists(Base::INSTALLATION_FOLDER . '/site');
115+
$this->assertFileExists(Base::INSTALLATION_FOLDER . '/site/config.php');
116+
$this->assertContains('Congratulations, ProcessWire has been successfully installed.', $output);
117+
}
118+
119+
/**
120+
* @depends testInstall
121+
* @expectedExceptionMessageRegExp /(There is already a \')(.*)(\' project)/
122+
*/
123+
public function testIsInstalled() {
124+
$this->tester->execute($this->defaults);
125+
}
126+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php namespace Wirecli\Tests\Commands\Common;
2+
3+
use Symfony\Component\Console\Tester\CommandTester;
4+
use Wirecli\Tests\BaseTestCase as Base;
5+
use Wirecli\Commands\Common\StatusCommand;
6+
7+
class StatusCommandTest extends Base {
8+
9+
/**
10+
* @before
11+
*/
12+
public function setupCommand() {
13+
$this->app->add(new StatusCommand());
14+
$this->command = $this->app->find('status');
15+
$this->tester = new CommandTester($this->command);
16+
}
17+
18+
public function testNotEmptyOutput() {
19+
$this->tester->execute(array(
20+
'command' => $this->command->getName()
21+
));
22+
23+
$output = $this->tester->getDisplay();
24+
$this->assertContains('Version', $output);
25+
$this->assertContains('ProcessWire', $output);
26+
$this->assertContains('*****', $output);
27+
}
28+
29+
public function testImageDiagnostic() {
30+
$this->tester->execute(array(
31+
'command' => $this->command->getName(),
32+
'--image' => true
33+
));
34+
35+
$output = $this->tester->getDisplay();
36+
$this->assertContains('Image Diagnostics', $output);
37+
}
38+
39+
public function testPhpDiagnostic() {
40+
$this->tester->execute(array(
41+
'command' => $this->command->getName(),
42+
'--php' => true
43+
));
44+
45+
$output = $this->tester->getDisplay();
46+
$this->assertContains('PHP Diagnostics', $output);
47+
}
48+
49+
public function testDisplayPass() {
50+
$this->tester->execute(array(
51+
'command' => $this->command->getName(),
52+
'--pass' => true
53+
));
54+
55+
$output = $this->tester->getDisplay();
56+
$this->assertNotContains('*****', $output);
57+
}
58+
}

0 commit comments

Comments
 (0)