Skip to content

Commit 363a115

Browse files
author
Maxime Rainville
authored
Merge pull request #661 from creative-commoners/pulls/3/sapphire-test-nine
API phpunit9 support
2 parents 2da5f45 + d8ecb77 commit 363a115

10 files changed

+29
-40
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
],
99
"type": "silverstripe-vendormodule",
1010
"require": {
11+
"php": "^7.3 || ^8.0",
1112
"silverstripe/cms": "^4.0",
1213
"silverstripe/lumberjack": "^2.0",
1314
"silverstripe/tagfield": "^2.0",
1415
"silverstripe/assets": "^1.0",
1516
"silverstripe/asset-admin": "^1.0"
1617
},
1718
"require-dev": {
18-
"sminnee/phpunit": "^5.7",
19+
"phpunit/phpunit": "^9.5",
1920
"squizlabs/php_codesniffer": "^3.0"
2021
},
2122
"extra": {

phpunit.xml.dist

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
2-
<testsuite name="blog">
3-
<directory>tests/</directory>
4-
</testsuite>
5-
2+
<testsuites>
3+
<testsuite name="blog">
4+
<directory>tests/</directory>
5+
</testsuite>
6+
</testsuites>
67
<filter>
78
<whitelist addUncoveredFilesFromWhitelist="true">
89
<directory suffix=".php">src/</directory>

tests/BlogCategoryTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
use SilverStripe\Security\Member;
1414
use SilverStripe\Security\Security;
1515

16-
/**
17-
* @mixin PHPUnit_Framework_TestCase
18-
*/
1916
class BlogCategoryTest extends FunctionalTest
2017
{
2118
/**
@@ -26,7 +23,7 @@ class BlogCategoryTest extends FunctionalTest
2623
/**
2724
* {@inheritdoc}
2825
*/
29-
public function setUp()
26+
protected function setUp(): void
3027
{
3128
parent::setUp();
3229

@@ -36,7 +33,7 @@ public function setUp()
3633
/**
3734
* {@inheritdoc}
3835
*/
39-
public function tearDown()
36+
protected function tearDown(): void
4037
{
4138
DBDatetime::clear_mock_now();
4239

tests/BlogFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BlogFunctionalTest extends FunctionalTest
1313

1414
protected static $use_draft_site = true;
1515

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

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

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

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

tests/BlogPostFilterTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use SilverStripe\Security\Security;
99

1010
/**
11-
* @mixin PHPUnit_Framework_TestCase
1211
* @coversDefaultClass \SilverStripe\Blog\Model\BlogPostFilter
1312
*/
1413
class BlogPostFilterTest extends SapphireTest
@@ -18,14 +17,14 @@ class BlogPostFilterTest extends SapphireTest
1817
*/
1918
protected static $fixture_file = 'blog.yml';
2019

21-
public function setUp()
20+
protected function setUp(): void
2221
{
2322
parent::setUp();
2423

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

28-
public function tearDown()
27+
protected function tearDown(): void
2928
{
3029
DBDatetime::clear_mock_now();
3130

tests/BlogPostTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BlogPostTest extends SapphireTest
1313
{
1414
protected static $fixture_file = 'blog.yml';
1515

16-
protected function tearDown()
16+
protected function tearDown(): void
1717
{
1818
DBDatetime::clear_mock_now();
1919
parent::tearDown();
@@ -159,7 +159,7 @@ public function testGetMonthlyArchiveLink($type, $expected)
159159
$blogPost = $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
160160

161161
$archiveLink = $blogPost->getMonthlyArchiveLink($type);
162-
$this->assertContains('archive/', $archiveLink);
162+
$this->assertStringContainsString('archive/', $archiveLink);
163163
$this->assertStringEndsWith($expected, $archiveLink);
164164
}
165165

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

183183
$archiveLink = $blogPost->getYearlyArchiveLink();
184-
$this->assertContains('archive/', $archiveLink);
184+
$this->assertStringContainsString('archive/', $archiveLink);
185185
$this->assertStringEndsWith('/2013', $archiveLink);
186186
}
187187
}

tests/BlogTagTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace SilverStripe\Blog\Tests;
44

5-
use PHPUnit_Framework_TestCase;
65
use SilverStripe\Blog\Model\Blog;
76
use SilverStripe\Blog\Model\BlogPost;
87
use SilverStripe\Blog\Model\BlogTag;
@@ -13,21 +12,18 @@
1312
use SilverStripe\Security\Member;
1413
use SilverStripe\Security\Security;
1514

16-
/**
17-
* @mixin PHPUnit_Framework_TestCase
18-
*/
1915
class BlogTagTest extends FunctionalTest
2016
{
2117
protected static $fixture_file = 'blog.yml';
2218

23-
protected function setUp()
19+
protected function setUp(): void
2420
{
2521
parent::setUp();
2622

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

30-
protected function tearDown()
26+
protected function tearDown(): void
3127
{
3228
DBDatetime::clear_mock_now();
3329

tests/BlogTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SilverStripe\Blog\Tests;
44

5-
use PHPUnit_Framework_TestCase;
5+
use SilverStripe\Control\HTTPResponse_Exception;
66
use SilverStripe\Blog\Model\Blog;
77
use SilverStripe\Blog\Model\BlogController;
88
use SilverStripe\Blog\Model\BlogPost;
@@ -17,14 +17,11 @@
1717
use SilverStripe\ORM\SS_List;
1818
use SilverStripe\Security\Member;
1919

20-
/**
21-
* @mixin PHPUnit_Framework_TestCase
22-
*/
2320
class BlogTest extends SapphireTest
2421
{
2522
protected static $fixture_file = 'blog.yml';
2623

27-
protected function setUp()
24+
protected function setUp(): void
2825
{
2926
parent::setUp();
3027

@@ -37,7 +34,7 @@ protected function setUp()
3734
$blog->publishRecursive();
3835
}
3936

40-
protected function tearDown()
37+
protected function tearDown(): void
4138
{
4239
DBDatetime::clear_mock_now();
4340

@@ -327,12 +324,10 @@ public function testFilteredCategoriesArchive()
327324
);
328325
}
329326

330-
/**
331-
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
332-
* @expectedExceptionCode 404
333-
*/
334327
public function testDisabledProfiles()
335328
{
329+
$this->expectException(HTTPResponse_Exception::class);
330+
$this->expectExceptionCode(404);
336331
Config::modify()->set(BlogController::class, 'disable_profiles', true);
337332

338333
$controller = BlogController::create();

tests/Model/BlogControllerFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BlogControllerFunctionalTest extends FunctionalTest
1313

1414
protected static $use_draft_site = true;
1515

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

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

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

3636
$this->assertEquals(200, $result->getStatusCode());
37-
$this->assertContains('برتراند', $result->getBody());
37+
$this->assertStringContainsString('برتراند', $result->getBody());
3838
}
3939
}

tests/Widgets/BlogArchiveWidgetTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BlogArchiveWidgetTest extends SapphireTest
1515
{
1616
protected static $fixture_file = 'BlogArchiveWidgetTest.yml';
1717

18-
protected function setUp()
18+
protected function setUp(): void
1919
{
2020
if (!class_exists(Widget::class)) {
2121
self::$fixture_file = null;
@@ -28,7 +28,7 @@ protected function setUp()
2828
parent::setUp();
2929
}
3030

31-
protected function tearDown()
31+
protected function tearDown(): void
3232
{
3333
parent::tearDown();
3434

0 commit comments

Comments
 (0)