Compare commits

..

6 commits

Author SHA1 Message Date
90ba4df308
ci: add newer PHP versions
Seems I had started this a while back and never actually finished.
Bumped the copyright years and added a funding and git ignore file.
Redid the Travis configuration based on my more recent experiences with
testing multiple PHP versions. Updated the development dependencies and
added a configuration file for PHPUnit.
2020-01-26 17:28:29 -06:00
805b303a04
Conditional mock method 2018-01-14 23:11:11 -06:00
83250394b0
Alias TestCase and some cleanup 2018-01-14 22:56:33 -06:00
c83f8a4914
Pin coveralls version 2018-01-09 00:26:46 -06:00
053fe5e75e
Changes to get older and newer tests running 2018-01-09 00:19:26 -06:00
7ea1bd219f
Bumped copyright, expanded PHP versions 2018-01-09 00:15:18 -06:00
9 changed files with 199 additions and 149 deletions

1
.coveralls.yml Normal file
View file

@ -0,0 +1 @@
service_name: travis-ci

View file

@ -1,29 +0,0 @@
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

40
.travis.yml Normal file
View file

@ -0,0 +1,40 @@
language: php
dist: bionic
sudo: required
matrix:
include:
- php: 5.3
dist: precise
- php: 5.4
dist: trusty
- php: 5.5
dist: trusty
- php: 5.6
dist: trusty
- php: 7.0
dist: xenial
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.4
env: COVERAGE=true
- php: nightly
allow_failures:
- php: nightly
install:
- php --version
- composer install
before_script:
- mkdir -p build/logs
script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_success:
- |
if [[ $COVERAGE ]]; then
travis_retry php vendor/bin/php-coveralls --config .coveralls.yml -v
fi

View file

@ -1 +1 @@
github: joshtronic patreon: joshtronic

View file

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2012-2014 Josh Sherman Copyright (c) 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Josh Sherman
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View file

@ -1,26 +1,33 @@
{ {
"name": "joshtronic/php-projecthoneypot", "name": "joshtronic/php-projecthoneypot",
"description": "PHP Wrapper for Project Honey Pot", "description": "PHP Wrapper for Project Honey Pot",
"version": "1.0.0", "version": "1.0.1",
"type": "library", "type": "library",
"keywords": ["project", "honey", "pot", "api", "spam", "spammer"], "keywords": [
"homepage": "https://github.com/joshtronic/php-projecthoneypot", "project",
"license": "MIT", "honey",
"authors": [{ "pot",
"name": "Josh Sherman", "api",
"email": "hello@joshtronic.com", "spam",
"homepage": "http://joshtronic.com" "spammer"
}], ],
"require": { "homepage": "https://github.com/joshtronic/php-projecthoneypot",
"php": ">=5.3.0" "license": "MIT",
}, "authors": [{
"require-dev": { "name": "Josh Sherman",
"phpunit/phpunit": "^4.8.36 || ^9.0" "email": "hello@joshtronic.com",
}, "homepage": "https://joshtronic.com"
"autoload": { }],
"psr-4": {"joshtronic\\": "src/"} "require": {
}, "php": ">=5.3"
"autoload-dev": { },
"psr-4": {"joshtronic\\Tests\\": "tests/"} "require-dev": {
"php-coveralls/php-coveralls": ">=1",
"phpunit/phpunit": ">=4"
},
"autoload": {
"psr-4": {
"joshtronic\\": "src/"
} }
}
} }

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit <phpunit
colors="true" colors="true"
bootstrap="./vendor/autoload.php"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
@ -12,7 +11,7 @@
verbose="true" verbose="true"
> >
<testsuites> <testsuites>
<testsuite name="Project Honeypot"> <testsuite name="Project Honey Pot">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>

View file

@ -9,7 +9,7 @@
* Redistribution of these files must retain the above copyright notice. * Redistribution of these files must retain the above copyright notice.
* *
* @author Josh Sherman <hello@joshtronic.com> * @author Josh Sherman <hello@joshtronic.com>
* @copyright Copyright 2012-2015, Josh Sherman * @copyright Copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018 Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html * @license http://www.opensource.org/licenses/mit-license.html
* @link https://github.com/joshtronic/php-projecthoneypot * @link https://github.com/joshtronic/php-projecthoneypot
* @link http://www.projecthoneypot.org/httpbl_configure.php * @link http://www.projecthoneypot.org/httpbl_configure.php
@ -122,7 +122,7 @@ class ProjectHoneyPot
/** /**
* DNS Get Record * DNS Get Record
* *
* Wrapper method for dns_get_record() to allow for easy mocking of the * Wrapper method for dns_get_record() to allow fo easy mocking of the
* results in our tests. Takes an already reversed IP address and does a * results in our tests. Takes an already reversed IP address and does a
* DNS lookup for A records against the http:BL API. * DNS lookup for A records against the http:BL API.
* *

View file

@ -1,22 +1,34 @@
<?php <?php
namespace joshtronic\Tests;
use joshtronic\ProjectHoneyPot;
use PHPUnit\Framework\TestCase;
class ProjectHoneyPotTest extends TestCase require_once '../src/ProjectHoneyPot.php';
if (
!class_exists('\PHPUnit_Framework_TestCase')
&& class_exists('\PHPUnit\Framework\TestCase')
) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
}
$createMock = 'createMock';
if (version_compare(PHPUnit_Runner_Version::id(), '5.4', '<=')) {
$createMock = 'getMock';
}
class ProjectHoneyPotTest extends PHPUnit_Framework_TestCase
{ {
/**
* @expectedException Exception
* @expectedExceptionMessage You must specify a valid API key.
*/
public function testInvalidKey() public function testInvalidKey()
{ {
try { new joshtronic\ProjectHoneyPot('foo');
new ProjectHoneyPot('foo');
} catch (\Exception $e) {
$this->assertSame('You must specify a valid API key.', $e->getMessage());
}
} }
public function testInvalidIP() public function testInvalidIP()
{ {
$object = new ProjectHoneyPot('foobarfoobar'); $object = new joshtronic\ProjectHoneyPot('foobarfoobar');
$this->assertEquals( $this->assertEquals(
array('error' => 'Invalid IP address.'), array('error' => 'Invalid IP address.'),
@ -26,28 +38,32 @@ class ProjectHoneyPotTest extends TestCase
public function testMissingResults() public function testMissingResults()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue('foo')); ->method('dns_get_record')
->will($this->returnValue('foo'));
$this->assertFalse($mock->query('1.2.3.4')); $this->assertFalse($mock->query('1.2.3.4'));
} }
public function testCategory0() public function testCategory0()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.0')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.0'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -56,14 +72,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory1() public function testCategory1()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.1')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.1'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -72,14 +90,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory2() public function testCategory2()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.2')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.2'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -88,14 +108,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory3() public function testCategory3()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.3')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.3'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -107,14 +129,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory4() public function testCategory4()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.4')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.4'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -126,14 +150,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory5() public function testCategory5()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.5')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.5'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -145,14 +171,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory6() public function testCategory6()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.6')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.6'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -164,14 +192,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategory7() public function testCategory7()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.7')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.7'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -183,14 +213,16 @@ class ProjectHoneyPotTest extends TestCase
public function testCategoryDefault() public function testCategoryDefault()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '127.0.0.255')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '127.0.0.255'))));
$results = $mock->query('1.2.3.4'); $results = $mock->query('1.2.3.4');
@ -202,14 +234,16 @@ class ProjectHoneyPotTest extends TestCase
public function testWithout127() public function testWithout127()
{ {
$mock = $this->getMockBuilder('joshtronic\\ProjectHoneyPot') $mock = $this->$createMock(
->setConstructorArgs(array('foobarfoobar')) 'joshtronic\ProjectHoneyPot',
->setMethods(array('dns_get_record')) array('dns_get_record'),
->getMock(); array('foobarfoobar')
);
$mock->expects($this->once()) $mock
->method('dns_get_record') ->expects($this->once())
->will($this->returnValue(array(array('ip' => '1.0.0.0')))); ->method('dns_get_record')
->will($this->returnValue(array(array('ip' => '1.0.0.0'))));
$this->assertFalse($mock->query('1.2.3.4')); $this->assertFalse($mock->query('1.2.3.4'));
} }
@ -217,11 +251,9 @@ class ProjectHoneyPotTest extends TestCase
// Doesn't serve much purpose aside from helping achieve 100% coverage // Doesn't serve much purpose aside from helping achieve 100% coverage
public function testDnsGetRecord() public function testDnsGetRecord()
{ {
$object = new ProjectHoneyPot('foobarfoobar'); $object = new joshtronic\ProjectHoneyPot('foobarfoobar');
$result = $object->dns_get_record('1.2.3.4'); $object->dns_get_record('1.2.3.4');
$this->assertEquals(array(), $result);
} }
} }