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 #221

Merged
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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"silverstripe/admin": "^1.6",
"silverstripe/framework": "^4.6",
"silverstripe/framework": "^4.10",
"silverstripe/versioned": "^1.6",
"silverstripe/graphql": "^3.5 || ^4",
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"sminnee/phpunit": "^5",
"sminnee/phpunit-mock-objects": "^3.4.5",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3",
"silverstripe/cms": "^4.6"
},
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<phpunit bootstrap="vendor/silverstripe/cms/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">src/</directory>
Expand Down
2 changes: 1 addition & 1 deletion tests/ArchiveAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ArchiveAdminTest extends SapphireTest
ViewProviderVersionedObject::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
}
Expand Down
19 changes: 10 additions & 9 deletions tests/Behat/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\VersionedAdmin\Tests\Behat\Context;

use Behat\Mink\Element\NodeElement;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\SilverStripeContext;

if (!class_exists(SilverStripeContext::class)) {
Expand All @@ -25,7 +26,7 @@ public function iShouldSeeAListOfVersions()
public function iShouldSeeAListOfVersionsInDescendingOrder()
{
$versions = $this->getVersions();
assertNotEmpty($versions, 'I see a list of versions');
Assert::assertNotEmpty($versions, 'I see a list of versions');

$previous = null;

Expand All @@ -43,7 +44,7 @@ public function iShouldSeeAListOfVersionsInDescendingOrder()
*/
public function iClickOnTheFirstVersion()
{
assertNotNull($this->getLatestVersion(), 'I should see a list of versions');
Assert::assertNotNull($this->getLatestVersion(), 'I should see a list of versions');
$this->getLatestVersion()->click();
}

Expand All @@ -61,7 +62,7 @@ public function iClickOnVersion($versionNo)
break;
}
}
assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.');
Assert::assertNotNull($desiredVersion, 'Desired version ' . $versionNo . ' was not found in the page.');
$this->clickVersion($desiredVersion);
}

Expand All @@ -71,7 +72,7 @@ public function iClickOnVersion($versionNo)
public function iOpenTheHistoryViewerActionsMenu()
{
$button = $this->getSession()->getPage()->find('css', '.history-viewer__heading .history-viewer__actions .btn');
assertNotNull($button, 'History viewer actions menu not found in the page.');
Assert::assertNotNull($button, 'History viewer actions menu not found in the page.');

$button->click();
}
Expand All @@ -85,7 +86,7 @@ public function theTextShouldBeDeleted($text)
'xpath',
sprintf('//del[contains(normalize-space(string(.)), \'%s\')]', $text)
);
assertNotNull($result, $text . ' was not shown as deleted');
Assert::assertNotNull($result, $text . ' was not shown as deleted');
}

/**
Expand All @@ -97,7 +98,7 @@ public function theTextShouldBeAdded($text)
'xpath',
sprintf('//ins[contains(normalize-space(string(.)), \'%s\')]', $text)
);
assertNotNull($result, $text . ' was not shown as added');
Assert::assertNotNull($result, $text . ' was not shown as added');
}

/**
Expand Down Expand Up @@ -158,7 +159,7 @@ public function iShouldSeeInTheAuthorColumn($text, $versionNumber)
$authorColumn = $version->find('css', '.history-viewer__author');

$exists = strpos($authorColumn->getText(), $text) !== false;
assertTrue($exists, 'Author column contains ' . $text);
Assert::assertTrue($exists, 'Author column contains ' . $text);
}

/**
Expand All @@ -172,7 +173,7 @@ public function iShouldSeeInTheRecordColumn($text, $versionNumber)
$recordColumn = $version->find('css', '.history-viewer__version-state');

$exists = strpos($recordColumn->getText(), $text) !== false;
assertTrue($exists, 'Record column contains ' . $text);
Assert::assertTrue($exists, 'Record column contains ' . $text);
}

/**
Expand All @@ -184,7 +185,7 @@ public function iShouldSeeInTheVersionColumn($text, $versionNumber)
$versionColumn = $version->find('css', '.history-viewer__version-no');

$exists = strpos($versionColumn->getText(), $text) !== false;
assertTrue($exists, 'Version column contains ' . $text);
Assert::assertTrue($exists, 'Version column contains ' . $text);
}

/**
Expand Down
44 changes: 15 additions & 29 deletions tests/Controllers/HistoryViewerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,18 @@ public function testSchema()
$this->assertSame('application/json', $result->getHeader('Content-Type'));
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessageRegExp /Missing required field/
*/
public function testGetVersionFormThrowsExceptionWhenArgsAreMissing()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/Missing required field/');
$controller = new HistoryViewerController();
$controller->getVersionForm([]);
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessageRegExp /Missing required field/
*/
public function testGetVersionFormThrowsExceptionWhenArgsAreFalsy()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/Missing required field/');
$controller = new HistoryViewerController();
$controller->getVersionForm([
'RecordClass' => 'Page',
Expand All @@ -109,12 +105,10 @@ public function testGetVersionFormThrowsExceptionWhenArgsAreFalsy()
]);
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 404
*/
public function testGetVersionFormThrowsExceptionWhenRecordVersionDoesntExist()
{
$this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class);
$this->expectExceptionCode(404);
$controller = new HistoryViewerController();
$controller->getVersionForm([
'RecordClass' => UnviewableVersionedObject::class,
Expand All @@ -123,13 +117,11 @@ public function testGetVersionFormThrowsExceptionWhenRecordVersionDoesntExist()
]);
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 403
* @expectedExceptionMessage You don't have the necessary permissions to view Unviewable Versioned Object
*/
public function testGetVersionFormThrowsExceptionWhenCanViewIsFalse()
{
$this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class);
$this->expectExceptionCode(403);
$this->expectExceptionMessage("You don't have the necessary permissions to view Unviewable Versioned Object");
$controller = new HistoryViewerController();
$controller->getVersionForm([
'RecordClass' => UnviewableVersionedObject::class,
Expand All @@ -151,32 +143,26 @@ public function testGetVersionFormReturnsForm()
$this->assertInstanceOf(LeftAndMainFormRequestHandler::class, $result->getRequestHandler());
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 400
*/
public function testVersionFormThrowsExceptionWithoutRequest()
{
$this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class);
$this->expectExceptionCode(400);
$controller = new HistoryViewerController();
$controller->versionForm(null);
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 400
*/
public function testCompareFormThrowsExceptionWithoutRequest()
{
$this->expectException(\SilverStripe\Control\HTTPResponse_Exception::class);
$this->expectExceptionMessage(400);
$controller = new HistoryViewerController();
$controller->compareForm(null);
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessageRegExp /Missing required field/
*/
public function testVersionFormThrowsExceptionWhenArgsAreFalsy()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/Missing required field/');
$controller = new HistoryViewerController();
$controller->getVersionForm([
'RecordClass' => 'Page',
Expand Down
8 changes: 3 additions & 5 deletions tests/Forms/DataObjectVersionFormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DataObjectVersionFormFactoryTest extends SapphireTest
*/
protected $controller;

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

Expand All @@ -56,12 +56,10 @@ public function testIsReadonlyFormType()
);
}

/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Missing required context Record
*/
public function testGetFormThrowsExceptionOnMissingRequiredContext()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Missing required context Record');
$this->factory->getForm();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/DiffFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testScalarValuesAreDiffed()
$diffField->setComparisonField($newField);
$diffField->setValue('old');

$this->assertRegExp('/^<ins>new<\/ins> *<del>old<\/del>$/', $diffField->Value());
$this->assertMatchesRegularExpression('/^<ins>new<\/ins> *<del>old<\/del>$/', $diffField->Value());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Forms/DiffTransformationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DiffTransformationTest extends SapphireTest
*/
private $testForm;

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

Expand Down Expand Up @@ -62,8 +62,8 @@ public function testTransform()
$form->loadDataFrom($oldData);

foreach ($form->Fields() as $index => $field) {
$this->assertContains($expected[$index]['before'], $field->Value(), 'Value before is shown');
$this->assertContains($expected[$index]['after'], $field->Value(), 'Value after is shown');
$this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown');
$this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown');
}
}

Expand All @@ -87,8 +87,8 @@ public function testTransformWithCompositeFields()
$form->loadDataFrom($oldData);

foreach (array_values($form->Fields()->dataFields()) as $index => $field) {
$this->assertContains($expected[$index]['before'], $field->Value(), 'Value before is shown');
$this->assertContains($expected[$index]['after'], $field->Value(), 'Value after is shown');
$this->assertStringContainsString($expected[$index]['before'], $field->Value(), 'Value before is shown');
$this->assertStringContainsString($expected[$index]['after'], $field->Value(), 'Value after is shown');
}
}

Expand Down