Skip to content

Commit

Permalink
Version 2: support for multiple SNMP transports
Browse files Browse the repository at this point in the history
Also move to Github Actions and Coveralls
  • Loading branch information
grongor committed Jun 4, 2020
1 parent 514cbfb commit b173ce8
Show file tree
Hide file tree
Showing 65 changed files with 2,310 additions and 1,384 deletions.
139 changes: 139 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: CI
on: [push, pull_request]
jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.4]
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
tools: cs2pr
extensions: json snmp

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-${{ matrix.php-version }}
restore-keys: php-${{ matrix.php-version }}

- name: Install dependencies with composer
run: COMPOSER_ARGS="--prefer-stable" make

- name: Run a static analysis with phpstan/phpstan
env:
PHPSTAN_ARGS: --error-format=checkstyle
run: make -is static-analysis | cs2pr

coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.3]
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
tools: cs2pr

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-${{ matrix.php-version }}
restore-keys: php-${{ matrix.php-version }}

- name: Install dependencies with composer
run: COMPOSER_ARGS="--prefer-stable" make

- name: Run squizlabs/php_codesniffer
env:
PHPCS_ARGS: -q --no-colors --report=checkstyle
run: make -is cs | cs2pr

tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.3, 7.4]
dependencies: ["", --prefer-lowest]

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: ${{ matrix.php-version }}
extensions: json snmp

- name: Install dependencies
run: sudo apt install python-pip snmp

- name: Install snmpsim
run: sudo pip install snmpsim

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-${{ matrix.php-version }}-dependencies-${{ matrix.dependencies }}
restore-keys: php-${{ matrix.php-version }}

- name: Install dependencies with composer
run: COMPOSER_ARGS="--prefer-stable ${{ matrix.dependencies }}" make

- name: version
run: php -v && php -i

- name: Run tests
run: make test

coverage:
name: Tests Coverage
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.4]

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
coverage: pcov
php-version: ${{ matrix.php-version }}
extensions: json snmp

- name: Install dependencies
run: sudo apt install python-pip snmp

- name: Install snmpsim
run: sudo pip install snmpsim

- name: Cache dependencies installed with composer
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: php-${{ matrix.php-version }}
restore-keys: php-${{ matrix.php-version }}

- name: Install dependencies with composer
run: COMPOSER_ARGS="--prefer-stable" make

- name: Run tests coverage
run: PHPUNIT_ARGS="--coverage-clover coverage/clover.xml" make test

- name: Report to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_RUN_LOCALLY: 1
run: pwd && ls -la && ls -la coverage && echo $USER && vendor/bin/php-coveralls --verbose --coverage_clover coverage/clover.xml --json_path coverage
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/coverage/
/vendor/

/.phpcs-cache
/.phpunit.result.cache
/composer.lock
/phpcs.xml
/phpstan.neon
/phpunit.xml
17 changes: 0 additions & 17 deletions .scrutinizer.yml

This file was deleted.

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

This file was deleted.

37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
COMPOSER_ARGS += --no-interaction --no-progress --no-suggest

.PHONY: build
build: vendor

.PHONY: vendor
vendor: vendor/lock

vendor/lock: composer.json
composer update $(COMPOSER_ARGS)
touch vendor/lock

.PHONY: test
test:
vendor/bin/phpunit $(PHPUNIT_ARGS)

.PHONY: cs
cs:
vendor/bin/phpcs $(PHPCS_ARGS)

.PHONY: fix
fix:
vendor/bin/phpcbf

.PHONY: static-analysis
static-analysis:
vendor/bin/phpstan analyse $(PHPSTAN_ARGS)

.PHONY: check
check: build cs static-analysis test

.PHONY: clean
clean: clean-vendor

.PHONY: clean-vendor
clean-vendor:
rm -rf vendor
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
simpod/php-snmp [![Coverage Status](https://coveralls.io/repos/github/simPod/PHP-SNMP/badge.svg)](https://coveralls.io/github/simPod/PHP-SNMP)
===============
40 changes: 33 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "simpod/php-snmp",
"description": "PHP Simple Network Management",
"description": "PHP library for connecting to the SNMP agents; includes small collection of OIDs, neatly packed into classes/methods for convenient use.",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Simon Podlipsky",
"name": "Šimon Podlipský",
"email": "simon@podlipsky.net"
},
{
"name": "Jakub Chábek",
"email": "jakub@chabek.cz"
}
],
"keywords": [
Expand All @@ -17,14 +21,36 @@
"sort-packages": true
},
"require": {
"php": "^7.2",
"ext-snmp": "*",
"consistence/consistence": "^1.0|^2.0"
"php": "^7.3|^8.0"
},
"suggest": {
"ext-json": "Required for SNMP transport \"Api\"",
"ext-snmp": "Required for SNMP transport \"Extension\"",
"symfony/process": "Required for default implementation of SNMP transport \"Cli\"",
"nyholm/psr7": "Required for SNMP transport \"Api\"",
"psr/http-client": "Required for SNMP transport \"Api\"",
"psr/http-factory": "Required for SNMP transport \"Api\"",
"psr/http-message": "Required for SNMP transport \"Api\""
},
"require-dev": {
"ext-json": "*",
"ext-snmp": "*",
"cdn77/coding-standard": "^3.0",
"phpstan/phpstan": "^0.11.5",
"phpstan/phpstan-strict-rules": "^0.11.0"
"nyholm/psr7": "^1.3",
"php-http/curl-client": "^2.1",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.25",
"phpstan/phpstan-deprecation-rules": "^0.12.3",
"phpstan/phpstan-phpunit": "^0.12.8",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.1",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"simpod/php-coveralls-mirror": "^3.0",
"squizlabs/php_codesniffer": "^3.5",
"symfony/process": "^4.3",
"thecodingmachine/phpstan-safe-rule": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 4 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
parameters:
memory-limit: -1
level: max
paths:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
ignoreErrors:
# extension is badly designed, we know these types won't ever be here
- '~Parameter #1 \$output of method SimPod\\PhpSnmp\\Transport\\ExtensionSnmpClient::processOutput\(\) expects array<string, string>, array\|string\|false given\.~'
- '~Parameter #1 \$output of method SimPod\\PhpSnmp\\Transport\\ExtensionSnmpClient::processOutput\(\) expects array<string, string>, array\|false given\.~'
17 changes: 3 additions & 14 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
executionOrder="random"
colors="true"
bootstrap="tests/bootstrap.php"
>
Expand All @@ -15,18 +14,8 @@
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log
showOnlySummary="true"
showUncoveredFiles="true"
target="php://stdout"
type="coverage-text"
/>
<log type="coverage-clover" target="temp/clover.xml"/>
<log type="coverage-html" target="temp/coverage-html"/>
</logging>
</phpunit>
16 changes: 16 additions & 0 deletions src/Exception/CannotParseUnknownValueType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace SimPod\PhpSnmp\Exception;

use RuntimeException;
use function Safe\sprintf;

final class CannotParseUnknownValueType extends RuntimeException implements SnmpException
{
public static function new(string $type) : self
{
return new self(sprintf('Encountered unknown value type "%s"', $type));
}
}

0 comments on commit b173ce8

Please sign in to comment.