Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 3d5f62d

Browse files
authored
Better sites:add error handling, and other fixes
* Add better error output when RSD detection doesn't work. * Add upgrade instructions to README.md * Remove code coverage for now, and update PHPUnit configuration.
1 parent 12dda08 commit 3d5f62d

File tree

4 files changed

+50
-24
lines changed

4 files changed

+50
-24
lines changed

README.md

+25-9
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,33 @@ or via commands such as `sites:add` and `sites:modify`.
2121
## Installation
2222

2323
1. Clone the repository:
24-
25-
git clone https://github.com/samwilson/mwcli
24+
```console
25+
git clone https://github.com/samwilson/mwcli
26+
```
2627

2728
2. Install dependencies:
28-
29-
cd mwcli
30-
composer install --no-dev
31-
32-
3. Optionally add `mwcli` to your path:
33-
34-
echo 'export PATH=$PATH:'$(pwd)/bin >> ~/.profile
29+
```console
30+
cd mwcli
31+
composer install --no-dev
32+
```
33+
34+
3. Optionally add `mwcli` to your $PATH. For example, on Linux:
35+
```console
36+
echo 'export PATH=$PATH:'$(pwd)/bin >> ~/.profile
37+
```
38+
39+
## Upgrading
40+
41+
1. Update the code:
42+
```console
43+
cd mwcli
44+
git pull origin main
45+
```
46+
47+
2. Update dependencies:
48+
```console
49+
composer install --no-dev
50+
```
3551

3652
## Usage
3753

phpunit.xml.dist

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22

33
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
6-
backupGlobals="false"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
76
colors="true"
87
bootstrap="vendor/autoload.php"
8+
testdox="true"
9+
displayDetailsOnIncompleteTests="true"
10+
displayDetailsOnSkippedTests="true"
11+
displayDetailsOnPhpunitDeprecations="true"
12+
displayDetailsOnTestsThatTriggerDeprecations="true"
13+
displayDetailsOnTestsThatTriggerErrors="true"
14+
displayDetailsOnTestsThatTriggerNotices="true"
15+
displayDetailsOnTestsThatTriggerWarnings="true"
916
>
1017
<testsuites>
1118
<testsuite name="Project Test Suite">
12-
<directory>tests</directory>
19+
<directory>./tests/</directory>
1320
</testsuite>
1421
</testsuites>
15-
<filter>
16-
<whitelist>
17-
<directory>src</directory>
18-
</whitelist>
19-
</filter>
20-
<logging>
21-
<log type="coverage-clover" target="build/phpunit_clover.xml" />
22-
</logging>
22+
<source>
23+
<include>
24+
<directory suffix=".php">./src/</directory>
25+
</include>
26+
</source>
2327
</phpunit>

src/Command/SitesAddCommand.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
66
use Addwiki\Mediawiki\Api\Client\MediaWiki;
7+
use Addwiki\Mediawiki\Api\Client\RsdException;
8+
use Symfony\Component\Console\Command\Command;
79
use Symfony\Component\Console\Input\InputInterface;
810
use Symfony\Component\Console\Input\InputOption;
911
use Symfony\Component\Console\Output\OutputInterface;
@@ -23,8 +25,12 @@ public function execute( InputInterface $input, OutputInterface $output ) {
2325
if ( !$url ) {
2426
$url = $this->io->ask( $this->msg( 'sites-add-ask-url' ) );
2527
}
26-
/** @var Aci */
27-
$api = MediaWiki::newFromPage( $url );
28+
try {
29+
$api = MediaWiki::newFromPage( $url );
30+
} catch ( RsdException $e ) {
31+
$this->io->error( $e->getMessage() );
32+
return Command::FAILURE;
33+
}
2834
$siteinfoReq = ActionRequest::simpleGet( 'query', [ 'meta' => 'siteinfo' ] );
2935
$siteInfo = $api->action()->request( $siteinfoReq );
3036

@@ -36,6 +42,6 @@ public function execute( InputInterface $input, OutputInterface $output ) {
3642
$this->setSite( $input, $siteInfo['query']['general']['wikiid'], $newSite );
3743

3844
$this->io->block( $this->msg( 'sites-add-added', [ $newSite['name'], $newSite['main_page_url'] ] ) );
39-
return 0;
45+
return Command::SUCCESS;
4046
}
4147
}

tests/SitesAddCommandTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testAddSite( $configFilename ): void {
2424
unlink( $configFile );
2525
}
2626

27-
public function provideAddSite() {
27+
public static function provideAddSite() {
2828
return [
2929
[ 'config.yml' ],
3030
[ 'foobar.yaml' ]

0 commit comments

Comments
 (0)