Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API phpunit9 support #38

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
],
"license": "BSD-3-Clause",
"require": {
"silverstripe/framework": "^4.0",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10",
"monolog/monolog": "~1.11",
"psr/log": "~1.0",
"tractorcow/silverstripe-proxy-db": "~0.1"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0",
"silverstripe/versioned": "^1.0"
},
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
<testsuites>
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">code/</directory>
Expand Down
46 changes: 23 additions & 23 deletions tests/AuditHookMFATest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SilverStripe\Auditor\Tests;

use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use SilverStripe\Auditor\Tests\AuditHookTest\Logger;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
Expand Down Expand Up @@ -33,11 +33,11 @@ class AuditHookMFATest extends SapphireTest
protected $member;

/**
* @var MethodInterface|PHPUnit_Framework_MockObject_MockObject
* @var MethodInterface|MockObject
*/
protected $method;

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

Expand Down Expand Up @@ -65,19 +65,19 @@ public function testOnRegisterMethod()
$this->handler->extend('onRegisterMethod', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('registered MFA method', $message);
$this->assertContains('MethodInterface', $message, 'Method class name is in context');
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('registered MFA method', $message);
$this->assertStringContainsString('MethodInterface', $message, 'Method class name is in context');
}

public function testOnRegisterMethodFailure()
{
$this->handler->extend('onRegisterMethodFailure', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('failed registering new MFA method', $message);
$this->assertContains('MethodInterface', $message, 'Method class name is in context');
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('failed registering new MFA method', $message);
$this->assertStringContainsString('MethodInterface', $message, 'Method class name is in context');
}

public function testOnMethodVerificationFailure()
Expand All @@ -86,10 +86,10 @@ public function testOnMethodVerificationFailure()
$this->handler->extend('onMethodVerificationFailure', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('failed to verify using MFA method', $message);
$this->assertContains('MethodInterface', $message, 'Method class name is in context');
$this->assertNotContains('attempt_limit', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('failed to verify using MFA method', $message);
$this->assertStringContainsString('MethodInterface', $message, 'Method class name is in context');
$this->assertStringNotContainsString('attempt_limit', $message);
}

public function testOnMethodVerificationFailureWithLockoutConfiguration()
Expand All @@ -101,30 +101,30 @@ public function testOnMethodVerificationFailureWithLockoutConfiguration()
$this->handler->extend('onMethodVerificationFailure', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('failed to verify using MFA method', $message);
$this->assertContains('MethodInterface', $message, 'Method class name is in context');
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('failed to verify using MFA method', $message);
$this->assertStringContainsString('MethodInterface', $message, 'Method class name is in context');
// NB: json format is defined by AuditHookTest\Logger::log()
$this->assertContains('"attempts":3', $message);
$this->assertContains('"attempt_limit":5', $message);
$this->assertStringContainsString('"attempts":3', $message);
$this->assertStringContainsString('"attempt_limit":5', $message);
}

public function testOnSkipRegistration()
{
$this->handler->extend('onSkipRegistration', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('skipped MFA registration', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('skipped MFA registration', $message);
}

public function testOnMethodVerificationSuccess()
{
$this->handler->extend('onMethodVerificationSuccess', $this->member, $this->method);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('successfully verified using MFA method', $message);
$this->assertContains('MethodInterface', $message, 'Method class name is in context');
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('successfully verified using MFA method', $message);
$this->assertStringContainsString('MethodInterface', $message, 'Method class name is in context');
}
}
2 changes: 1 addition & 1 deletion tests/AuditHookSessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AuditHookSessionManagerTest extends SapphireTest
*/
protected $writer = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists(LoginSessionController::class)) {
Expand Down
88 changes: 44 additions & 44 deletions tests/AuditHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AuditHookTest extends FunctionalTest
*/
protected $writer = null;

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

Expand All @@ -36,8 +36,8 @@ public function testLoggingIn()
$this->logInWithPermission('ADMIN');

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('successfully logged in', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('successfully logged in', $message);
}

public function testAutoLoggingIn()
Expand All @@ -49,8 +49,8 @@ public function testAutoLoggingIn()
$member->extend('memberAutoLoggedIn');

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('successfully restored autologin', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('successfully restored autologin', $message);
}

public function testLoggingOut()
Expand All @@ -61,8 +61,8 @@ public function testLoggingOut()
$this->logOut();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('successfully logged out', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('successfully logged out', $message);
}

public function testLoggingWriteDoesNotOccurWhenNotLoggedIn()
Expand All @@ -84,9 +84,9 @@ public function testLoggingWriteWhenLoggedIn()
$group->write();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('modified', $message);
$this->assertContains(Group::class, $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('modified', $message);
$this->assertStringContainsString(Group::class, $message);
}

public function testAddMemberToGroupUsingGroupMembersRelation()
Expand All @@ -102,9 +102,9 @@ public function testAddMemberToGroupUsingGroupMembersRelation()
$group->Members()->add($member);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('added Member "joe1"', $message);
$this->assertContains('to Group "My group"', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('added Member "joe1"', $message);
$this->assertStringContainsString('to Group "My group"', $message);
}

public function testAddMemberToGroupUsingMemberGroupsRelation()
Expand All @@ -120,9 +120,9 @@ public function testAddMemberToGroupUsingMemberGroupsRelation()
$member->Groups()->add($group);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('added Member "joe2"', $message);
$this->assertContains('to Group "My group"', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('added Member "joe2"', $message);
$this->assertStringContainsString('to Group "My group"', $message);
}

public function testRemoveMemberFromGroupUsingGroupMembersRelation()
Expand All @@ -139,9 +139,9 @@ public function testRemoveMemberFromGroupUsingGroupMembersRelation()
$group->Members()->remove($member);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('removed Member "joe3"', $message);
$this->assertContains('from Group "My group"', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('removed Member "joe3"', $message);
$this->assertStringContainsString('from Group "My group"', $message);
}

public function testRemoveMemberFromGroupUsingMemberGroupsRelation()
Expand All @@ -158,9 +158,9 @@ public function testRemoveMemberFromGroupUsingMemberGroupsRelation()
$member->Groups()->remove($group);

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('removed Member "joe4"', $message);
$this->assertContains('from Group "My group"', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('removed Member "joe4"', $message);
$this->assertStringContainsString('from Group "My group"', $message);
}

public function testAddRoleCodeToRole()
Expand All @@ -175,8 +175,8 @@ public function testAddRoleCodeToRole()
$permissionRole->write();

$message = $this->writer->getLastMessage();
$this->assertContains('Effective code', $message);
$this->assertContains('grand_ruler', $message);
$this->assertStringContainsString('Effective code', $message);
$this->assertStringContainsString('grand_ruler', $message);
}

public function testAddViewerGroupToPage()
Expand All @@ -198,8 +198,8 @@ public function testAddViewerGroupToPage()
$page->publishSingle();

$message = $this->writer->getLastMessage();
$this->assertContains('Effective ViewerGroups', $message);
$this->assertContains('OnlyTheseUsers', $message);
$this->assertStringContainsString('Effective ViewerGroups', $message);
$this->assertStringContainsString('OnlyTheseUsers', $message);
}

public function testPublishPage()
Expand All @@ -217,9 +217,9 @@ public function testPublishPage()
$page->publishSingle();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('published Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('published Page', $message);
$this->assertStringContainsString('My page', $message);
}

public function testUnpublishPage()
Expand All @@ -238,9 +238,9 @@ public function testUnpublishPage()
$page->doUnpublish();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('unpublished Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('unpublished Page', $message);
$this->assertStringContainsString('My page', $message);
}

public function testDuplicatePage()
Expand All @@ -258,9 +258,9 @@ public function testDuplicatePage()
$page->duplicate();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('duplicated Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('duplicated Page', $message);
$this->assertStringContainsString('My page', $message);
}

public function testRevertToLive()
Expand All @@ -282,9 +282,9 @@ public function testRevertToLive()
$page->doRevertToLive();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('reverted Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('reverted Page', $message);
$this->assertStringContainsString('My page', $message);
}

public function testDelete()
Expand All @@ -304,9 +304,9 @@ public function testDelete()
$page->delete();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('deleted Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('deleted Page', $message);
$this->assertStringContainsString('My page', $message);
}

public function testRestoreToStage()
Expand All @@ -329,8 +329,8 @@ public function testRestoreToStage()
$page->delete();

$message = $this->writer->getLastMessage();
$this->assertContains('[email protected]', $message);
$this->assertContains('deleted Page', $message);
$this->assertContains('My page', $message);
$this->assertStringContainsString('[email protected]', $message);
$this->assertStringContainsString('deleted Page', $message);
$this->assertStringContainsString('My page', $message);
}
}