Skip to content

Commit cbde785

Browse files
Andreas Frömericanhazstring
authored andcommitted
Drop php7.2 and symfony/process ^4.4 support.
Update phpunit with prophecy trait
1 parent da067b9 commit cbde785

File tree

10 files changed

+93
-82
lines changed

10 files changed

+93
-82
lines changed

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"description": "PHP wrapper for systemctl",
44
"type": "library",
55
"require": {
6-
"php": "^7.2",
7-
"symfony/process": "^4.4 || ^5.0"
6+
"php": "^7.3",
7+
"symfony/process": "^5.0"
88
},
99
"require-dev": {
10-
"phpunit/phpunit": "^8.5 || ^9.0",
11-
"squizlabs/php_codesniffer": "^3.5",
12-
"codeclimate/php-test-reporter": "dev-master",
13-
"slevomat/coding-standard": "^6.1",
14-
"phpstan/phpstan": "^0.12.10"
10+
"phpunit/phpunit": "^9.4.2",
11+
"squizlabs/php_codesniffer": "^3.5.8",
12+
"slevomat/coding-standard": "^6.4.1",
13+
"phpstan/phpstan": "^0.12.51",
14+
"phpspec/prophecy-phpunit": "^2.0.1"
1515
},
1616
"autoload": {
1717
"psr-4": {

src/Command/CommandDispatcherInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function setBinary(string $binary): CommandDispatcherInterface;
3333
* Dispatch given commands against implementers logic and creating a new command
3434
* to read results
3535
*
36-
* @param array<int, string> $commands
36+
* @param string ...$commands
3737
*
3838
* @return CommandInterface
3939
* @throws CommandFailedException
4040
*/
41-
public function dispatch(...$commands): CommandInterface;
41+
public function dispatch(string ...$commands): CommandInterface;
4242
}

src/Command/SymfonyCommandDispatcher.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace icanhazstring\SystemCtl\Command;
44

55
use Symfony\Component\Process\Process;
6-
use Symfony\Component\Process\ProcessBuilder;
76

87
/**
98
* Class SymfonyCommandDispatcher
@@ -38,10 +37,7 @@ public function setTimeout(int $timeout): CommandDispatcherInterface
3837
return $this;
3938
}
4039

41-
/**
42-
* @inheritDoc
43-
*/
44-
public function dispatch(...$commands): CommandInterface
40+
public function dispatch(string ...$commands): CommandInterface
4541
{
4642
$process = new Process(array_merge([$this->binary], $commands));
4743
$process->setTimeout($this->timeout);

src/Unit/AbstractUnit.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ public function getInstanceName(): ?string
7474
abstract protected function getUnitSuffix(): string;
7575

7676
/**
77-
* @param array<int, string> $commands
78-
*
7977
* @return CommandInterface
8078
* @throws CommandFailedException
8179
*/
82-
public function execute(...$commands): CommandInterface
80+
public function execute(string ...$commands): CommandInterface
8381
{
8482
$commands[] = implode(
8583
'.',

test/Integration/SystemCtlTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Prophecy\Argument;
7+
use Prophecy\PhpUnit\ProphecyTrait;
78
use Prophecy\Prophecy\ObjectProphecy;
89
use icanhazstring\SystemCtl\Command\CommandDispatcherInterface;
910
use icanhazstring\SystemCtl\Command\CommandInterface;
@@ -19,6 +20,8 @@
1920
*/
2021
class SystemCtlTest extends TestCase
2122
{
23+
use ProphecyTrait;
24+
2225
/**
2326
* @return ObjectProphecy
2427
*/
@@ -58,7 +61,7 @@ public function testListUnitsWithAvailableUnits(): void
5861
$systemctl->setCommandDispatcher($dispatcherStub->reveal());
5962

6063
$units = $systemctl->listUnits(null, SystemCtl::AVAILABLE_UNITS);
61-
$this->assertCount(12, $units);
64+
self::assertCount(12, $units);
6265
}
6366

6467
public function testListUnitsWithSupportedUnits(): void
@@ -87,15 +90,15 @@ public function testListUnitsWithSupportedUnits(): void
8790
$systemctl->setCommandDispatcher($dispatcherStub->reveal());
8891

8992
$units = $systemctl->listUnits();
90-
$this->assertCount(5, $units);
93+
self::assertCount(5, $units);
9194
}
9295

9396
public function testCreateUnitFromSupportedSuffixShouldWord(): void
9497
{
9598
$unit = SystemCtl::unitFromSuffix('service', 'SuccessService');
96-
$this->assertInstanceOf(UnitInterface::class, $unit);
97-
$this->assertInstanceOf(Service::class, $unit);
98-
$this->assertEquals('SuccessService', $unit->getName());
99+
self::assertInstanceOf(UnitInterface::class, $unit);
100+
self::assertInstanceOf(Service::class, $unit);
101+
self::assertEquals('SuccessService', $unit->getName());
99102
}
100103

101104
public function testCreateUnitFromUnsupportedSuffixShouldRaiseException(): void
@@ -126,7 +129,7 @@ public function testGetServices(): void
126129

127130
$services = $systemctl->getServices();
128131

129-
$this->assertCount(2, $services);
132+
self::assertCount(2, $services);
130133
}
131134

132135
public function testGetTimers(): void
@@ -150,7 +153,7 @@ public function testGetTimers(): void
150153
$systemctl->setCommandDispatcher($dispatcherStub->reveal());
151154
$timers = $systemctl->getTimers();
152155

153-
$this->assertCount(2, $timers);
156+
self::assertCount(2, $timers);
154157
}
155158

156159
/**
@@ -167,6 +170,6 @@ public function itShouldReturnTrueOnSuccessfulDaemonReload(): void
167170
$systemCtl = new SystemCtl();
168171
$systemCtl->setCommandDispatcher($dispatcher->reveal());
169172

170-
$this->assertTrue($systemCtl->daemonReload());
173+
self::assertTrue($systemCtl->daemonReload());
171174
}
172175
}

test/Integration/Unit/UnitTest.php

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use icanhazstring\SystemCtl\Unit\Device;
66
use PHPUnit\Framework\TestCase;
77
use Prophecy\Argument;
8+
use Prophecy\PhpUnit\ProphecyTrait;
89
use Prophecy\Prophecy\ObjectProphecy;
910
use icanhazstring\SystemCtl\Command\CommandDispatcherInterface;
1011
use icanhazstring\SystemCtl\Command\CommandInterface;
@@ -21,6 +22,8 @@
2122
*/
2223
class UnitTest extends TestCase
2324
{
25+
use ProphecyTrait;
26+
2427
public function testServiceCommandsIfProcessIsSuccessfulShouldReturnTrue(): void
2528
{
2629
$command = $this->prophesize(CommandInterface::class);
@@ -31,12 +34,12 @@ public function testServiceCommandsIfProcessIsSuccessfulShouldReturnTrue(): void
3134

3235
$service = new Service('AwesomeService', $commandDispatcher->reveal());
3336

34-
$this->assertTrue($service->start());
35-
$this->assertTrue($service->stop());
36-
$this->assertTrue($service->enable());
37-
$this->assertTrue($service->disable());
38-
$this->assertTrue($service->reload());
39-
$this->assertTrue($service->restart());
37+
self::assertTrue($service->start());
38+
self::assertTrue($service->stop());
39+
self::assertTrue($service->enable());
40+
self::assertTrue($service->disable());
41+
self::assertTrue($service->reload());
42+
self::assertTrue($service->restart());
4043
}
4144

4245
public function createCommandDispatcherStub(): ObjectProphecy
@@ -69,12 +72,12 @@ public function testTimerCommandsIfProcessIsSuccessfulShouldReturnTrue(): void
6972

7073
$timer = new Timer('AwesomeService', $commandDispatcher->reveal());
7174

72-
$this->assertTrue($timer->start());
73-
$this->assertTrue($timer->stop());
74-
$this->assertTrue($timer->enable());
75-
$this->assertTrue($timer->disable());
76-
$this->assertTrue($timer->reload());
77-
$this->assertTrue($timer->restart());
75+
self::assertTrue($timer->start());
76+
self::assertTrue($timer->stop());
77+
self::assertTrue($timer->enable());
78+
self::assertTrue($timer->disable());
79+
self::assertTrue($timer->reload());
80+
self::assertTrue($timer->restart());
7881
}
7982

8083
public function testTimerCommandsIfProcessIsUnsuccessFulShouldRaiseException(): void
@@ -98,12 +101,12 @@ public function testSocketCommandsIfProcessIsSuccessfulShouldReturnTrue(): void
98101

99102
$socket = new Socket('AwesomeSocket', $commandDispatcher->reveal());
100103

101-
$this->assertTrue($socket->start());
102-
$this->assertTrue($socket->stop());
103-
$this->assertTrue($socket->enable());
104-
$this->assertTrue($socket->disable());
105-
$this->assertTrue($socket->reload());
106-
$this->assertTrue($socket->restart());
104+
self::assertTrue($socket->start());
105+
self::assertTrue($socket->stop());
106+
self::assertTrue($socket->enable());
107+
self::assertTrue($socket->disable());
108+
self::assertTrue($socket->reload());
109+
self::assertTrue($socket->restart());
107110
}
108111

109112
public function testSocketCommandsIfProcessIsUnsuccessFulShouldRaiseException(): void
@@ -127,12 +130,12 @@ public function testScopeCommandsIfProcessIsSuccessfulShouldReturnTrue(): void
127130

128131
$scope = new Scope('AwesomeScope', $commandDispatcher->reveal());
129132

130-
$this->assertTrue($scope->start());
131-
$this->assertTrue($scope->stop());
132-
$this->assertTrue($scope->enable());
133-
$this->assertTrue($scope->disable());
134-
$this->assertTrue($scope->reload());
135-
$this->assertTrue($scope->restart());
133+
self::assertTrue($scope->start());
134+
self::assertTrue($scope->stop());
135+
self::assertTrue($scope->enable());
136+
self::assertTrue($scope->disable());
137+
self::assertTrue($scope->reload());
138+
self::assertTrue($scope->restart());
136139
}
137140

138141
public function testScopeCommandsIfProcessIsUnsuccessFulShouldRaiseException(): void
@@ -156,12 +159,12 @@ public function testDeviceCommandsIfProcessIsSuccessfulShouldReturnTrue()
156159

157160
$device = new Device('AwesomeDevice', $commandDispatcher->reveal());
158161

159-
$this->assertTrue($device->start());
160-
$this->assertTrue($device->stop());
161-
$this->assertTrue($device->enable());
162-
$this->assertTrue($device->disable());
163-
$this->assertTrue($device->reload());
164-
$this->assertTrue($device->restart());
162+
self::assertTrue($device->start());
163+
self::assertTrue($device->stop());
164+
self::assertTrue($device->enable());
165+
self::assertTrue($device->disable());
166+
self::assertTrue($device->reload());
167+
self::assertTrue($device->restart());
165168
}
166169

167170
public function testDeviceCommandsIfProcessIsUnsuccessFulShouldRaiseException()

test/Unit/Command/SymfonyCommandTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace icanhazstring\SystemCtl\Test\Unit\Command;
44

55
use PHPUnit\Framework\TestCase;
6+
use Prophecy\PhpUnit\ProphecyTrait;
67
use Symfony\Component\Process\Process;
78
use icanhazstring\SystemCtl\Command\SymfonyCommand;
89
use icanhazstring\SystemCtl\Exception\CommandFailedException;
@@ -15,6 +16,8 @@
1516
*/
1617
class SymfonyCommandTest extends TestCase
1718
{
19+
use ProphecyTrait;
20+
1821
/**
1922
* @test
2023
*/
@@ -23,7 +26,7 @@ public function itShouldCreateValidInstance(): void
2326
$process = $this->prophesize(Process::class);
2427
$command = new SymfonyCommand($process->reveal());
2528

26-
$this->assertInstanceOf(SymfonyCommand::class, $command);
29+
self::assertInstanceOf(SymfonyCommand::class, $command);
2730
}
2831

2932
/**
@@ -35,7 +38,7 @@ public function itShouldReturnOutputFromProcess(): void
3538
$process->getOutput()->willReturn('test');
3639

3740
$command = new SymfonyCommand($process->reveal());
38-
$this->assertEquals('test', $command->getOutput());
41+
self::assertEquals('test', $command->getOutput());
3942
}
4043

4144
/**
@@ -47,7 +50,7 @@ public function itShouldReturnSuccessfulFromProcess(): void
4750
$process->isSuccessful()->willReturn(true);
4851

4952
$command = new SymfonyCommand($process->reveal());
50-
$this->assertTrue($command->isSuccessful());
53+
self::assertTrue($command->isSuccessful());
5154
}
5255

5356
/**
@@ -61,7 +64,7 @@ public function itShouldReturnTheCommandIfCommandRanSuccessFul(): void
6164
$process->isSuccessful()->willReturn(true);
6265

6366
$command = new SymfonyCommand($process->reveal());
64-
$this->assertEquals($command, $command->run());
67+
self::assertEquals($command, $command->run());
6568
}
6669

6770
/**

0 commit comments

Comments
 (0)