From e5b27316fa3f7659d1c9c3d67394cbb2e237d320 Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Sun, 3 Jun 2018 11:44:21 +0000 Subject: [PATCH 1/2] Add Gitter badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d39504..90b11e1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # systemctl-php -[![Build Status](https://api.travis-ci.org/icanhazstring/systemctl-php.svg?branch=master)](https://travis-ci.org/icanhazstring/systemctl-php) [![Code Climate](https://codeclimate.com/github/icanhazstring/systemctl-php/badges/gpa.svg)](https://codeclimate.com/github/icanhazstring/systemctl-php) [![Test Coverage](https://codeclimate.com/github/icanhazstring/systemctl-php/badges/coverage.svg)](https://codeclimate.com/github/icanhazstring/systemctl-php/coverage) +[![Build Status](https://api.travis-ci.org/icanhazstring/systemctl-php.svg?branch=master)](https://travis-ci.org/icanhazstring/systemctl-php) [![Code Climate](https://codeclimate.com/github/icanhazstring/systemctl-php/badges/gpa.svg)](https://codeclimate.com/github/icanhazstring/systemctl-php) [![Test Coverage](https://codeclimate.com/github/icanhazstring/systemctl-php/badges/coverage.svg)](https://codeclimate.com/github/icanhazstring/systemctl-php/coverage) [![Join the chat at https://gitter.im/icanhazstring/systemctl-php](https://badges.gitter.im/icanhazstring/systemctl-php.svg)](https://gitter.im/icanhazstring/systemctl-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) PHP wrapper for systemctl (PHP7.1) From 4653447910ad8bf6e2dd18c9c26799db45d8d183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Fr=C3=B6mer?= Date: Tue, 19 Mar 2019 14:06:35 +0100 Subject: [PATCH 2/2] Fix issue with failed service Failed services may contain non valid character in front of there service name. This commit improves the regex to extract the service name. --- src/Utils/OutputFetcher.php | 2 +- tests/Integration/SystemCtlTest.php | 3 ++- tests/Unit/Utils/OutputFetcherTest.php | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Utils/OutputFetcher.php b/src/Utils/OutputFetcher.php index 5292dc6..b0dadf1 100644 --- a/src/Utils/OutputFetcher.php +++ b/src/Utils/OutputFetcher.php @@ -19,7 +19,7 @@ class OutputFetcher */ public static function fetchUnitNames(string $suffix, string $output): array { - preg_match_all('/^\s*(?.*)\.' . $suffix . '\s.*$/m', $output, $matches); + preg_match_all('/^[^[:alnum:]-_\.@]*(?.*)\.' . $suffix . '\s.*$/m', $output, $matches); return $matches['unit'] ?? []; } } diff --git a/tests/Integration/SystemCtlTest.php b/tests/Integration/SystemCtlTest.php index 958963a..0e02ca2 100644 --- a/tests/Integration/SystemCtlTest.php +++ b/tests/Integration/SystemCtlTest.php @@ -45,6 +45,7 @@ public function testListUnitsWithAvailableUnits() beanstalkd.service loaded active running console-setup.service loaded active exited cron.service loaded active running +● failed-server@foo.service loaded failed failed EOT; $command = $this->prophesize(CommandInterface::class); @@ -57,7 +58,7 @@ public function testListUnitsWithAvailableUnits() $systemctl->setCommandDispatcher($dispatcherStub->reveal()); $units = $systemctl->listUnits(null, SystemCtl::AVAILABLE_UNITS); - $this->assertCount(11, $units); + $this->assertCount(12, $units); } public function testListUnitsWithSupportedUnits() diff --git a/tests/Unit/Utils/OutputFetcherTest.php b/tests/Unit/Utils/OutputFetcherTest.php index 34b2e40..209be65 100644 --- a/tests/Unit/Utils/OutputFetcherTest.php +++ b/tests/Unit/Utils/OutputFetcherTest.php @@ -35,21 +35,22 @@ public function itDeterminesTheCorrectAmountOfUnits( public function itDeterminesTheCorrectAmountOfUnitsDataProvider(): array { $output = << $output, 'suffix' => 'service', - 'amount' => 4, + 'amount' => 5, ], [ 'output' => $output, @@ -97,6 +98,7 @@ public function itOnlyExtractsTheUnitNamesDataProvider(): array nonservice.timer Active running instance-service@1.service Active running instance-service@foo.service Active running +● failed-service@foo.service loaded failed failed OUTPUT; return [ @@ -108,6 +110,7 @@ public function itOnlyExtractsTheUnitNamesDataProvider(): array 'foo-bar', 'instance-service@1', 'instance-service@foo', + 'failed-service@foo' ], ], [