From 77ddfec2963d1790eb78b1e1537dd55e9809bd07 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Sun, 9 Feb 2020 12:27:18 +0100 Subject: [PATCH] updates tests for PHPUnit 8.5 --- .../TestCase/IntegrationTestCase.php | 2 +- tests/Integration/Queue/Backend/MysqlTest.php | 4 +- tests/Integration/Queue/Backend/RedisTest.php | 2 +- .../Queue/Backend/SentinelTest.php | 11 +- tests/Integration/Queue/FactoryTest.php | 7 +- tests/Integration/Queue/LockTest.php | 4 +- tests/Integration/Queue/ManagerTest.php | 4 +- .../Queue/Processor/HandlerTest.php | 4 +- tests/Integration/Queue/ProcessorTest.php | 11 +- tests/Integration/QueueTest.php | 4 +- tests/Integration/QueuedTrackingTest.php | 2 +- tests/Integration/Settings/NumWorkersTest.php | 4 +- tests/Integration/SettingsTest.php | 149 ++++++++---------- tests/Integration/SystemCheckTest.php | 16 +- tests/Integration/Tracker/HandlerTest.php | 4 +- tests/System/TrackerTest.php | 4 +- tests/Unit/ConfigurationTest.php | 2 +- tests/Unit/Queue/Processor/HandlerTest.php | 2 +- 18 files changed, 106 insertions(+), 130 deletions(-) diff --git a/tests/Framework/TestCase/IntegrationTestCase.php b/tests/Framework/TestCase/IntegrationTestCase.php index 58018ca..832834a 100644 --- a/tests/Framework/TestCase/IntegrationTestCase.php +++ b/tests/Framework/TestCase/IntegrationTestCase.php @@ -22,7 +22,7 @@ class IntegrationTestCase extends \Piwik\Tests\Framework\TestCase\IntegrationTes { protected $testRequiresRedis = true; - public function setUp() + public function setUp(): void { if ($this->testRequiresRedis && !self::isRedisAvailable()) { $this->markTestSkipped('Redis extension is not installed, skipping test'); diff --git a/tests/Integration/Queue/Backend/MysqlTest.php b/tests/Integration/Queue/Backend/MysqlTest.php index 125eae4..6f622b5 100644 --- a/tests/Integration/Queue/Backend/MysqlTest.php +++ b/tests/Integration/Queue/Backend/MysqlTest.php @@ -30,7 +30,7 @@ class MysqlTest extends IntegrationTestCase private $listKey = 'testMyListTestKey'; private $key = 'testKeyValueKey'; - public function setUp() + public function setUp(): void { if (!$this->hasDependencies()) { parent::setUp(); @@ -50,7 +50,7 @@ public function setUp() } } - public function tearDown() + public function tearDown(): void { $GLOBALS['PIWIK_TRACKER_MODE'] = false; Db::destroyDatabaseObject(); diff --git a/tests/Integration/Queue/Backend/RedisTest.php b/tests/Integration/Queue/Backend/RedisTest.php index 1818ded..8494f75 100644 --- a/tests/Integration/Queue/Backend/RedisTest.php +++ b/tests/Integration/Queue/Backend/RedisTest.php @@ -28,7 +28,7 @@ class RedisTest extends IntegrationTestCase private $listKey = 'testMyListTestKey'; private $key = 'testKeyValueKey'; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Integration/Queue/Backend/SentinelTest.php b/tests/Integration/Queue/Backend/SentinelTest.php index 4be95c2..2ae4d7d 100644 --- a/tests/Integration/Queue/Backend/SentinelTest.php +++ b/tests/Integration/Queue/Backend/SentinelTest.php @@ -20,7 +20,7 @@ */ class SentinelTest extends RedisTest { - public function setUp() + public function setUp(): void { if (self::isTravisCI()) { $this->markTestSkipped('Sentinel is not installed on travis'); @@ -28,7 +28,7 @@ public function setUp() parent::setUp(); } - public function tearDown() + public function tearDown(): void { Config::getInstance()->QueuedTracking = array(); parent::tearDown(); @@ -64,12 +64,11 @@ public function test_canCreateInstanceWithMultipleSentinelAndFallback() $this->assertTrue($sentinel->testConnection()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage QueuedTracking_NumHostsNotMatchNumPorts - */ public function test_connect_ShouldThrowException_IfNotExactSameHostAndPortNumbersGiven() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('QueuedTracking_NumHostsNotMatchNumPorts'); + $this->enableRedisSentinel(); $settings = Factory::getSettings(); diff --git a/tests/Integration/Queue/FactoryTest.php b/tests/Integration/Queue/FactoryTest.php index fe69371..36f9493 100644 --- a/tests/Integration/Queue/FactoryTest.php +++ b/tests/Integration/Queue/FactoryTest.php @@ -58,12 +58,11 @@ public function test_makeBackend_shouldReturnARedisInstance() $this->assertFalse($backend instanceof Queue\Backend\Sentinel); } - /** - * @expectedException \Exception - * @expectedExceptionMessage You must configure a sentinel master name - */ public function test_makeBackend_shouldFailToCreateASentinelInstance_IfNotFullyConfigured() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('You must configure a sentinel master name'); + Config::getInstance()->QueuedTracking = array('useSentinelBackend' => '1', 'sentinelMasterName' => ''); Factory::makeBackend(); } diff --git a/tests/Integration/Queue/LockTest.php b/tests/Integration/Queue/LockTest.php index b6f82f0..03b82d3 100644 --- a/tests/Integration/Queue/LockTest.php +++ b/tests/Integration/Queue/LockTest.php @@ -31,7 +31,7 @@ class LockTest extends IntegrationTestCase */ public $lock; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -39,7 +39,7 @@ public function setUp() $this->lock = $this->createLock($redis); } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); diff --git a/tests/Integration/Queue/ManagerTest.php b/tests/Integration/Queue/ManagerTest.php index 8ebe177..7a2bd5f 100644 --- a/tests/Integration/Queue/ManagerTest.php +++ b/tests/Integration/Queue/ManagerTest.php @@ -42,7 +42,7 @@ class ManagerTest extends IntegrationTestCase */ private $lock; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -64,7 +64,7 @@ private function createQueueManager() return array('queue' => $queue, 'lock' => $lock); } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); diff --git a/tests/Integration/Queue/Processor/HandlerTest.php b/tests/Integration/Queue/Processor/HandlerTest.php index be18429..81088cc 100644 --- a/tests/Integration/Queue/Processor/HandlerTest.php +++ b/tests/Integration/Queue/Processor/HandlerTest.php @@ -42,7 +42,7 @@ class HandlerTest extends IntegrationTestCase */ private $tracker; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -54,7 +54,7 @@ public function setUp() $this->handler->init($this->tracker); } - public function tearDown() + public function tearDown(): void { $this->handler->rollBack($this->tracker); diff --git a/tests/Integration/Queue/ProcessorTest.php b/tests/Integration/Queue/ProcessorTest.php index 63bb502..c1acab5 100644 --- a/tests/Integration/Queue/ProcessorTest.php +++ b/tests/Integration/Queue/ProcessorTest.php @@ -55,7 +55,7 @@ class ProcessorTest extends IntegrationTestCase */ private $lock; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -72,7 +72,7 @@ public function setUp() $this->processor = $this->createProcessor(); } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); @@ -155,12 +155,11 @@ public function test_process_shouldProcessEachBulkRequestsWithinRequest() $this->assertNumberOfRequestSetsLeftInQueue(2); } - /** - * @expectedException \Piwik\Plugins\QueuedTracking\Queue\LockExpiredException - * @expectedExceptionMessage Rolled back - */ public function test_processRequestSets_ShouldThrowAnExceptionAndRollback_InCaseWeDoNoLongerHaveTheLock() { + $this->expectException(\Piwik\Plugins\QueuedTracking\Queue\LockExpiredException::class); + $this->expectExceptionMessage('Rolled back'); + $queuedRequestSets = array( $this->buildRequestSet(5) ); diff --git a/tests/Integration/QueueTest.php b/tests/Integration/QueueTest.php index c883fef..ccf9fb1 100644 --- a/tests/Integration/QueueTest.php +++ b/tests/Integration/QueueTest.php @@ -27,7 +27,7 @@ class QueueTest extends IntegrationTestCase */ private $queue; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -44,7 +44,7 @@ private function createQueue($id) return $queue; } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); diff --git a/tests/Integration/QueuedTrackingTest.php b/tests/Integration/QueuedTrackingTest.php index 86fac4f..cdfcf94 100644 --- a/tests/Integration/QueuedTrackingTest.php +++ b/tests/Integration/QueuedTrackingTest.php @@ -25,7 +25,7 @@ class QueuedTrackingTest extends IntegrationTestCase */ private $plugin; - public function setUp() + public function setUp(): void { parent::setUp(); $this->plugin = new QueuedTracking(); diff --git a/tests/Integration/Settings/NumWorkersTest.php b/tests/Integration/Settings/NumWorkersTest.php index ce5a11e..0a3ac73 100644 --- a/tests/Integration/Settings/NumWorkersTest.php +++ b/tests/Integration/Settings/NumWorkersTest.php @@ -26,7 +26,7 @@ class NumWorkersTest extends IntegrationTestCase */ private $settings; - public function setUp() + public function setUp(): void { parent::setUp(); $this->clearBackend(); @@ -35,7 +35,7 @@ public function setUp() $this->settings = $container->get('Piwik\Plugins\QueuedTracking\SystemSettings'); } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); diff --git a/tests/Integration/SettingsTest.php b/tests/Integration/SettingsTest.php index 69f6d02..51c7ded 100644 --- a/tests/Integration/SettingsTest.php +++ b/tests/Integration/SettingsTest.php @@ -24,89 +24,81 @@ class SettingsTest extends IntegrationTestCase */ private $settings; - public function setUp() + public function setUp(): void { parent::setUp(); $this->settings = new SystemSettings(); } - public function tearDown() + public function tearDown(): void { parent::tearDown(); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Max 500 characters - */ public function test_redisHost_ShouldFail_IfMoreThan300CharctersGiven() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Max 500 characters'); + $this->settings->redisHost->setValue(str_pad('3', 503, '4')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Port has to be at least 1 - */ public function test_redisPort_ShouldFail_IfPortIsTooLow() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Port has to be at least 1'); + $this->settings->redisPort->setValue(0); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Port should be max 65535 - */ public function test_redisPort_ShouldFail_IfPortIsTooHigh() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Port should be max 65535'); + $this->settings->redisPort->setValue(65536); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Max 5 characters - */ public function test_redisTimeout_ShouldFail_IfTooLong() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Max 5 characters'); + $this->settings->redisTimeout->setIsWritableByCurrentUser(true); $this->settings->redisTimeout->setValue('333.43'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage should be numeric - */ public function test_redisTimeout_ShouldFail_IfNotNumeric() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('should be numeric'); + $this->settings->redisTimeout->setIsWritableByCurrentUser(true); $this->settings->redisTimeout->setValue('33d3.43'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Max 200 characters are allowed - */ public function test_sentinelMasterName_ShouldFail_IfTooManyCharacters() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Max 200 characters are allowed'); + $this->settings->sentinelMasterName->setValue(str_pad('1', 201, '1')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Max 100 characters - */ public function test_redisPassword_ShouldFail_IfMoreThan100CharctersGiven() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Max 100 characters'); + $this->settings->redisPassword->setValue(str_pad('4', 102, '4')); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Connection to Redis failed - */ public function test_queueEnabled_ShouldFail_IfEnabledButWrongConnectionDetail() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Connection to Redis failed'); + $this->settings->redisPort->setValue(6378); $this->settings->queueEnabled->setValue(true); } @@ -119,75 +111,67 @@ public function test_queueEnabled_ShouldNotFail_IfEnabledButWrongConnectionDetai $this->assertFalse($this->settings->queueEnabled->getValue()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Number should be 1 or higher - */ public function test_numRequestsToProcess_ShouldFail_IfTooLow() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Number should be 1 or higher'); + $this->settings->numRequestsToProcess->setValue(0); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Value should be a number - */ public function test_numRequestsToProcess_ShouldFail_IfNotNumeric() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Value should be a number'); + $this->settings->numRequestsToProcess->setValue('33d3.43'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The database has to be an integer - */ public function test_redisDatabase_ShouldFail_IfIsNumericButFloat() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The database has to be an integer'); + $this->settings->redisDatabase->setValue('5.34'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage The database has to be an integer - */ public function test_redisDatabase_ShouldFail_IfNotNumeric() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('The database has to be an integer'); + $this->settings->redisDatabase->setValue('33d3.43'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Max 5 digits allowed - */ public function test_redisDatabase_ShouldFail_IfTooLong() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Max 5 digits allowed'); + $this->settings->redisDatabase->setValue('333333'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage should be an integer - */ public function test_numQueueWorkers_ShouldFail_IfNotNumeric() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('should be an integer'); + $this->settings->numQueueWorkers->setValue('1f'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Only 1-16 workers allowed - */ public function test_numQueueWorkers_ShouldFail_IfTooHigh() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Only 1-16 workers allowed'); + $this->settings->numQueueWorkers->setValue('17'); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Only 1-16 workers allowed - */ public function test_numQueueWorkers_ShouldFail_IfTooLow() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Only 1-16 workers allowed'); + $this->settings->numQueueWorkers->setValue('0'); } @@ -244,12 +228,11 @@ public function test_useSentinelBackend() $this->assertTrue($this->settings->useSentinelBackend->getValue()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled - */ public function test_redisPort_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEnabled() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled'); + $this->settings->redisPort->setValue('45,56,788'); } @@ -260,23 +243,21 @@ public function test_redisPort_ShouldNotFailAndConvertToIntWhenMultipleValuesGiv $this->assertSame('55,44', $this->settings->redisPort->getValue()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage A port has to be a number - */ public function test_redisPort_ShouldValidateEachPortSeparately_WhenManySpecified() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('A port has to be a number'); + $this->enableRedisSentinel(); $this->settings->redisPort->setValue('55 , 44.34, 4mk '); $this->assertSame('55,44', $this->settings->redisPort->getValue()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled - */ public function test_redisHost_ShouldFailWhenMultipleValuesGiven_IfSentinelNotEnabled() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled'); + $this->settings->redisHost->setValue('10.0.0.1,127.0.0.1'); } @@ -388,11 +369,12 @@ public function test_convertCommaSeparatedValueToArray($stringValue, $expectedAr /** * @dataProvider getCommaSeparatedWithMultipleValues - * @expectedException \Exception - * @expectedExceptionMessage QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled */ public function test_checkMultipleServersOnlyConfiguredWhenSentinelIsEnabled_shouldFailWhenMoreThanOneValue_IfSentinelNotEnabled($stringValue) { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('QueuedTracking_MultipleServersOnlyConfigurableIfSentinelEnabled'); + $this->disableRedisSentinel(); $this->settings->checkMultipleServersOnlyConfiguredWhenSentinelIsEnabled($stringValue); @@ -417,12 +399,11 @@ public function getCommaSeparatedWithMultipleValues() ); } - /** - * @expectedException \Exception - * @expectedExceptionMessage QueuedTracking_NumHostsNotMatchNumPorts - */ public function test_save_shouldFailIfPortAndHostMismatch() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('QueuedTracking_NumHostsNotMatchNumPorts'); + $this->enableRedisSentinel(); $this->settings->redisPort->setValue('6379,6480,4393'); $this->settings->redisHost->setValue('127.0.0.1,127.0.0.2'); diff --git a/tests/Integration/SystemCheckTest.php b/tests/Integration/SystemCheckTest.php index eeee6ba..56f5a03 100644 --- a/tests/Integration/SystemCheckTest.php +++ b/tests/Integration/SystemCheckTest.php @@ -26,7 +26,7 @@ class SystemCheckTest extends IntegrationTestCase */ private $systemCheck; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -40,22 +40,20 @@ public function test_checkIsInstalled_shouldNotFailOnSystemsWherePhpRedisIsAvail $this->assertTrue(true); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Connection to Redis failed. Please verify Redis host and port - */ public function test_checkConnectionDetails_shouldFailIfServerIsWrong() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Connection to Redis failed. Please verify Redis host and port'); + $backend = $this->makeBackend('192.168.123.234', 6379, 0.2, null); $this->systemCheck->checkConnectionDetails($backend); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Connection to Redis failed. Please verify Redis host and port - */ public function test_checkConnectionDetails_shouldFailIfPortIsWrong() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('Connection to Redis failed. Please verify Redis host and port'); + $backend = $this->makeBackend('127.0.0.1', 6370, 0.2, null); $this->systemCheck->checkConnectionDetails($backend); } diff --git a/tests/Integration/Tracker/HandlerTest.php b/tests/Integration/Tracker/HandlerTest.php index 06608fd..88f5527 100644 --- a/tests/Integration/Tracker/HandlerTest.php +++ b/tests/Integration/Tracker/HandlerTest.php @@ -58,7 +58,7 @@ class HandlerTest extends IntegrationTestCase */ private $backend; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -76,7 +76,7 @@ public function setUp() $this->requestSet = new RequestSet(); } - public function tearDown() + public function tearDown(): void { $this->clearBackend(); parent::tearDown(); diff --git a/tests/System/TrackerTest.php b/tests/System/TrackerTest.php index facf38d..e11f356 100644 --- a/tests/System/TrackerTest.php +++ b/tests/System/TrackerTest.php @@ -33,7 +33,7 @@ class TrackerTest extends SystemTestCase private $requestProcessLimit = 5; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -58,7 +58,7 @@ public function setUp() $this->enableQueue(); } - public function tearDown() + public function tearDown(): void { $this->createRedisBackend()->flushAll(); diff --git a/tests/Unit/ConfigurationTest.php b/tests/Unit/ConfigurationTest.php index 3784a5c..7098604 100644 --- a/tests/Unit/ConfigurationTest.php +++ b/tests/Unit/ConfigurationTest.php @@ -22,7 +22,7 @@ class ConfigurationTest extends \PHPUnit\Framework\TestCase */ private $configuration; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Queue/Processor/HandlerTest.php b/tests/Unit/Queue/Processor/HandlerTest.php index d11acac..4860e51 100644 --- a/tests/Unit/Queue/Processor/HandlerTest.php +++ b/tests/Unit/Queue/Processor/HandlerTest.php @@ -56,7 +56,7 @@ class HandlerTest extends UnitTestCase private $transactionId = 'my4929transactionid'; - public function setUp() + public function setUp(): void { parent::setUp(); $this->handler = new TestHandler();