Skip to content

Commit

Permalink
API phpunit9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 19, 2021
1 parent 095e2c4 commit 8f35b71
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
],
"require": {
"silverstripe/admin": "^1.5",
"silverstripe/framework": "^4.5",
"silverstripe/framework": "^4.10",
"silverstripe/versioned": "^1.5",
"silverstripe/vendor-plugin": "^1.0"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3",
"silverstripe/asset-admin": "^1.5",
"silverstripe/cms": "^4.5"
Expand Down
13 changes: 5 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,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>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand Down
41 changes: 21 additions & 20 deletions tests/behat/src/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Element\NodeElement;
use PHPUnit\Framework\Assert;
use SilverStripe\BehatExtension\Context\FixtureContext as BaseFixtureContext;
use SilverStripe\BehatExtension\Utility\StepHelper;
use SilverStripe\MinkFacebookWebDriver\FacebookWebDriver;
Expand All @@ -24,7 +25,7 @@ public function iShouldSeeTheCampaign($name)
{
$item = $this->getCampaign($name);

assertNotNull($item, "Could not find campaign \"$name\" in the list");
Assert::assertNotNull($item, "Could not find campaign \"$name\" in the list");
}

/**
Expand All @@ -35,7 +36,7 @@ public function iShouldNotSeeTheCampaign($name)
{
$item = $this->getCampaign($name);

assertNull($item, "Found campaign \"$name\" in the list");
Assert::assertNull($item, "Found campaign \"$name\" in the list");
}

/**
Expand All @@ -47,11 +48,11 @@ public function iShouldNotSeeTheCampaign($name)
public function iShouldSeeInTheCampaignColumn($text, $column, $name)
{
$campaignRow = $this->getCampaign($name);
assertNotNull($campaignRow, sprintf('Could not find campaign "%s"', $name));
Assert::assertNotNull($campaignRow, sprintf('Could not find campaign "%s"', $name));

$cell = $campaignRow->find('xpath', "/td[{$column}][contains(text(), '{$text}')]");

assertNotNull($cell, sprintf('Could not find "%s" in column %d of "%s"', $text, $column, $name));
Assert::assertNotNull($cell, sprintf('Could not find "%s" in column %d of "%s"', $text, $column, $name));
}

/**
Expand All @@ -61,7 +62,7 @@ public function iShouldSeeInTheCampaignColumn($text, $column, $name)
public function iViewTheCampaign($name)
{
$item = $this->getCampaign($name);
assertNotNull($item, sprintf('Campaign %s not found', $name));
Assert::assertNotNull($item, sprintf('Campaign %s not found', $name));

$item->find('css', 'td')->click();
}
Expand All @@ -73,10 +74,10 @@ public function iViewTheCampaign($name)
public function iEditTheCampaign($name)
{
$item = $this->getCampaign($name);
assertNotNull($item, sprintf('Campaign %s not found', $name));
Assert::assertNotNull($item, sprintf('Campaign %s not found', $name));

$button = $item->find('css', '.font-icon-cog');
assertNotNull($button, sprintf('Campaign %s has no edit button', $name));
Assert::assertNotNull($button, sprintf('Campaign %s has no edit button', $name));
$button->click();
}

Expand All @@ -87,10 +88,10 @@ public function iEditTheCampaign($name)
public function iDeleteTheCampaign($name)
{
$item = $this->getCampaign($name);
assertNotNull($item, sprintf('Campaign %s not found', $name));
Assert::assertNotNull($item, sprintf('Campaign %s not found', $name));

$button = $item->find('css', '.font-icon-cancel');
assertNotNull($button, sprintf('Campaign %s has no delete button', $name));
Assert::assertNotNull($button, sprintf('Campaign %s has no delete button', $name));
$button->click();

/** @var FacebookWebDriver $driver */
Expand All @@ -108,8 +109,8 @@ public function iShouldSeeTheForm($id)
/** @var DocumentElement $page */
$page = $this->getMainContext()->getSession()->getPage();
$form = $page->find('css', "form#{$id}");
assertNotNull($form, "form with id $id could not be found");
assertTrue($form->isVisible(), "form with id $id is not visible");
Assert::assertNotNull($form, "form with id $id could not be found");
Assert::assertTrue($form->isVisible(), "form with id $id is not visible");
}

/**
Expand All @@ -135,8 +136,8 @@ public function iShouldSeeAModalTitled($title)
{
$page = $this->getMainContext()->getSession()->getPage();
$modalTitle = $page->find('css', '[role=dialog] .modal-header > .modal-title');
assertNotNull($modalTitle, 'No modal on the page');
assertTrue($modalTitle->getText() == $title);
Assert::assertNotNull($modalTitle, 'No modal on the page');
Assert::assertTrue($modalTitle->getText() == $title);
}

/**
Expand All @@ -147,7 +148,7 @@ public function iCloseTheModal()
/** @var DocumentElement $page */
$page = $this->getMainContext()->getSession()->getPage();
$button = $page->find('css', '.modal-header .close');
assertNotNull($button, 'Close button not found');
Assert::assertNotNull($button, 'Close button not found');

$button->click();
}
Expand All @@ -166,7 +167,7 @@ public function iClickTheGalleryItem($name)
"//div[contains(@class, 'gallery-item')]//div[contains(text(), '{$name}')]"
);

assertNotNull($cell, sprintf('Gallery item "%s" could not be found', $name));
Assert::assertNotNull($cell, sprintf('Gallery item "%s" could not be found', $name));

$cell->click();
}
Expand All @@ -182,12 +183,12 @@ public function iSeeTheCampaignItem($negate, $name)
$shouldSee = !trim($negate);

if ($shouldSee) {
assertNotNull($item, sprintf('Item "%s" could not be found', $name));
assertTrue($item->isVisible(), sprintf('Item "%s" is not visible', $name));
Assert::assertNotNull($item, sprintf('Item "%s" could not be found', $name));
Assert::assertTrue($item->isVisible(), sprintf('Item "%s" is not visible', $name));
} elseif ($item) {
assertFalse($item->isVisible(), sprintf('Item "%s" is visible', $name));
Assert::assertFalse($item->isVisible(), sprintf('Item "%s" is visible', $name));
} else {
assertNull($item, sprintf('Item "%s" exists', $name));
Assert::assertNull($item, sprintf('Item "%s" exists', $name));
}
}

Expand All @@ -198,7 +199,7 @@ public function iSeeTheCampaignItem($negate, $name)
public function iSelectTheCampaignItem($name)
{
$item = $this->getCampaignItem($name);
assertNotNull($item, sprintf('Item "%s" could not be found', $name));
Assert::assertNotNull($item, sprintf('Item "%s" could not be found', $name));
$item->click();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/php/AddToCampaignValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AddToCampaignValidatorTest extends SapphireTest
*/
protected $validator = null;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->logInWithPermission('ADMIN');
Expand Down
2 changes: 1 addition & 1 deletion tests/php/CampaignAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CampaignAdminTest extends SapphireTest

protected static $fixture_file = 'CampaignAdminTest.yml';

protected function setUp()
protected function setUp(): void
{
parent::setUp();
DBDatetime::set_mock_now('2011-09-24 11:11:00');
Expand Down

0 comments on commit 8f35b71

Please sign in to comment.