Skip to content

Commit

Permalink
updates tests for PHPUnit 8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Feb 27, 2020
1 parent b90b2d2 commit 1a1d25f
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 189 deletions.
44 changes: 20 additions & 24 deletions tests/Commands/AddCustomDimensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,35 @@
*/
class AddCustomDimensionTest extends IntegrationTestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The specified scope is invalid. Use either
*/
public function testExecute_ShouldThrowException_IfArgumentIsMissing()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The specified scope is invalid. Use either');

$this->executeCommand(null, null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The specified scope is invalid. Use either "--scope=visit" or "--scope=action"
*/
public function testExecute_ShouldThrowException_IfScopeIsInvalid()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The specified scope is invalid. Use either "--scope=visit" or "--scope=action"');

$this->executeCommand('invalidscope', null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Option "count" must be a number
*/
public function testExecute_ShouldThrowException_IfCountIsNotANumber()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Option "count" must be a number');

$this->executeCommand(CustomDimensions::SCOPE_VISIT, '545fddfd');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Option "count" must be at least one
*/
public function testExecute_ShouldThrowException_IfCountIsLessThanONe()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Option "count" must be at least one');

$this->executeCommand(CustomDimensions::SCOPE_VISIT, '0');
}

Expand All @@ -79,10 +75,10 @@ public function testExecute_ShouldAddSpecifiedCount()

$result = $this->executeCommand(CustomDimensions::SCOPE_ACTION, $count = 3);

$this->assertContains('Adding 3 Custom Dimension(s) in scope action.', $result);
$this->assertContains('Are you sure you want to perform this action?', $result);
$this->assertContains('Starting to add Custom Dimension(s)', $result);
$this->assertContains('Your Piwik is now configured for up to 8 Custom Dimensions in scope action.', $result);
self::assertStringContainsString('Adding 3 Custom Dimension(s) in scope action.', $result);
self::assertStringContainsString('Are you sure you want to perform this action?', $result);
self::assertStringContainsString('Starting to add Custom Dimension(s)', $result);
self::assertStringContainsString('Your Piwik is now configured for up to 8 Custom Dimensions in scope action.', $result);

$logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
$this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
Expand All @@ -107,10 +103,10 @@ public function testExecute_ShouldAddSpecifiedCount_IfScopeIsVisitShouldAlsoUpda

$result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $count = 2);

$this->assertContains('Adding 2 Custom Dimension(s) in scope visit.', $result);
$this->assertContains('Are you sure you want to perform this action?', $result);
$this->assertContains('Starting to add Custom Dimension(s)', $result);
$this->assertContains('Your Piwik is now configured for up to 7 Custom Dimensions in scope visit.', $result);
self::assertStringContainsString('Adding 2 Custom Dimension(s) in scope visit.', $result);
self::assertStringContainsString('Are you sure you want to perform this action?', $result);
self::assertStringContainsString('Starting to add Custom Dimension(s)', $result);
self::assertStringContainsString('Your Piwik is now configured for up to 7 Custom Dimensions in scope visit.', $result);

$logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
$this->assertSame(range(1,7), $logVisit->getInstalledIndexes());
Expand Down
4 changes: 2 additions & 2 deletions tests/Commands/InfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testExecute_ShouldOutputInfoSuccess_IfEverythingIsOk()
{
$output = $this->executeCommand();

$this->assertContains('./console customdimensions:add-custom-dimension --scope=visit"
self::assertStringContainsString('./console customdimensions:add-custom-dimension --scope=visit"
Installed indexes are:
1 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=1
2 to remove this Custom Dimension execute ./console customdimensions:remove-custom-dimension --scope=visit --index=2
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testExecute_ShouldOutputErrorMessage_IfColumnsDoNotMatch()
$model = new LogTable(CustomDimensions::SCOPE_CONVERSION);
$model->removeCustomDimension(5);

$this->assertContains('We found an error, Custom Dimensions in scope "conversion" are not correctly installed. Execute the following command to repair it:
self::assertStringContainsString('We found an error, Custom Dimensions in scope "conversion" are not correctly installed. Execute the following command to repair it:
./console customdimensions:add-custom-dimension --scope=conversion --count=1', $this->executeCommand());
}

Expand Down
51 changes: 23 additions & 28 deletions tests/Commands/RemoveCustomDimensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,43 @@
*/
class RemoveCustomDimensionTest extends IntegrationTestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The specified scope is invalid. Use either
*/
public function testExecute_ShouldThrowException_IfArgumentIsMissing()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The specified scope is invalid. Use either');

$this->executeCommand(null, null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The specified scope is invalid. Use either "--scope=visit" or "--scope=action"
*/
public function testExecute_ShouldThrowException_IfScopeIsInvalid()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The specified scope is invalid. Use either "--scope=visit" or "--scope=action"');

$this->executeCommand('invalidscope', null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage An option "index" must be specified
*/
public function testExecute_ShouldThrowException_IfIndexIsNotSpecifed()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('An option "index" must be specified');

$this->executeCommand(CustomDimensions::SCOPE_VISIT, null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Option "index" must be a number
*/
public function testExecute_ShouldThrowException_IfIndexIsNotANumber()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Option "index" must be a number');

$this->executeCommand(CustomDimensions::SCOPE_VISIT, '545fddfd');
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Specified index is not installed
*/
public function testExecute_ShouldThrowException_IfCountIsLessThanONe()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Specified index is not installed');

$this->executeCommand(CustomDimensions::SCOPE_VISIT, '14');
}

Expand All @@ -88,10 +83,10 @@ public function testExecute_ShouldAddSpecifiedCount()

$result = $this->executeCommand(CustomDimensions::SCOPE_ACTION, $index = 3);

$this->assertContains('Remove Custom Dimension at index 3 in scope action.', $result);
$this->assertContains('Are you sure you want to perform this action?', $result);
$this->assertContains('Starting to remove this Custom Dimension', $result);
$this->assertContains('Your Piwik is now configured for up to 4 Custom Dimensions in scope action.', $result);
self::assertStringContainsString('Remove Custom Dimension at index 3 in scope action.', $result);
self::assertStringContainsString('Are you sure you want to perform this action?', $result);
self::assertStringContainsString('Starting to remove this Custom Dimension', $result);
self::assertStringContainsString('Your Piwik is now configured for up to 4 Custom Dimensions in scope action.', $result);

$logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
$this->assertSame(range(1,5), $logVisit->getInstalledIndexes());
Expand All @@ -113,10 +108,10 @@ public function testExecute_ShouldAddSpecifiedCount_IfScopeIsVisitShouldAlsoUpda

$result = $this->executeCommand(CustomDimensions::SCOPE_VISIT, $index = 2);

$this->assertContains('Remove Custom Dimension at index 2 in scope visit', $result);
$this->assertContains('Are you sure you want to perform this action?', $result);
$this->assertContains('Starting to remove this Custom Dimension', $result);
$this->assertContains('Your Piwik is now configured for up to 4 Custom Dimensions in scope visit.', $result);
self::assertStringContainsString('Remove Custom Dimension at index 2 in scope visit', $result);
self::assertStringContainsString('Are you sure you want to perform this action?', $result);
self::assertStringContainsString('Starting to remove this Custom Dimension', $result);
self::assertStringContainsString('Your Piwik is now configured for up to 4 Custom Dimensions in scope visit.', $result);

$logVisit = new LogTable(CustomDimensions::SCOPE_VISIT);
$this->assertSame(array(1,3,4,5), $logVisit->getInstalledIndexes());
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/TrackVisitsWithCustomDimensionsFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class TrackVisitsWithCustomDimensionsFixture extends Fixture
public $idSite = 1;
public $idSite2 = 2;

public function setUp()
public function setUp(): void
{
$this->setUpWebsites();
$this->addGoals();
Expand All @@ -37,7 +37,7 @@ public function setUp()
$this->trackThirdVisit();
}

public function tearDown()
public function tearDown(): void
{
// empty
}
Expand Down
55 changes: 24 additions & 31 deletions tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ApiTest extends IntegrationTestCase
*/
private $api;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -51,7 +51,7 @@ public function test_configureNewDimension_shouldFailWhenThereIsAnError($dimensi
try {
$this->api->configureNewCustomDimension($idSite = 1, $dimension['name'], $dimension['scope'], $dimension['active'], $dimension['extractions'], $dimension['case_sensitive']);
} catch (Exception $e) {
$this->assertContains($dimension['message'], $e->getMessage());
self::assertStringContainsString($dimension['message'], $e->getMessage());
return;
}

Expand Down Expand Up @@ -94,12 +94,11 @@ public function test_configureNewDimension_shouldReturnCreatedIdOnSuccess()
$this->assertSame(array($expectedDimension), $dimensions);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasWriteAccess
*/
public function test_configureNewDimension_shouldFailWhenNotHavingAdminPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasWriteAccess');

$this->setUser();
$this->api->configureNewCustomDimension($idSite = 1, 'Valid Name äöü', CustomDimensions::SCOPE_VISIT, '1', array(array('dimension' => 'urlparam', 'pattern' => 'test')));
}
Expand All @@ -113,7 +112,7 @@ public function test_configureExistingCustomDimension_shouldFailWhenThereIsAnErr
$this->test_configureNewDimension_shouldReturnCreatedIdOnSuccess();
$this->api->configureExistingCustomDimension($dimension['id'], $idSite = 1, $dimension['name'], $dimension['active'], $dimension['extractions']);
} catch (Exception $e) {
$this->assertContains($dimension['message'], $e->getMessage());
self::assertStringContainsString($dimension['message'], $e->getMessage());
return;
}

Expand Down Expand Up @@ -163,62 +162,56 @@ public function test_configureExistingCustomDimension_shouldNotChangeCaseSensiti
$this->assertFalse($dimensions[0]['case_sensitive']);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Extractions can be used only in scope 'action'
*/
public function test_configureExistingCustomDimension_shouldThrowException_WhenTryingToSetExtractionsForNonActionScope()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Extractions can be used only in scope \'action\'');

$id = $this->api->configureNewCustomDimension($idSite = 1, 'Name', CustomDimensions::SCOPE_VISIT, '1');
$this->api->configureExistingCustomDimension($id, $idSite, 'Name', '0', array(array('dimension' => 'urlparam', 'pattern' => 'newtest')));
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasWriteAccess
*/
public function test_configureExistingCustomDimension_shouldFailWhenNotHavingAdminPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasWriteAccess');

$this->setUser();
$this->api->configureExistingCustomDimension($id = 1, $idSite = 1, 'New Valid Name äöü', '0', array(array('dimension' => 'urlparam', 'pattern' => 'newtest')));
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasViewAccess
*/
public function test_getConfiguredCustomDimensions_shouldFailWhenNotHavingAdminPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasViewAccess');

$this->setAnonymousUser();
$this->api->getConfiguredCustomDimensions($idSite = 1);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasViewAccess
*/
public function test_getAvailableScopes_shouldFailWhenNotHavingAdminPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasViewAccess');

$this->setAnonymousUser();
$this->api->getAvailableScopes($idSite = 1);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasSomeWriteAccess
*/
public function test_getAvailableExtractionDimensions_shouldFailWhenNotHavingAdminPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasSomeWriteAccess');

$this->setUser();
$this->api->getAvailableExtractionDimensions();
}

/**
* @expectedException \Exception
* @expectedExceptionMessage checkUserHasViewAccess
*/
public function test_getCustomDimension_shouldFailWhenNotHavingViewPermissions()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('checkUserHasViewAccess');

$this->setAnonymousUser();
$this->api->getCustomDimension($idDimension = 1, $idSite = 1, $period = 'day', $date = 'today');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/CustomDimensionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CustomDimensionsTest extends IntegrationTestCase
*/
private $plugin;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
16 changes: 7 additions & 9 deletions tests/Integration/Dao/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConfigurationTest extends IntegrationTestCase

private $tableName;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -48,12 +48,11 @@ public function test_shouldInstallConfigTable()
$this->assertSame($expected, $columns);
}

/**
* @expectedException \Zend_Db_Statement_Exception
* @expectedExceptionMessage custom_dimensions
*/
public function test_shouldBeAbleToUninstallConfigTable()
{
$this->expectException(\Zend_Db_Statement_Exception::class);
$this->expectExceptionMessage('custom_dimensions');

$this->config->uninstall();

try {
Expand Down Expand Up @@ -82,12 +81,11 @@ public function test_configureNewDimension_shouldGenerateDimensionIdCorrectlyAnd
}
}

/**
* @expectedException \Zend_Db_Statement_Exception
* @expectedExceptionMessage Duplicate
*/
public function test_configureNewDimension_shouldNotBePossibleToAssignSameIndexForSameScopeAndIdSiteTwice()
{
$this->expectException(\Zend_Db_Statement_Exception::class);
$this->expectExceptionMessage('Duplicate');

$this->configureNewDimension();
$this->configureNewDimension();
}
Expand Down
Loading

0 comments on commit 1a1d25f

Please sign in to comment.