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 Nov 1, 2021
1 parent de38165 commit 9e49b0b
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 83 deletions.
5 changes: 3 additions & 2 deletions composer.json
Expand Up @@ -16,7 +16,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.1 || ^8.0",
"php": "^7.3 || ^8.0",
"silverstripe/framework": "^4.10@dev",
"silverstripe/cms": "^4.7@dev",
"silverstripe/admin": "^1.7@dev",
"silverstripe/versioned": "^1.7@dev",
Expand All @@ -26,7 +27,7 @@
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"silverstripe/recipe-testing": "1.x-dev"
"silverstripe/recipe-testing": "^2"
},
"suggest": {
"silverstripe/elemental-blocks": "Adds a set of common SilverStripe content block types",
Expand Down
2 changes: 1 addition & 1 deletion docs/en/advanced_setup.md
Expand Up @@ -300,7 +300,7 @@ TractorCow\Fluent\Model\Locale:
In the case your fixture needs to contain data for only a single locale you can specify your desired locale in your unit test like this:

```php
protected function setUp()
protected function setUp(): void
{
// Set locale for fixture creation
FluentState::singleton()->withState(function (FluentState $state) {
Expand Down
9 changes: 5 additions & 4 deletions phpunit.xml.dist
@@ -1,8 +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">src/</directory>
Expand Down
8 changes: 4 additions & 4 deletions tests/BaseElementTest.php
Expand Up @@ -107,7 +107,7 @@ public function testLink()
{
$element = $this->objFromFixture(ElementContent::class, 'content1');

$this->assertContains($element->getPage()->Link(), $element->Link());
$this->assertStringContainsString($element->getPage()->Link(), $element->Link());
}

public function testGetEditLink()
Expand All @@ -118,14 +118,14 @@ public function testGetEditLink()
$element = $this->objFromFixture(ElementContent::class, 'content1');
$editLink = $element->getEditLink();

$this->assertContains('http://example.com', $editLink, 'Link should be absolute');
$this->assertContains('pages/edit', $editLink, 'Link should contain reference to the page');
$this->assertStringContainsString('http://example.com', $editLink, 'Link should be absolute');
$this->assertStringContainsString('pages/edit', $editLink, 'Link should contain reference to the page');
}

public function testGetIcon()
{
$element = new ElementContent();
$this->assertContains('class="font-icon-block-content"', $element->getIcon());
$this->assertStringContainsString('class="font-icon-block-content"', $element->getIcon());

Config::modify()->set(ElementContent::class, 'icon', '');
$this->assertEmpty($element->getIcon());
Expand Down
57 changes: 29 additions & 28 deletions tests/Behat/Context/FeatureContext.php
Expand Up @@ -3,6 +3,7 @@

use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Mink\Element\NodeElement;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\BasicContext;
use SilverStripe\BehatExtension\Context\SilverStripeContext;
use SilverStripe\Framework\Tests\Behaviour\CmsFormsContext;
Expand Down Expand Up @@ -43,10 +44,10 @@ public function iShouldSeeTheEditFormForBlock($negative, $position)
$form = $block->find('css', '.element-editor-editform');

if ($iShouldNotSee) {
assertTrue(!$form || !$form->isVisible(), 'I see the form! Try again later.');
Assert::assertTrue(!$form || !$form->isVisible(), 'I see the form! Try again later.');
} else {
assertNotNull($form, 'Edit form not found');
assertTrue($form->isVisible());
Assert::assertNotNull($form, 'Edit form not found');
Assert::assertTrue($form->isVisible());
}
}

Expand All @@ -55,23 +56,23 @@ public function iShouldSeeTheEditFormForBlock($negative, $position)
*/
public function iShouldSeeAListOfBlocks()
{
assertNotEmpty($this->getBlocks());
Assert::assertNotEmpty($this->getBlocks());
}

/**
* @Then /^I (?:should\s)?see an empty list of blocks$/i
*/
public function iShouldSeeAnEmptyListOfBlocks()
{
assertEmpty($this->getBlocks());
Assert::assertEmpty($this->getBlocks());
}

/**
* @Then I should see block :position
*/
public function iShouldSeeBlock($position)
{
assertNotNull($this->getSpecificBlock($position));
Assert::assertNotNull($this->getSpecificBlock($position));
}

/**
Expand All @@ -80,7 +81,7 @@ public function iShouldSeeBlock($position)
public function iClickOnBlock($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
$block->click();
}

Expand All @@ -91,7 +92,7 @@ public function iClickOnTheCaretButtonForBlock($position)
{
$block = $this->getSpecificBlock($position);
$button = $this->getCaretButton($block);
assertNotNull($button, 'Caret button for block ' . $position . ' was not found in the page.');
Assert::assertNotNull($button, 'Caret button for block ' . $position . ' was not found in the page.');
$button->click();
}

Expand All @@ -102,7 +103,7 @@ public function iShouldSeeAsTheTitleForBlock($text, $position)
{
$block = $this->getSpecificBlock($position);
$title = $block->find('css', '.element-editor-header__title');
assertEquals($title->getText(), $text);
Assert::assertEquals($title->getText(), $text);
}

/**
Expand All @@ -112,7 +113,7 @@ public function iShouldSeeAsTheSummaryForBlock($text, $position)
{
$block = $this->getSpecificBlock($position);
$summary = $block->find('css', '.element-editor-summary__content');
assertEquals($summary->getText(), $text);
Assert::assertEquals($summary->getText(), $text);
}

/**
Expand All @@ -139,9 +140,9 @@ public function iShouldSeeThePublishButtonForBlock($negative, $position)
$publishButton = $this->findPublishButton($position);

if ($iShouldNotSee) {
assertNull($publishButton, 'Publish button displayed (but shouldn\'t)');
Assert::assertNull($publishButton, 'Publish button displayed (but shouldn\'t)');
} else {
assertNotNull($publishButton, 'Publish button not displayed (but should be)');
Assert::assertNotNull($publishButton, 'Publish button not displayed (but should be)');
}
}

Expand All @@ -158,9 +159,9 @@ public function iShouldSeeTheUnpublishButtonForBlock($negative, $position)
$unpublishButton = $this->findUnpublishButton($position);

if ($iShouldNotSee) {
assertNull($unpublishButton, 'Unpublish button displayed (but shouldn\'t)');
Assert::assertNull($unpublishButton, 'Unpublish button displayed (but shouldn\'t)');
} else {
assertNotNull($unpublishButton, 'Unpublish button not displayed (but should be)');
Assert::assertNotNull($unpublishButton, 'Unpublish button not displayed (but should be)');
}
}

Expand All @@ -172,7 +173,7 @@ public function iShouldSeeTheUnpublishButtonForBlock($negative, $position)
public function iHoverOverBlock($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
$block->mouseOver();
}

Expand All @@ -184,7 +185,7 @@ public function iHoverOverBlock($position)
public function iHoverOverTheIconOfBlock($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
$icon = $block->find(
'css',
'.element-editor-header .element-editor-header__info .element-editor-header__icon-container'
Expand All @@ -204,7 +205,7 @@ public function stepIPressTheButtonInTheAddBlockPopover($text)

// Selector preferable not font-icon, but other class shared among all buttons
$button = $popover->find('css', '.font-icon-block-'. $blockType);
assertNotNull($button, "{$text} button not found in Add Block popover");
Assert::assertNotNull($button, "{$text} button not found in Add Block popover");
$button->click();
}

Expand All @@ -223,7 +224,7 @@ public function stepIPressTheButtonInTheActionMenuForBlock($buttonName, $blockNu

$button = $popover->find('xpath', sprintf('/button[contains(text(), \'%s\')]', $buttonName));

assertNotNull($button, sprintf('Could not find button labelled "%s"', $buttonName));
Assert::assertNotNull($button, sprintf('Could not find button labelled "%s"', $buttonName));

$button->click();
}
Expand Down Expand Up @@ -274,10 +275,10 @@ public function theFieldForBlockShouldContain($field, $blockNumber, $negate, $co
public function iClickOnTheReport($reportName)
{
$reportsTable = $this->getSession()->getPage()->find('css', '.all-reports-gridfield .grid-field__table');
assertNotNull($reportsTable, 'Report table could not be found');
Assert::assertNotNull($reportsTable, 'Report table could not be found');

$report = $reportsTable->find('xpath', sprintf('//a[contains(text(), \'%s\')]', $reportName));
assertNotNull($report, 'Specified report "' . $reportName . '" could not be found.');
Assert::assertNotNull($report, 'Specified report "' . $reportName . '" could not be found.');

$report->click();

Expand Down Expand Up @@ -327,10 +328,10 @@ protected function getSpecificBlock($position)
protected function getArchiveButton($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');

$button = $block->find('css', '.element-editor__actions-archive');
assertNotNull($button, 'Archive button not found');
Assert::assertNotNull($button, 'Archive button not found');

return $button;
}
Expand All @@ -344,7 +345,7 @@ protected function getArchiveButton($position)
protected function findPublishButton($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');

$button = $block->find('css', '.element-editor__actions-publish');

Expand All @@ -360,7 +361,7 @@ protected function findPublishButton($position)
protected function findUnpublishButton($position)
{
$block = $this->getSpecificBlock($position);
assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
Assert::assertNotNull($block, 'Block ' . $position . ' was not found in the page.');

$button = $block->find('css', '.element-editor__actions-unpublish');

Expand All @@ -376,7 +377,7 @@ protected function findUnpublishButton($position)
protected function getCaretButton($block)
{
$button = $block->find('css', '.element-editor-header__expand');
assertNotNull($button, 'Caret button not found');
Assert::assertNotNull($button, 'Caret button not found');

return $button;
}
Expand All @@ -390,8 +391,8 @@ protected function findFieldInBlock($block, $name)
{
$label = $block->findAll('xpath', sprintf('//label[contains(text(), \'%s\')]', $name));

assertNotCount(0, $label, sprintf('Could not find a label for a field with the content "%s"', $name));
assertCount(
Assert::assertNotCount(0, $label, sprintf('Could not find a label for a field with the content "%s"', $name));
Assert::assertCount(
1,
$label,
sprintf(
Expand All @@ -405,7 +406,7 @@ protected function findFieldInBlock($block, $name)
$fieldId = $label->getAttribute('for');
$field = $block->find('css', '#' . $fieldId);

assertNotNull($field, sprintf(
Assert::assertNotNull($field, sprintf(
'Label found matching "%s" but there was no field that has the ID matching the "for" attribute ("#%s")',
$name,
$fieldId
Expand Down
4 changes: 2 additions & 2 deletions tests/ElementControllerTest.php
Expand Up @@ -26,7 +26,7 @@ class ElementControllerTest extends FunctionalTest
TestElement::class
];

protected function setUp()
protected function setUp(): void
{
Versioned::set_stage(Versioned::DRAFT);

Expand All @@ -40,6 +40,6 @@ public function testForTemplate()
$this->logInWithPermission('ADMIN');
$controller = new TestElementController($element);

$this->assertContains('Hello Test', $controller->forTemplate());
$this->assertStringContainsString('Hello Test', $controller->forTemplate());
}
}
4 changes: 2 additions & 2 deletions tests/ElementalAreaTest.php
Expand Up @@ -85,8 +85,8 @@ public function testForTemplate()
{
$area = $this->objFromFixture(ElementalArea::class, 'area1');

$this->assertContains('Hello Test', $area->forTemplate());
$this->assertContains('Hello Test 2', $area->forTemplate());
$this->assertStringContainsString('Hello Test', $area->forTemplate());
$this->assertStringContainsString('Hello Test 2', $area->forTemplate());
}

public function testCanBePublished()
Expand Down
2 changes: 1 addition & 1 deletion tests/ElementalPageExtensionTest.php
Expand Up @@ -26,7 +26,7 @@ class ElementalPageExtensionTest extends FunctionalTest
TestPage::class,
];

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Extensions/ElementalAreasExtensionTest.php
Expand Up @@ -25,7 +25,7 @@ class ElementalAreasExtensionTest extends SapphireTest
TestUnusedElement::class,
];

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/ElementalAreaFieldTest.php
Expand Up @@ -23,7 +23,7 @@ class ElementalAreaFieldTest extends SapphireTest
*/
protected $field;

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Forms/TextCheckboxGroupFieldTest.php
Expand Up @@ -15,7 +15,7 @@ class TextCheckboxGroupFieldTest extends SapphireTest
*/
protected $field;

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

Expand Down
10 changes: 3 additions & 7 deletions tests/GraphQL/AddElementToAreaMutationTest.php
Expand Up @@ -18,7 +18,7 @@ class AddElementToAreaMutationTest extends SapphireTest
TestElement::class,
];

protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists(Schema::class)) {
Expand Down Expand Up @@ -50,20 +50,16 @@ public function testAddingBlocksInOrder()
$this->assertIdsInOrder([$five, $one, $three, $two, $four], 'The fifth element is added first, after ID 0');
}

/**
* @expectedException InvalidArgumentException
*/
public function testBadElementalArea()
{
$this->expectException(InvalidArgumentException::class);
$areaID = $this->objFromFixture(ElementalArea::class, 'one')->ID;
$this->runMutation(TestElement::class, $areaID + 1);
}

/**
* @expectedException InvalidArgumentException
*/
public function testOrderingByWrongElementalArea()
{
$this->expectException(InvalidArgumentException::class);
$firstArea = ElementalArea::get()->first();
$elementInFirstArea = TestElement::create();
$firstArea->Elements()->add($elementInFirstArea);
Expand Down
2 changes: 1 addition & 1 deletion tests/GraphQL/DuplicateElementMutationTest.php
Expand Up @@ -12,7 +12,7 @@

class DuplicateElementMutationTest extends SapphireTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();
if (!class_exists(Schema::class)) {
Expand Down

0 comments on commit 9e49b0b

Please sign in to comment.