Merge pull request #156 from creative-commoners/pulls/4/sapphire-test-nine

API phpunit 9 support
This commit is contained in:
Maxime Rainville 2021-11-01 17:55:12 +13:00 committed by GitHub
commit b544032a22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 41 deletions

View File

@ -20,18 +20,16 @@
} }
], ],
"require": { "require": {
"php": "^7.3 || ^8.0",
"silverstripe/vendor-plugin": "^1", "silverstripe/vendor-plugin": "^1",
"silverstripe/framework": "^4.2", "silverstripe/framework": "^4.10",
"silverstripe/cms": "^4.2", "silverstripe/cms": "^4.2",
"silverstripe/reports": "^4.2", "silverstripe/reports": "^4.2",
"silverstripe/siteconfig": "^4.2" "silverstripe/siteconfig": "^4.2"
}, },
"require-dev": { "require-dev": {
"sminnee/phpunit": "^5.7", "silverstripe/recipe-testing": "^2",
"squizlabs/php_codesniffer": "^3", "squizlabs/php_codesniffer": "^3"
"silverstripe/behat-extension": "^3",
"silverstripe/serve": "^2",
"se/selenium-server-standalone": "2.41.0"
}, },
"suggest": { "suggest": {
"symbiote/silverstripe-queuedjobs": "Automatically schedules content review emails to be sent, only requiring one crontask to be created" "symbiote/silverstripe-queuedjobs": "Automatically schedules content review emails to be sent, only requiring one crontask to be created"

View File

@ -1,7 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true"> <phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="Default"> <testsuite name="Default">
<directory>tests/php/</directory> <directory>tests/php/</directory>
</testsuite> </testsuite>
</testsuites>
<filter> <filter>
<whitelist addUncoveredFilesFromWhitelist="true"> <whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory> <directory suffix=".php">src/</directory>

View File

@ -80,7 +80,7 @@ class ContentReviewNotificationJob extends AbstractQueuedJob implements QueuedJo
return QueuedJob::QUEUED; return QueuedJob::QUEUED;
} }
public function setup() public function setUp()
{ {
parent::setup(); parent::setup();

View File

@ -18,7 +18,7 @@ abstract class ContentReviewBaseTest extends FunctionalTest
*/ */
protected $translatableEnabledBefore; protected $translatableEnabledBefore;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -39,7 +39,7 @@ abstract class ContentReviewBaseTest extends FunctionalTest
} }
} }
protected function tearDown() protected function tearDown(): void
{ {
if (class_exists(Translatable::class)) { if (class_exists(Translatable::class)) {
if ($this->translatableEnabledBefore) { if ($this->translatableEnabledBefore) {

View File

@ -17,9 +17,6 @@ use SilverStripe\Security\Group;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
/**
* @mixin PHPUnit_Framework_TestCase
*/
class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
{ {
/** /**

View File

@ -18,9 +18,6 @@ use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\ContentReview\Models\ContentReviewLog; use SilverStripe\ContentReview\Models\ContentReviewLog;
/**
* @mixin PHPUnit_Framework_TestCase
*/
class ContentReviewNotificationTest extends SapphireTest class ContentReviewNotificationTest extends SapphireTest
{ {
/** /**
@ -28,7 +25,7 @@ class ContentReviewNotificationTest extends SapphireTest
*/ */
protected static $fixture_file = 'ContentReviewTest.yml'; protected static $fixture_file = 'ContentReviewTest.yml';
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
@ -70,15 +67,15 @@ class ContentReviewNotificationTest extends SapphireTest
$email = $this->findEmail($ToEmail, null, $Subject); $email = $this->findEmail($ToEmail, null, $Subject);
$this->assertNotNull($email, "Email haven't been sent."); $this->assertNotNull($email, "Email haven't been sent.");
$this->assertContains( $this->assertStringContainsString(
"<h1>$Subject</h1>". "<h1>$Subject</h1>".
"<p>There are $PagesCount pages that are due for review today by you, $ToFirstName.</p>". "<p>There are $PagesCount pages that are due for review today by you, $ToFirstName.</p>".
"<p>This email was sent to $ToEmail</p>", "<p>This email was sent to $ToEmail</p>",
$email['HtmlContent'] $email['HtmlContent']
); );
$this->assertContains('Staff', $email['HtmlContent']); $this->assertStringContainsString('Staff', $email['HtmlContent']);
$this->assertContains('Contact Us', $email['HtmlContent']); $this->assertStringContainsString('Contact Us', $email['HtmlContent']);
$this->assertContains('Contact Us Child', $email['HtmlContent']); $this->assertStringContainsString('Contact Us Child', $email['HtmlContent']);
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();
} }

View File

@ -4,7 +4,6 @@ namespace SilverStripe\ContentReview\Tests;
use function date; use function date;
use Page; use Page;
use PHPUnit_Framework_TestCase;
use SilverStripe\CMS\Controllers\CMSPageEditController; use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension; use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
@ -22,8 +21,6 @@ use SilverStripe\SiteConfig\SiteConfig;
/** /**
* This class tests that settings are inherited correctly based on the inherited, * This class tests that settings are inherited correctly based on the inherited,
* custom or disabled settings. * custom or disabled settings.
*
* @mixin PHPUnit_Framework_TestCase
*/ */
class ContentReviewSettingsTest extends SapphireTest class ContentReviewSettingsTest extends SapphireTest
{ {

View File

@ -5,6 +5,7 @@ namespace SilverStripe\ContentReview\Tests\Extensions;
use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension; use SilverStripe\ContentReview\Extensions\ContentReviewCMSExtension;
use SilverStripe\ContentReview\Forms\ReviewContentHandler; use SilverStripe\ContentReview\Forms\ReviewContentHandler;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
@ -29,21 +30,17 @@ class ContentReviewCMSExtensionTest extends SapphireTest
$this->assertTrue($result); $this->assertTrue($result);
} }
/**
* @expectedException SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionMessage Bad record ID #1234
*/
public function testGetReviewContentFormThrowsExceptionWhenPageNotFound() public function testGetReviewContentFormThrowsExceptionWhenPageNotFound()
{ {
$this->expectException(HTTPResponse_Exception::class);
$this->expectExceptionMessage('Bad record ID #1234');
(new ContentReviewCMSExtension)->getReviewContentForm(1234); (new ContentReviewCMSExtension)->getReviewContentForm(1234);
} }
/**
* @expectedException SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionMessage It seems you don't have the necessary permissions to review this content
*/
public function testGetReviewContentFormThrowsExceptionWhenObjectCannotBeReviewed() public function testGetReviewContentFormThrowsExceptionWhenObjectCannotBeReviewed()
{ {
$this->expectException(HTTPResponse_Exception::class);
$this->expectExceptionMessage('It seems you don\'t have the necessary permissions to review this content');
$this->logOut(); $this->logOut();
$mock = $this->getMockBuilder(ContentReviewCMSExtension::class) $mock = $this->getMockBuilder(ContentReviewCMSExtension::class)

View File

@ -14,6 +14,7 @@ use SilverStripe\Forms\Form;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\TextareaField; use SilverStripe\Forms\TextareaField;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\ORM\ValidationException;
class ReviewContentHandlerTest extends SapphireTest class ReviewContentHandlerTest extends SapphireTest
{ {
@ -37,12 +38,10 @@ class ReviewContentHandlerTest extends SapphireTest
$this->assertTrue($saveAction->hasClass('review-content__action')); $this->assertTrue($saveAction->hasClass('review-content__action'));
} }
/**
* @expectedException SilverStripe\ORM\ValidationException
* @expectedExceptionMessage It seems you don't have the necessary permissions to submit a content review
*/
public function testExceptionThrownWhenSubmittingReviewForInvalidObject() public function testExceptionThrownWhenSubmittingReviewForInvalidObject()
{ {
$this->expectException(ValidationException::class);
$this->expectExceptionMessage('It seems you don\'t have the necessary permissions to submit a content review');
ReviewContentHandler::create()->submitReview(new Member, ['foo' => 'bar']); ReviewContentHandler::create()->submitReview(new Member, ['foo' => 'bar']);
} }

View File

@ -17,9 +17,6 @@ use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
/**
* @mixin PHPUnit_Framework_TestCase
*/
class SiteTreeContentReviewTest extends ContentReviewBaseTest class SiteTreeContentReviewTest extends ContentReviewBaseTest
{ {
protected $usesTransactions = false; protected $usesTransactions = false;