Skip to content

Commit

Permalink
Merge pull request #3 from limestonenetworks/feature/php8
Browse files Browse the repository at this point in the history
Feature/php8
  • Loading branch information
montross50 authored Oct 31, 2022
2 parents 2eb91f6 + dd377b3 commit ea4106d
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 127 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on: [push]

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
ini-values: pcov.directory=src
coverage: pcov
- name: Install dependencies
uses: php-actions/composer@v6
with:
php_version: '8.1'
- name: Lint
run: vendor/bin/phpcs --standard=psr2 src/
- name: Test
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

- uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: '*.clover'
fail_ci_if_error: true # optional (default = false)
verbose: true
23 changes: 0 additions & 23 deletions .scrutinizer.yml

This file was deleted.

1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]


Expand Down Expand Up @@ -68,15 +65,9 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio

[ico-version]: https://img.shields.io/packagist/v/limestonenetworks/php-ipmitool.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/limestonenetworks/php-ipmitool/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/limestonenetworks/php-ipmitool.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/limestonenetworks/php-ipmitool.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/limestonenetworks/php-ipmitool.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/limestonenetworks/php-ipmitool
[link-travis]: https://travis-ci.org/limestonenetworks/php-ipmitool
[link-scrutinizer]: https://scrutinizer-ci.com/g/limestonenetworks/php-ipmitool/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/limestonenetworks/php-ipmitool
[link-downloads]: https://packagist.org/packages/limestonenetworks/php-ipmitool
[link-author]: https://github.com/limestonenetworks
[link-contributors]: ../../contributors
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
}
],
"require": {
"php": "~7.0",
"symfony/process": "^4.1"
"php": ">=8.1",
"symfony/process": ">=5.4"
},
"require-dev": {
"phpunit/phpunit" : "~7.0",
"squizlabs/php_codesniffer": "^3.1",
"mockery/mockery": "~1.0"
"phpunit/phpunit" : "^9.5",
"squizlabs/php_codesniffer": "^3.7.1",
"mockery/mockery": "~1.5.1"
},
"autoload": {
"psr-4": {
Expand Down
46 changes: 19 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
12 changes: 5 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class Client
protected $config;
protected $cwd;

public function __construct(Process $process, Config $config)
public function __construct(Config $config)
{
$this->process = $process;
$this->config = $config;
}

Expand All @@ -22,14 +21,13 @@ public function run(array $command, callable $callback = null)
$config = $this->getConfig();
$env = $config->getEnvironmentVariables();
$command = array_merge($config->generateBaseCommand(), $command);
$cwd = null;
if ($config->getCwd() !== '') {
$this->process->setWorkingDirectory($config->getCwd());
$cwd = $config->getCwd();
}
$this->process->setCommandLine($command);

$timeout = $config->getTimeout();
if ($timeout > 0) {
$this->process->setTimeout($timeout);
}
$this->setProcess(new Process($command, $cwd, null, null, $timeout));
$this->process->run($callback, $env);
if (!$this->process->isSuccessful()) {
throw new ProcessFailedException($this->process);
Expand Down
8 changes: 4 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private function setDefaults(array $config): array
'interface' => 'lanplus',
'binary' => 'ipmitool',
'cwd' => '',
'timeout' => 0
'timeout' => 15
];

return array_merge($defaults, $config);
Expand Down Expand Up @@ -287,7 +287,7 @@ public function setFlags(array $flags): Config
* @codeCoverageIgnore
* @return bool
*/
public function offsetExists($offset)
public function offsetExists(mixed $offset): bool
{
return isset($this->config[$offset]);
}
Expand All @@ -298,7 +298,7 @@ public function offsetExists($offset)
* @codeCoverageIgnore
* @return mixed
*/
public function offsetGet($offset)
public function offsetGet(mixed $offset): mixed
{
return $this->config[$offset];
}
Expand All @@ -310,7 +310,7 @@ public function offsetGet($offset)
* @codeCoverageIgnore
* @return void
*/
public function offsetSet($offset, $value): void
public function offsetSet(mixed $offset, $value): void
{
$this->config[$offset] = $value;
}
Expand Down
23 changes: 11 additions & 12 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LSN\ipmitool;

use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

class ClientTest extends \PHPUnit\Framework\TestCase
Expand All @@ -14,7 +15,7 @@ public function testCommandIsExecuted()
$config->shouldReceive('getCwd')->andReturn('');
$config->shouldReceive('getTimeout')->andReturn(0);
$config->shouldReceive('generateBaseCommand')->andReturn([]);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$resultb = $client->run(['ls']);
$this->assertEquals($resulta, $resultb);
}
Expand All @@ -23,15 +24,15 @@ public function testCommandEnvIsInjected()
{
$resulta = shell_exec('env');
$config = \Mockery::mock(Config::class);
$config->shouldReceive('getEnvironmentVariables')->andReturn(['foo'=>'bar']);
$config->shouldReceive('getEnvironmentVariables')->andReturn(['FOO'=>'bar']);
$config->shouldReceive('getCwd')->andReturn('');
$config->shouldReceive('getTimeout')->andReturn(0);
$config->shouldReceive('generateBaseCommand')->andReturn([]);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$resultb = $client->run(['env']);
$this->assertNotEquals($resulta, $resultb);
$this->assertNotContains('foo=bar', $resulta);
$this->assertContains('foo=bar', $resultb);
$this->assertStringNotContainsString('FOO=bar', $resulta);
$this->assertStringContainsString('FOO=bar', $resultb);
}

public function testBaseCommandIsInjected()
Expand All @@ -42,22 +43,20 @@ public function testBaseCommandIsInjected()
$config->shouldReceive('getCwd')->andReturn('');
$config->shouldReceive('getTimeout')->andReturn(0);
$config->shouldReceive('generateBaseCommand')->andReturn(['ls']);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$resultb = $client->run(['-lh']);
$this->assertEquals($resulta, $resultb);
}

/**
* @expectedException \Symfony\Component\Process\Exception\ProcessFailedException
*/
public function testProcessFailedExceptionIsThrownOnFail()
{
$this->expectException(ProcessFailedException::class);
$config = \Mockery::mock(Config::class);
$config->shouldReceive('getEnvironmentVariables')->andReturn([]);
$config->shouldReceive('getCwd')->andReturn('');
$config->shouldReceive('getTimeout')->andReturn(0);
$config->shouldReceive('generateBaseCommand')->andReturn(['exit']);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$client->run(['1']);
}

Expand All @@ -69,7 +68,7 @@ public function testCWDisRespected()
$config->shouldReceive('generateBaseCommand')->andReturn(['ls']);
$config->shouldReceive('getCwd')->andReturn('..');
$config->shouldReceive('getTimeout')->andReturn(0);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$resultb = $client->run(['-lh']);
$this->assertEquals($resulta, $resultb);
}
Expand All @@ -82,7 +81,7 @@ public function testTimeoutisRespected()
$config->shouldReceive('generateBaseCommand')->andReturn(['ls']);
$config->shouldReceive('getCwd')->andReturn('..');
$config->shouldReceive('getTimeout')->andReturn(1);
$client = new Client(new Process(''), $config);
$client = new Client($config);
$resultb = $client->run(['-lh']);
$this->assertEquals($resulta, $resultb);
$process = $client->getProcess();
Expand Down
20 changes: 10 additions & 10 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function testConfigDefault()
$conf = $config->getConfig();
$this->assertEquals('ADMIN', $conf['username']);
$this->assertEquals('lanplus', $conf['interface']);
$this->assertEquals(0, $conf['timeout']);
$this->assertEquals(15, $conf['timeout']);
}

public function testConfigValidate()
Expand Down Expand Up @@ -82,22 +82,22 @@ public function testGenerateBaseCommand()
{
$config = new Config(['password'=>'foobar']);
$base = $config->generateBaseCommand();
$this->assertTrue(is_array($base));
$this->assertIsArray($base);
$this->assertEquals('ipmitool', $base[0]);
$this->assertContains(implode(' ', ['-U','ADMIN']), implode(' ', $base));
$this->assertContains(implode(' ', ['-I','lanplus']), implode(' ', $base));
$this->assertContains(implode(' ', ['-P','foobar']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-U','ADMIN']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-I','lanplus']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-P','foobar']), implode(' ', $base));
}

public function testGenerateBaseCommandWithPasswordEnv()
{
$config = new Config(['password_env'=>'foobar']);
$base = $config->generateBaseCommand();
$this->assertTrue(is_array($base));
$this->assertIsArray($base);
$this->assertEquals('ipmitool', $base[0]);
$this->assertContains(implode(' ', ['-U','ADMIN']), implode(' ', $base));
$this->assertContains(implode(' ', ['-I','lanplus']), implode(' ', $base));
$this->assertContains(implode(' ', ['-E']), implode(' ', $base));
$this->assertNotContains(implode(' ', ['-P']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-U','ADMIN']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-I','lanplus']), implode(' ', $base));
$this->assertStringContainsString(implode(' ', ['-E']), implode(' ', $base));
$this->assertStringNotContainsString(implode(' ', ['-P']), implode(' ', $base));
}
}

0 comments on commit ea4106d

Please sign in to comment.