diff --git a/.travis.yml b/.travis.yml
index 3d4f8cb..eead7a1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,10 +1,9 @@
language: php
before_script:
- phpenv config-add travis-config.ini
- - wget http://getcomposer.org/composer.phar
- - php composer.phar install --dev
+ - composer install
php:
- - 5.5
- - 5.6
- - 7.0
+ - 7.2
+ - 7.3
+ - 7.4
script: phpunit
diff --git a/composer.json b/composer.json
index 30e1a34..5ecfab6 100644
--- a/composer.json
+++ b/composer.json
@@ -1,5 +1,6 @@
{
"name":"enygma/expose",
+ "version": "4.0.0",
"type":"library",
"description":"An intrusion detection library based on PHPIDS",
"keywords":["ids","intrusion","detection"],
@@ -13,13 +14,13 @@
}
],
"require":{
- "php":">=5.3.1",
- "twig/twig": "1.*|2.*",
- "monolog/monolog": "~1.4",
- "symfony/console": "~2.1|~3.0"
+ "php":">=7.2",
+ "twig/twig": "~3.0",
+ "monolog/monolog": "~2.0",
+ "symfony/console": "~2.1|~3.0|~4.0|~5.0"
},
"require-dev" : {
- "phpunit/phpunit": "3.7.*",
+ "phpunit/phpunit": "7.*",
"squizlabs/php_codesniffer": "1.*",
"phpmd/phpmd": "dev-master"
},
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6d3f7e0..ca36fe6 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -3,9 +3,7 @@
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
- mapTestClassNameToCoveredClassName="true"
bootstrap="vendor/autoload.php"
- strict="true"
verbose="true"
colors="true">
@@ -13,4 +11,12 @@
./tests/
+
+
+ src
+
+ src/autoload.php
+
+
+
diff --git a/src/Expose/Queue/Mongo.php b/src/Expose/Queue/Mongo.php
index 7f77fc5..1ca4889 100644
--- a/src/Expose/Queue/Mongo.php
+++ b/src/Expose/Queue/Mongo.php
@@ -2,6 +2,8 @@
namespace Expose\Queue;
+use MongoDB\Driver\Manager;
+
class Mongo extends \Expose\Queue
{
/**
@@ -24,7 +26,7 @@ class Mongo extends \Expose\Queue
public function getAdapter()
{
if ($this->adapter === null) {
- $this->setAdapter(new \MongoClient());
+ $this->setAdapter(new Manager());
}
return $this->adapter;
}
diff --git a/tests/ConverterConvertSQLTest.php b/tests/ConverterConvertSQLTest.php
index 0c54780..168ecb5 100644
--- a/tests/ConverterConvertSQLTest.php
+++ b/tests/ConverterConvertSQLTest.php
@@ -2,7 +2,9 @@
namespace Expose\Converter;
-class ConvertSQLTest extends \PHPUnit_Framework_TestCase
+use PHPUnit\Framework\TestCase;
+
+class ConvertSQLTest extends TestCase
{
/**
@@ -12,7 +14,7 @@ class ConvertSQLTest extends \PHPUnit_Framework_TestCase
*/
public function testConvertFromSQLKeywordsWithNull()
{
- $converter = new \Expose\Converter\ConvertSQL();
+ $converter = new ConvertSQL();
$this->assertEquals($converter->convertFromSQLKeywords('SELECT 1,null;'), 'SELECT 1,0;');
$this->assertEquals($converter->convertFromSQLKeywords('SELECT 1, null;'), 'SELECT 1,0;');
}
diff --git a/tests/Expose/Console/Command/FilterCommandTest.php b/tests/Expose/Console/Command/FilterCommandTest.php
new file mode 100644
index 0000000..2d40f4c
--- /dev/null
+++ b/tests/Expose/Console/Command/FilterCommandTest.php
@@ -0,0 +1,14 @@
+assertInstanceOf('Expose\Console\Command\FilterCommand', $tst);
+ }
+}
diff --git a/tests/Expose/Queue/MongoTest.php b/tests/Expose/Queue/MongoTest.php
new file mode 100644
index 0000000..a067f03
--- /dev/null
+++ b/tests/Expose/Queue/MongoTest.php
@@ -0,0 +1,25 @@
+test = new Mongo();
+ }
+
+ public function testGetAdapter()
+ {
+ $this->assertInstanceOf(Manager::class, $this->test->getAdapter());
+ }
+}
diff --git a/tests/FilterCollectionTest.php b/tests/FilterCollectionTest.php
index 5108d95..0530502 100644
--- a/tests/FilterCollectionTest.php
+++ b/tests/FilterCollectionTest.php
@@ -2,14 +2,16 @@
namespace Expose;
-class FilterConnectionTest extends \PHPUnit_Framework_TestCase
+use PHPUnit\Framework\TestCase;
+
+class FilterConnectionTest extends TestCase
{
/**
* @var \Expose\FilterCollection
*/
private $collection = null;
- public function setUp()
+ public function setUp(): void
{
$this->collection = new FilterCollection();
}
@@ -26,7 +28,7 @@ public function testGetSetFilterData()
array('id' => 1234)
);
- $filter = new \Expose\Filter();
+ $filter = new Filter();
$filter->setId(1234);
$this->collection->setFilterData($data);
@@ -46,7 +48,7 @@ public function testGetFilterDataWithId() {
array('id' => 1234)
);
- $filter = new \Expose\Filter();
+ $filter = new Filter();
$filter->setId(1234);
$this->collection->setFilterData($data);
diff --git a/tests/FilterTest.php b/tests/FilterTest.php
index 2f7ce1f..8034701 100644
--- a/tests/FilterTest.php
+++ b/tests/FilterTest.php
@@ -2,18 +2,20 @@
namespace Expose;
-class FilterTest extends \PHPUnit_Framework_TestCase
+use PHPUnit\Framework\TestCase;
+
+class FilterTest extends TestCase
{
private $filter = null;
- public function setUp()
+ public function setUp(): void
{
- $this->filter = new \Expose\Filter();
+ $this->filter = new Filter();
}
/**
* Test the getter/setter for impact value
- *
+ *
* @covers \Expose\Filter::setImpact
* @covers \Expose\Filter::getImpact
*/
@@ -29,7 +31,7 @@ public function testGetSetImpact()
/**
* Test the getter/setter for the tag value
- *
+ *
* @covers \Expose\Filter::setTags
* @covers \Expose\Filter::getTags
*/
@@ -45,7 +47,7 @@ public function testGetSetTags()
/**
* Test the getter/setter for the description
- *
+ *
* @covers \Expose\Filter::setDescription
* @covers \Expose\Filter::getDescription
*/
@@ -61,7 +63,7 @@ public function testGetSetDescription()
/**
* Test the getter/setter for the ID
- *
+ *
* @covers \Expose\Filter::setId
* @covers \Expose\Filter::getId
*/
@@ -77,7 +79,7 @@ public function testGetSetId()
/**
* Test the gettet/setter for the regex rule
- *
+ *
* @covers \Expose\Filter::setRule
* @covers \Expose\Filter::getRule
*/
@@ -94,7 +96,7 @@ public function testGetSetRule()
/**
* Test that the result is true when a match is found
* for the rule
- *
+ *
* @covers \Expose\Filter::setRule
* @covers \Expose\Filter::execute
*/
@@ -111,7 +113,7 @@ public function testMatchDataValid()
/**
* Test that the result is false when a match is not found
- *
+ *
* @covers \Expose\Filter::setRule
* @covers \Expose\Filter::execute
*/
@@ -128,7 +130,7 @@ public function testMAtchDataInvalid()
/**
* Test that the output of the data in an array is correct
- *
+ *
* @covers \Expose\Filter::toArray
*/
public function testOutputAsArray()
@@ -140,11 +142,11 @@ public function testOutputAsArray()
'tags' => array('csrf', 'xss'),
'impact' => 3
);
- $filter = new \Expose\Filter($data);
+ $filter = new Filter($data);
$data['tags'] = 'csrf, xss';
$this->assertEquals(
$filter->toArray(), $data
);
}
-}
\ No newline at end of file
+}
diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php
index b86f29f..2972433 100644
--- a/tests/ManagerTest.php
+++ b/tests/ManagerTest.php
@@ -2,11 +2,18 @@
namespace Expose;
+use Expose\Exception\QueueNotDefined;
+use Expose\Log\Mongo;
+use Expose\Notify\Email;
+use Expose\Queue\MockQueue;
+use PHPUnit\Framework\TestCase;
+
require_once 'MockLogger.php';
require_once 'MockQueue.php';
-class ManagerTest extends \PHPUnit_Framework_TestCase
+class ManagerTest extends TestCase
{
+ /** @var Manager */
private $manager = null;
private $sampleFilters = array(
array(
@@ -18,20 +25,20 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
),
);
- public function setUp()
+ public function setUp(): void
{
- $logger = new \Expose\Log\Mongo();
- $filters = new \Expose\FilterCollection();
- $this->manager = new \Expose\Manager($filters, $logger);
+ $logger = new Mongo();
+ $filters = new FilterCollection();
+ $this->manager = new Manager($filters, $logger);
}
public function executeFilters($data, $queue = false, $notify = false)
{
- $filterCollection = new \Expose\FilterCollection();
+ $filterCollection = new FilterCollection();
$filterCollection->setFilterData($this->sampleFilters);
$logger = new MockLogger();
- $manager = new \Expose\Manager($filterCollection, $logger);
+ $manager = new Manager($filterCollection, $logger);
$manager->setConfig(array('test' => 'foo'));
$manager->run($data, $queue, $notify);
@@ -47,7 +54,7 @@ public function executeFilters($data, $queue = false, $notify = false)
*/
public function testGetSetFilters()
{
- $filters = new \Expose\FilterCollection();
+ $filters = new FilterCollection();
$filters->setFilterData($this->sampleFilters);
$this->manager->setFilters($filters);
@@ -71,7 +78,7 @@ public function testGetSetData()
$this->manager->setData($data);
$getData = $this->manager->getData();
$this->assertTrue(
- $getData instanceof \Expose\DataCollection
+ $getData instanceof DataCollection
);
}
@@ -127,11 +134,11 @@ public function testRunSuccessWithImpactLimit()
)
);
- $filterCollection = new \Expose\FilterCollection();
+ $filterCollection = new FilterCollection();
$filterCollection->setFilterData($this->sampleFilters);
$logger = new MockLogger();
- $manager = new \Expose\Manager($filterCollection, $logger);
+ $manager = new Manager($filterCollection, $logger);
$manager->setImpactLimit(1);
$manager->setConfig(array('test' => 'foo'));
$manager->run($data, false, false);
@@ -160,7 +167,7 @@ public function testRunExportFound()
$this->assertEquals(count($export), 1);
$report = array_shift($export);
- $this->assertTrue($report instanceof \Expose\Report);
+ $this->assertTrue($report instanceof Report);
}
/**
@@ -273,11 +280,11 @@ public function testSetupConfigArray()
*/
public function testExceptionIsIgnored()
{
- $filterCollection = new \Expose\FilterCollection();
+ $filterCollection = new FilterCollection();
$filterCollection->setFilterData($this->sampleFilters);
$logger = new MockLogger();
- $manager = new \Expose\Manager($filterCollection, $logger);
+ $manager = new Manager($filterCollection, $logger);
$manager->setConfig(array('test' => 'foo'));
$manager->setException('POST.foo');
$manager->setException('POST.bar.baz');
@@ -303,11 +310,11 @@ public function testExceptionIsIgnored()
*/
public function testExceptionWildcardIsIgnored()
{
- $filterCollection = new \Expose\FilterCollection();
+ $filterCollection = new FilterCollection();
$filterCollection->setFilterData($this->sampleFilters);
$logger = new MockLogger();
- $manager = new \Expose\Manager($filterCollection, $logger);
+ $manager = new Manager($filterCollection, $logger);
$manager->setConfig(array('test' => 'foo'));
$manager->setException('POST.foo[0-9]+');
@@ -329,7 +336,7 @@ public function testExceptionWildcardIsIgnored()
*/
public function testGetSetQueue()
{
- $queue = new \Expose\Queue\MockQueue();
+ $queue = new MockQueue();
$this->manager->setQueue($queue);
$this->assertEquals(
@@ -343,10 +350,10 @@ public function testGetSetQueue()
* first gives us an exception
*
* @covers \Expose\Manager::getQueue
- * @expectedException \Expose\Exception\QueueNotDefined
*/
public function testGetUndefinedQueue()
{
+ $this->expectException(QueueNotDefined::class);
$queue = $this->manager->getQueue();
}
@@ -358,7 +365,7 @@ public function testGetUndefinedQueue()
*/
public function testGetSetNotify()
{
- $notify = new \Expose\Notify\Email();
+ $notify = new Email();
$this->manager->setNotify($notify);
$this->assertEquals(
@@ -369,14 +376,14 @@ public function testGetSetNotify()
public function testThresholdLowerThenImpact() {
- $filter = new \Expose\Filter();
+ $filter = new Filter();
$filter->setImpact(100);
- $collection = new \Expose\FilterCollection();
+ $collection = new FilterCollection();
$collection->addFilter($filter);
$manager_mock = $this->getMockBuilder('\\Expose\\Manager')
- ->setConstructorArgs(array($collection, new \Expose\MockLogger()))
+ ->setConstructorArgs(array($collection, new MockLogger()))
->setMethods(array('sendNotification'))
->getMock();
@@ -390,14 +397,14 @@ public function testThresholdLowerThenImpact() {
}
public function testThresholdHigherThenImpact() {
- $filter = new \Expose\Filter();
+ $filter = new Filter();
$filter->setImpact(5);
- $collection = new \Expose\FilterCollection();
+ $collection = new FilterCollection();
$collection->addFilter($filter);
$manager_mock = $this->getMockBuilder('\\Expose\\Manager')
- ->setConstructorArgs(array($collection, new \Expose\MockLogger()))
+ ->setConstructorArgs(array($collection, new MockLogger()))
->setMethods(array('sendNotification'))
->getMock();
diff --git a/tests/MockMongoCollection.php b/tests/MockMongoCollection.php
index eaff262..2c3948a 100644
--- a/tests/MockMongoCollection.php
+++ b/tests/MockMongoCollection.php
@@ -13,11 +13,11 @@ class MockMongoCollection
public function __construct($data)
{
- $this->data = new \Expose\MockMongoCursor($data);
+ $this->data = new MockMongoCursor($data);
}
public function __call($name, $args)
{
return $this->data;
}
-}
\ No newline at end of file
+}
diff --git a/tests/Notify/EmailTest.php b/tests/Notify/EmailTest.php
index f5e5de0..624a6a6 100644
--- a/tests/Notify/EmailTest.php
+++ b/tests/Notify/EmailTest.php
@@ -2,13 +2,16 @@
namespace Expose\Notify;
-class EmailTest extends \PHPUnit_Framework_TestCase
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
+
+class EmailTest extends TestCase
{
private $email = null;
- public function setUp()
+ public function setUp(): void
{
- $this->email = new \Expose\Notify\Email();
+ $this->email = new Email();
}
/**
@@ -32,10 +35,10 @@ public function testSetToAddress()
* Try to set an invalid email To address
*
* @covers \Expose\Notify\Email::setToAddress
- * @expectedException \InvalidArgumentException
*/
public function testSetInvalidEmailToAddress()
{
+ $this->expectException(InvalidArgumentException::class);
$email = 'invalidemail';
$this->email->setToAddress($email);
}
@@ -61,11 +64,11 @@ public function testSetFromAddress()
* Try to set an invalid email From address
*
* @covers \Expose\Notify\Email::setFromAddress
- * @expectedException \InvalidArgumentException
*/
public function testSetInvalidEmailFromAddress()
{
+ $this->expectException(InvalidArgumentException::class);
$email = 'invalidemail';
$this->email->setFromAddress($email);
}
-}
\ No newline at end of file
+}
diff --git a/tests/QueueTest.php b/tests/QueueTest.php
index 48b9313..023d85b 100644
--- a/tests/QueueTest.php
+++ b/tests/QueueTest.php
@@ -2,41 +2,50 @@
namespace Expose;
+use Expose\Queue\Mongo;
+use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use stdClass;
+
include_once 'MockMongoCollection.php';
-class QueueTest extends \PHPUnit_Framework_TestCase
+class QueueTest extends TestCase
{
private $queue = null;
/**
* Get a mock of the Queue object that returns the given results
- *
+ *
* @param mixed $return Return data
- * @return Mocked object
+ *
+ * @return MockObject
*/
public function getQueueMock($return)
{
- $collection = new \Expose\MockMongoCollection($return);
+ $collection = new MockMongoCollection($return);
- $mock = $this->getMock('\\Expose\\Queue\\Mongo', array('getCollection'));
+ $mock = $this->getMockBuilder(
+ Mongo::class
+ )->setMethods(array('getCollection'))
+ ->getMock();
$mock->expects($this->once())
->method('getCollection')
->will($this->returnValue($collection));
-
+
return $mock;
}
/**
* Test the setting of the adapter on object construction
- *
+ *
* @covers \Expose\Queue::__construct
* @covers \Expose\Queue::getAdapter
*/
public function testSetAdapterOnConstruct()
{
- $adapter = new \stdClass();
+ $adapter = new stdClass();
$adapter->foo = 'test';
- $queue = new \Expose\Queue\Mongo($adapter);
+ $queue = new Mongo($adapter);
$this->assertEquals(
$queue->getAdapter(),
@@ -46,16 +55,16 @@ public function testSetAdapterOnConstruct()
/**
* Test the getter/setter for the adapter of the queue
- *
+ *
* @covers \Expose\Queue::getAdapter
* @covers \Expose\Queue::setAdapter
*/
public function testGetSetAdapter()
{
- $adapter = new \stdClass();
+ $adapter = new stdClass();
$adapter->foo = 'test';
-
- $queue = new \Expose\Queue\Mongo();
+
+ $queue = new Mongo();
$queue->setAdapter($adapter);
$this->assertEquals(
@@ -66,7 +75,7 @@ public function testGetSetAdapter()
/**
* Get the current set of pending records
- *
+ *
* @covers \Expose\Queue::getPending
*/
public function testGetPendingRecords()
@@ -85,7 +94,7 @@ public function testGetPendingRecords()
$queue = $this->getQueueMock($result);
$results = $queue->getPending();
-
+
// be sure they're all "pending"
$pass = true;
foreach ($results as $result) {
@@ -96,4 +105,4 @@ public function testGetPendingRecords()
$this->assertTrue($pass, 'Non-pending records found');
}
-}
\ No newline at end of file
+}
diff --git a/tests/ReportTest.php b/tests/ReportTest.php
index 2b552a3..3d7bdce 100644
--- a/tests/ReportTest.php
+++ b/tests/ReportTest.php
@@ -2,13 +2,15 @@
namespace Expose;
-class ReportTest extends \PHPUnit_Framework_TestCase
+use PHPUnit\Framework\TestCase;
+
+class ReportTest extends TestCase
{
private $report = null;
- public function setUp()
+ public function setUp(): void
{
- $this->report = new \Expose\Report();
+ $this->report = new Report();
}
/**
@@ -99,7 +101,7 @@ public function testObjectToArray()
*/
public function testObjectToArrayExpandFilters()
{
- $filter = new \Expose\Filter();
+ $filter = new Filter();
$filter->setId(1234);
$this->report->addFilterMatch($filter);
diff --git a/travis-config.ini b/travis-config.ini
index ea22061..33d8975 100644
--- a/travis-config.ini
+++ b/travis-config.ini
@@ -1 +1 @@
-extension = "mongo.so"
\ No newline at end of file
+extension = "mongodb.so"