Skip to content

Commit

Permalink
API phpunit 9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 27, 2021
1 parent 648f273 commit 1f42fb9
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
}
],
"require": {
"silverstripe/framework": "^4.5",
"silverstripe/framework": "^4.10",
"silverstripe/versioned": "^1@dev",
"silverstripe/vendor-plugin": "^1.0",
"php": "^7.1 || ^8"
"php": "^7.3 || ^8.0"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3",
"nikic/php-parser": "^3 || ^4",
"monolog/monolog": "~1.16"
Expand Down
8 changes: 5 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Standard module phpunit configuration.
Requires PHPUnit ^5.7
-->
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
<testsuites>
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 7 additions & 6 deletions tests/behat/src/AdminContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Admin\Tests\Behat\Context;

use Behat\Behat\Context\Context;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\MainContextAwareTrait;

class AdminContext implements Context
Expand All @@ -29,10 +30,10 @@ public function iShouldSeeAnInvalidTabIcon(string $not, string $tabLabel)
$element = $page->find('css', $selector);
$hiddenElement = $page->find('css', $hiddenSelector);
$message = "Tab validation icon for $id is visible when it should not be";
assertTrue(is_null($element) || $hiddenElement, $message);
Assert::assertTrue(is_null($element) || $hiddenElement, $message);
} else {
$element = $page->find('css', $selector);
assertNotNull($element, "Tab validation icon for $id was not found");
Assert::assertNotNull($element, "Tab validation icon for $id was not found");
}
}

Expand All @@ -48,15 +49,15 @@ public function iCanSeeTheFormValidationErrorMessage($not)
$element = $page->find('css', $selector);
if ($not) {
if (is_null($element)) {
assertTrue(true);
Assert::assertTrue(true);
} else {
$message = 'Form validation error message is present when it should not be';
assertFalse(strpos($element->getText(), $text), $message);
Assert::assertFalse(strpos($element->getText(), $text), $message);
}
} else {
$message = sprintf('Element %s not found', $selector);
assertNotNull($element, $message);
assertTrue(strpos($element->getText(), $text) !== false, $message);
Assert::assertNotNull($element, $message);
Assert::assertTrue(strpos($element->getText(), $text) !== false, $message);
}
}
}
2 changes: 1 addition & 1 deletion tests/php/CMSMenuItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public function testAttributes()
);

$menuItem->setAttributes(['<html>' => '<html>']);
$this->assertNotContains('<html>', $menuItem->getAttributesHTML(), 'Html is escaped for both name and value');
$this->assertStringNotContainsString('<html>', $menuItem->getAttributesHTML(), 'Html is escaped for both name and value');
}
}
4 changes: 2 additions & 2 deletions tests/php/CMSMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testBasicMenuHandling()
$menuItems = CMSMenu::get_menu_items();
$menuItem = $menuItems['SilverStripe-Admin-Tests-CMSMenuTest-LeftAndMainController'];
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'Controller menu item is of class CMSMenuItem');
$this->assertContains(
$this->assertStringContainsString(
$menuItem->url,
CMSMenuTest\LeftAndMainController::singleton()->Link(),
'Controller menu item has the correct link'
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testAdvancedMenuHandling()
CMSMenu::populate_menu();
$menuItem = CMSMenu::get_menu_item('SilverStripe-Admin-SecurityAdmin');
$this->assertInstanceOf(CMSMenuItem::class, $menuItem, 'SecurityAdmin menu item exists');
$this->assertContains($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link');
$this->assertStringContainsString($menuItem->url, SecurityAdmin::singleton()->Link(), 'Menu item has the correct link');
$this->assertEquals(
SecurityAdmin::class,
$menuItem->controller,
Expand Down
14 changes: 7 additions & 7 deletions tests/php/LeftAndMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LeftAndMainTest extends FunctionalTest

protected $backupCombined;

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

Expand Down Expand Up @@ -50,7 +50,7 @@ protected function resetMenu()
CMSMenu::populate_menu();
}

public function tearDown()
protected function tearDown(): void
{
parent::tearDown();
Requirements::set_combined_files_enabled($this->backupCombined);
Expand All @@ -62,12 +62,12 @@ public function testExtraCssAndJavascript()
$this->logInAs($admin);
$response = $this->get('admin/security');

$this->assertRegExp(
$this->assertMatchesRegularExpression(
'/tests\/php\/assets\/LeftAndMainTest.css/i',
$response->getBody(),
"body should contain custom css"
);
$this->assertRegExp(
$this->assertMatchesRegularExpression(
'/tests\/php\/assets\/LeftAndMainTest.js/i',
$response->getBody(),
"body should contain custom js"
Expand Down Expand Up @@ -95,9 +95,9 @@ public function testLeftAndMainSubclasses()
$this->assertInstanceOf(HTTPResponse::class, $response, "$link should return a response object");
$this->assertEquals(200, $response->getStatusCode(), "$link should return 200 status code");
// Check that a HTML page has been returned
$this->assertRegExp('/<html[^>]*>/i', $response->getBody(), "$link should contain <html> tag");
$this->assertRegExp('/<head[^>]*>/i', $response->getBody(), "$link should contain <head> tag");
$this->assertRegExp('/<body[^>]*>/i', $response->getBody(), "$link should contain <body> tag");
$this->assertMatchesRegularExpression('/<html[^>]*>/i', $response->getBody(), "$link should contain <html> tag");
$this->assertMatchesRegularExpression('/<head[^>]*>/i', $response->getBody(), "$link should contain <head> tag");
$this->assertMatchesRegularExpression('/<body[^>]*>/i', $response->getBody(), "$link should contain <body> tag");
}

public function testCanView()
Expand Down
4 changes: 2 additions & 2 deletions tests/php/ModelAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ public function testGetGridField()
$field = $form->Fields()->fieldByName('SilverStripe-Admin-Tests-ModelAdminTest-Player');
$this->assertNotNull($field, 'A GridField has been found on the form.');

$this->assertContains(
$this->assertStringContainsString(
'OverridenModelAdmin',
$field->extraClass(),
'OverridenModelAdmin has added an extra class to the grid field'
);
$this->assertContains(
$this->assertStringContainsString(
'called',
$field->getAttribute('ModelAdminExtension'),
'ModelAdminExtension has added an attribute to the GridField'
Expand Down
6 changes: 3 additions & 3 deletions tests/php/SecurityAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SecurityAdminTest extends FunctionalTest
// $lines = preg_split('/\n/', $this->content());

// $this->assertEquals(count($lines), 3, "Export with members has one content row");
// $this->assertRegExp('/"","","[email protected]"/', $lines[1], "Member values are correctly exported");
// $this->assertMatchesRegularExpression('/"","","[email protected]"/', $lines[1], "Member values are correctly exported");
// }

// TODO Fix export feature (moved from MemberTableField to GridFieldExportButton)
Expand Down Expand Up @@ -57,11 +57,11 @@ public function testPermissionFieldRespectsHiddenPermissions()
Config::modify()->merge(Permission::class, 'hidden_permissions', array('CMS_ACCESS_ReportAdmin'));
$response = $this->get(sprintf('admin/security/EditForm/field/Groups/item/%d/edit', $group->ID));

$this->assertContains(
$this->assertStringContainsString(
'CMS_ACCESS_SecurityAdmin',
$response->getBody()
);
$this->assertNotContains(
$this->assertStringNotContainsString(
'CMS_ACCESS_ReportAdmin',
$response->getBody()
);
Expand Down

0 comments on commit 1f42fb9

Please sign in to comment.