Skip to content

Commit

Permalink
API phpunit9 support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 1, 2021
1 parent 2da5f45 commit d8ecb77
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 40 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
],
"type": "silverstripe-vendormodule",
"require": {
"php": "^7.3 || ^8.0",
"silverstripe/cms": "^4.0",
"silverstripe/lumberjack": "^2.0",
"silverstripe/tagfield": "^2.0",
"silverstripe/assets": "^1.0",
"silverstripe/asset-admin": "^1.0"
},
"require-dev": {
"sminnee/phpunit": "^5.7",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.0"
},
"extra": {
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="blog">
<directory>tests/</directory>
</testsuite>

<testsuites>
<testsuite name="blog">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
Expand Down
7 changes: 2 additions & 5 deletions tests/BlogCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;

/**
* @mixin PHPUnit_Framework_TestCase
*/
class BlogCategoryTest extends FunctionalTest
{
/**
Expand All @@ -26,7 +23,7 @@ class BlogCategoryTest extends FunctionalTest
/**
* {@inheritdoc}
*/
public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -36,7 +33,7 @@ public function setUp()
/**
* {@inheritdoc}
*/
public function tearDown()
protected function tearDown(): void
{
DBDatetime::clear_mock_now();

Expand Down
6 changes: 3 additions & 3 deletions tests/BlogFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BlogFunctionalTest extends FunctionalTest

protected static $use_draft_site = true;

protected function setUp()
protected function setUp(): void
{
Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true);
i18n::set_locale('fa_IR');
Expand All @@ -33,14 +33,14 @@ public function testMemberProfileWithMultibyteUrlAndName()
$result = $this->get(rawurlencode('آبید') . '/profile/' . rawurlencode('عبّاس-آبان'));

$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody());
$this->assertStringContainsString('My Blog Post', $result->getBody());
}

public function testMemberProfileWithMultibyteUrlAndEnglishName()
{
$result = $this->get(rawurlencode('آبید') . '/profile/bob-jones');

$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('My Blog Post', $result->getBody());
$this->assertStringContainsString('My Blog Post', $result->getBody());
}
}
5 changes: 2 additions & 3 deletions tests/BlogPostFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Security\Security;

/**
* @mixin PHPUnit_Framework_TestCase
* @coversDefaultClass \SilverStripe\Blog\Model\BlogPostFilter
*/
class BlogPostFilterTest extends SapphireTest
Expand All @@ -18,14 +17,14 @@ class BlogPostFilterTest extends SapphireTest
*/
protected static $fixture_file = 'blog.yml';

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

DBDatetime::set_mock_now('2013-10-10 20:00:00');
}

public function tearDown()
protected function tearDown(): void
{
DBDatetime::clear_mock_now();

Expand Down
6 changes: 3 additions & 3 deletions tests/BlogPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BlogPostTest extends SapphireTest
{
protected static $fixture_file = 'blog.yml';

protected function tearDown()
protected function tearDown(): void
{
DBDatetime::clear_mock_now();
parent::tearDown();
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testGetMonthlyArchiveLink($type, $expected)
$blogPost = $this->objFromFixture(BlogPost::class, 'FirstBlogPost');

$archiveLink = $blogPost->getMonthlyArchiveLink($type);
$this->assertContains('archive/', $archiveLink);
$this->assertStringContainsString('archive/', $archiveLink);
$this->assertStringEndsWith($expected, $archiveLink);
}

Expand All @@ -181,7 +181,7 @@ public function testGetYearlyArchiveLink()
$blogPost = $this->objFromFixture(BlogPost::class, 'FirstBlogPost');

$archiveLink = $blogPost->getYearlyArchiveLink();
$this->assertContains('archive/', $archiveLink);
$this->assertStringContainsString('archive/', $archiveLink);
$this->assertStringEndsWith('/2013', $archiveLink);
}
}
8 changes: 2 additions & 6 deletions tests/BlogTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SilverStripe\Blog\Tests;

use PHPUnit_Framework_TestCase;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\BlogTag;
Expand All @@ -13,21 +12,18 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;

/**
* @mixin PHPUnit_Framework_TestCase
*/
class BlogTagTest extends FunctionalTest
{
protected static $fixture_file = 'blog.yml';

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

DBDatetime::set_mock_now('2013-10-10 20:00:00');
}

protected function tearDown()
protected function tearDown(): void
{
DBDatetime::clear_mock_now();

Expand Down
15 changes: 5 additions & 10 deletions tests/BlogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SilverStripe\Blog\Tests;

use PHPUnit_Framework_TestCase;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogController;
use SilverStripe\Blog\Model\BlogPost;
Expand All @@ -17,14 +17,11 @@
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;

/**
* @mixin PHPUnit_Framework_TestCase
*/
class BlogTest extends SapphireTest
{
protected static $fixture_file = 'blog.yml';

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

Expand All @@ -37,7 +34,7 @@ protected function setUp()
$blog->publishRecursive();
}

protected function tearDown()
protected function tearDown(): void
{
DBDatetime::clear_mock_now();

Expand Down Expand Up @@ -327,12 +324,10 @@ public function testFilteredCategoriesArchive()
);
}

/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 404
*/
public function testDisabledProfiles()
{
$this->expectException(HTTPResponse_Exception::class);
$this->expectExceptionCode(404);
Config::modify()->set(BlogController::class, 'disable_profiles', true);

$controller = BlogController::create();
Expand Down
6 changes: 3 additions & 3 deletions tests/Model/BlogControllerFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BlogControllerFunctionalTest extends FunctionalTest

protected static $use_draft_site = true;

protected function setUp()
protected function setUp(): void
{
Config::modify()->set(URLSegmentFilter::class, 'default_allow_multibyte', true);
i18n::set_locale('fa_IR');
Expand All @@ -26,14 +26,14 @@ public function testGetCategoriesWithMultibyteUrl()
$result = $this->get('my-blog/category/' . rawurlencode('آبید'));

$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('آبید', $result->getBody());
$this->assertStringContainsString('آبید', $result->getBody());
}

public function testGetTagsWithMultibyteUrl()
{
$result = $this->get('my-blog/tag/' . rawurlencode('برتراند'));

$this->assertEquals(200, $result->getStatusCode());
$this->assertContains('برتراند', $result->getBody());
$this->assertStringContainsString('برتراند', $result->getBody());
}
}
4 changes: 2 additions & 2 deletions tests/Widgets/BlogArchiveWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BlogArchiveWidgetTest extends SapphireTest
{
protected static $fixture_file = 'BlogArchiveWidgetTest.yml';

protected function setUp()
protected function setUp(): void
{
if (!class_exists(Widget::class)) {
self::$fixture_file = null;
Expand All @@ -28,7 +28,7 @@ protected function setUp()
parent::setUp();
}

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

Expand Down

0 comments on commit d8ecb77

Please sign in to comment.