diff --git a/.coveralls.yml b/.coveralls.yml
deleted file mode 100644
index 9160059..0000000
--- a/.coveralls.yml
+++ /dev/null
@@ -1 +0,0 @@
-service_name: travis-ci
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..ddf8b8d
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,29 @@
+name: Test
+on: [push, pull_request]
+jobs:
+ test:
+ name: Test PHP ${{ matrix.php-version }}
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-version }}
+ - name: PHP Version
+ run: php --version
+ - name: Composer Version
+ run: composer --version
+ - name: Install Dependencies
+ run: COMPOSER_MEMORY_LIMIT=-1 composer install
+ - name: Run Tests
+ run: vendor/bin/phpunit --coverage-clover ./coverage.xml
+ - name: Upload Coverage
+ if: ${{ matrix.php-version == '7.4' }}
+ uses: codecov/codecov-action@v1
+ with:
+ file: ./coverage.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a2144a3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+composer.lock
+composer.phar
+.phpunit.result.cache
+/vendor/
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 8bfb40e..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-language: php
-
-php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
- - hhvm
- - hhvm-nightly
-
-matrix:
- allow_failures:
- - php: hhvm-nightly
-
-install:
- - composer install
-
-before_script:
- - mkdir -p build/logs
- - cd tests
-
-script:
- - phpunit --colors --coverage-clover /home/travis/build/joshtronic/php-projecthoneypot/build/logs/clover.xml .
-
-after_success:
- - php ../vendor/bin/coveralls --config ../.coveralls.yml -v
diff --git a/FUNDING.yml b/FUNDING.yml
new file mode 100644
index 0000000..9396c28
--- /dev/null
+++ b/FUNDING.yml
@@ -0,0 +1 @@
+github: joshtronic
diff --git a/README.md b/README.md
index d575478..be38912 100644
--- a/README.md
+++ b/README.md
@@ -3,23 +3,18 @@
[][travis]
[][coveralls]
[][packagist]
-[][gittip]
PHP Wrapper for Project Honey Pot. Compatible with PHP 5.3+ and HHVM.
## Installation
-The preferred installation method is via `composer`. First add the following
-to your `composer.json`
+The preferred installation method is via `composer`. From the root of your
+project simply run:
-```json
-"require": {
- "joshtronic/php-projecthoneypot": "dev-master"
-}
+```shell
+composer require "joshtronic/php-projecthoneypot:dev-master"
```
-Then run `composer update`
-
## Usage
### Getting Started
diff --git a/composer.json b/composer.json
index e7d9e51..ed5854c 100644
--- a/composer.json
+++ b/composer.json
@@ -8,16 +8,19 @@
"license": "MIT",
"authors": [{
"name": "Josh Sherman",
- "email": "josh@gravityblvd.com",
+ "email": "hello@joshtronic.com",
"homepage": "http://joshtronic.com"
}],
- "require-dev": {
+ "require": {
"php": ">=5.3.0"
},
"require-dev": {
- "satooshi/php-coveralls": "dev-master"
+ "phpunit/phpunit": "^4.8.36 || ^9.0"
},
"autoload": {
"psr-4": {"joshtronic\\": "src/"}
+ },
+ "autoload-dev": {
+ "psr-4": {"joshtronic\\Tests\\": "tests/"}
}
}
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..82cbb00
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,24 @@
+
+
+
+
+ tests
+
+
+
+
+ ./src
+
+
+
diff --git a/src/ProjectHoneyPot.php b/src/ProjectHoneyPot.php
index 23cfb1b..a82b243 100644
--- a/src/ProjectHoneyPot.php
+++ b/src/ProjectHoneyPot.php
@@ -8,8 +8,8 @@
* Licensed under The MIT License.
* Redistribution of these files must retain the above copyright notice.
*
- * @author Josh Sherman
- * @copyright Copyright 2012-2014, Josh Sherman
+ * @author Josh Sherman
+ * @copyright Copyright 2012-2015, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @link https://github.com/joshtronic/php-projecthoneypot
* @link http://www.projecthoneypot.org/httpbl_configure.php
@@ -37,12 +37,9 @@ class ProjectHoneyPot
*/
public function __construct($api_key)
{
- if (preg_match('/^[a-z]{12}$/', $api_key))
- {
+ if (preg_match('/^[a-z]{12}$/', $api_key)) {
$this->api_key = $api_key;
- }
- else
- {
+ } else {
throw new \Exception('You must specify a valid API key.');
}
}
@@ -59,8 +56,7 @@ class ProjectHoneyPot
public function query($ip_address)
{
// Validates the IP format
- if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE))
- {
+ if (filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE)) {
// Flips the script, err, IP address
$octets = explode('.', $ip_address);
krsort($octets);
@@ -70,12 +66,10 @@ class ProjectHoneyPot
$results = $this->dns_get_record($reversed_ip);
// Processes the results
- if (isset($results[0]['ip']))
- {
+ if (isset($results[0]['ip'])) {
$results = explode('.', $results[0]['ip']);
- if ($results[0] == 127)
- {
+ if ($results[0] == 127) {
$results = array(
'last_activity' => $results[1],
'threat_score' => $results[2],
@@ -83,40 +77,31 @@ class ProjectHoneyPot
);
// Creates an array of categories
- switch ($results['categories'])
- {
+ switch ($results['categories']) {
case 0:
$categories = array('Search Engine');
break;
-
case 1:
$categories = array('Suspicious');
break;
-
case 2:
$categories = array('Harvester');
break;
-
case 3:
$categories = array('Suspicious', 'Harvester');
break;
-
case 4:
$categories = array('Comment Spammer');
break;
-
case 5:
$categories = array('Suspicious', 'Comment Spammer');
break;
-
case 6:
$categories = array('Harvester', 'Comment Spammer');
break;
-
case 7:
$categories = array('Suspicious', 'Harvester', 'Comment Spammer');
break;
-
default:
$categories = array('Reserved for Future Use');
break;
@@ -127,9 +112,7 @@ class ProjectHoneyPot
return $results;
}
}
- }
- else
- {
+ } else {
return array('error' => 'Invalid IP address.');
}
@@ -139,7 +122,7 @@ class ProjectHoneyPot
/**
* DNS Get Record
*
- * Wrapper method for dns_get_record() to allow fo easy mocking of the
+ * Wrapper method for dns_get_record() to allow for easy mocking of the
* results in our tests. Takes an already reversed IP address and does a
* DNS lookup for A records against the http:BL API.
*
diff --git a/tests/ProjectHoneyPotTest.php b/tests/ProjectHoneyPotTest.php
index 38128db..9c5e103 100644
--- a/tests/ProjectHoneyPotTest.php
+++ b/tests/ProjectHoneyPotTest.php
@@ -1,21 +1,22 @@
assertSame('You must specify a valid API key.', $e->getMessage());
+ }
}
public function testInvalidIP()
{
- $object = new joshtronic\ProjectHoneyPot('foobarfoobar');
+ $object = new ProjectHoneyPot('foobarfoobar');
$this->assertEquals(
array('error' => 'Invalid IP address.'),
@@ -25,11 +26,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testMissingResults()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -40,11 +40,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory0()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -57,11 +56,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory1()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -74,11 +72,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory2()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -91,11 +88,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory3()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -111,11 +107,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory4()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -131,11 +126,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory5()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -151,11 +145,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory6()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -171,11 +164,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategory7()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -191,11 +183,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testCategoryDefault()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -211,11 +202,10 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
public function testWithout127()
{
- $mock = $this->getMock(
- 'joshtronic\ProjectHoneyPot',
- array('dns_get_record'),
- array('foobarfoobar')
- );
+ $mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot')
+ ->setConstructorArgs(array('foobarfoobar'))
+ ->setMethods(array('dns_get_record'))
+ ->getMock();
$mock->expects($this->once())
->method('dns_get_record')
@@ -227,9 +217,11 @@ class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
// Doesn't serve much purpose aside from helping achieve 100% coverage
public function testDnsGetRecord()
{
- $object = new joshtronic\ProjectHoneyPot('foobarfoobar');
+ $object = new ProjectHoneyPot('foobarfoobar');
- $object->dns_get_record('1.2.3.4');
+ $result = $object->dns_get_record('1.2.3.4');
+
+ $this->assertEquals(array(), $result);
}
}