From 86c0f56620f9d483a3699c6a01cb845737cd5046 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 6 Apr 2018 10:22:58 +1200 Subject: [PATCH] Use ::class for class_exists checks on Widget, fix setUp/tearDown method visibility --- src/Widgets/BlogCategoriesWidget.php | 8 ++++---- src/Widgets/BlogRecentPostsWidget.php | 11 ++++++----- src/Widgets/BlogTagsCloudWidget.php | 8 ++++---- src/Widgets/BlogTagsWidget.php | 9 +++++---- tests/BlogPostNotificationsTest.php | 14 ++++++-------- tests/BlogPostTest.php | 9 +-------- tests/BlogTagTest.php | 15 +++------------ tests/BlogTagsCloudWidgetTest.php | 5 +++-- tests/BlogTest.php | 19 ++++--------------- 9 files changed, 36 insertions(+), 62 deletions(-) diff --git a/src/Widgets/BlogCategoriesWidget.php b/src/Widgets/BlogCategoriesWidget.php index dbd8d9e..215ddaf 100644 --- a/src/Widgets/BlogCategoriesWidget.php +++ b/src/Widgets/BlogCategoriesWidget.php @@ -2,10 +2,6 @@ namespace SilverStripe\Blog\Widgets; -if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) { - return; -} - use SilverStripe\Blog\Model\Blog; use SilverStripe\Core\Convert; use SilverStripe\Forms\DropdownField; @@ -14,6 +10,10 @@ use SilverStripe\Forms\NumericField; use SilverStripe\ORM\DataList; use SilverStripe\Widgets\Model\Widget; +if (!class_exists(Widget::class)) { + return; +} + /** * @method Blog Blog() */ diff --git a/src/Widgets/BlogRecentPostsWidget.php b/src/Widgets/BlogRecentPostsWidget.php index b53dd92..b5c23c4 100644 --- a/src/Widgets/BlogRecentPostsWidget.php +++ b/src/Widgets/BlogRecentPostsWidget.php @@ -2,16 +2,17 @@ namespace SilverStripe\Blog\Widgets; -if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) { - return; -} - use SilverStripe\Blog\Model\Blog; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\NumericField; +use SilverStripe\ORM\DataList; use SilverStripe\Widgets\Model\Widget; +if (!class_exists(Widget::class)) { + return; +} + /** * @method Blog Blog() * @@ -72,7 +73,7 @@ class BlogRecentPostsWidget extends Widget } /** - * @return array + * @return array|DataList */ public function getPosts() { diff --git a/src/Widgets/BlogTagsCloudWidget.php b/src/Widgets/BlogTagsCloudWidget.php index 81885ab..4730e7e 100644 --- a/src/Widgets/BlogTagsCloudWidget.php +++ b/src/Widgets/BlogTagsCloudWidget.php @@ -2,10 +2,6 @@ namespace SilverStripe\Blog\Widgets; -if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) { - return; -} - use SilverStripe\Blog\Model\Blog; use SilverStripe\Core\Convert; use SilverStripe\Forms\DropdownField; @@ -14,6 +10,10 @@ use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; use SilverStripe\Widgets\Model\Widget; +if (!class_exists(Widget::class)) { + return; +} + /** * @method Blog Blog() */ diff --git a/src/Widgets/BlogTagsWidget.php b/src/Widgets/BlogTagsWidget.php index 9994e62..cf178ea 100644 --- a/src/Widgets/BlogTagsWidget.php +++ b/src/Widgets/BlogTagsWidget.php @@ -2,17 +2,18 @@ namespace SilverStripe\Blog\Widgets; -if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) { - return; -} - use SilverStripe\Blog\Model\Blog; use SilverStripe\Core\Convert; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\NumericField; +use SilverStripe\ORM\DataList; use SilverStripe\Widgets\Model\Widget; +if (!class_exists(Widget::class)) { + return; +} + /** * @method Blog Blog() */ diff --git a/tests/BlogPostNotificationsTest.php b/tests/BlogPostNotificationsTest.php index 22559c3..6c62565 100644 --- a/tests/BlogPostNotificationsTest.php +++ b/tests/BlogPostNotificationsTest.php @@ -3,24 +3,22 @@ namespace SilverStripe\Blog\Tests; use SilverStripe\Blog\Model\BlogPost; +use SilverStripe\CommentNotifications\Extensions\CommentNotifier; +use SilverStripe\Comments\Model\Comment; use SilverStripe\Dev\SapphireTest; class BlogPostNotificationsTest extends SapphireTest { - /** - * {@inheritDoc} - * @var string - */ protected static $fixture_file = 'blog.yml'; public function testUpdateNotificationRecipients() { - if (!class_exists('CommentNotifier')) { + if (!class_exists(CommentNotifier::class)) { $this->markTestSkipped('Comments Notification module is not installed'); } $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); - $comment = new \SilverStripe\Comments\Model\Comment(); + $comment = new Comment(); $comment->Comment = 'This is a comment'; $comment->write(); $recipients = $blogPost->notificationRecipients( @@ -41,11 +39,11 @@ class BlogPostNotificationsTest extends SapphireTest public function testUpdateNotificationSubject() { - if (!class_exists('CommentNotifier')) { + if (!class_exists(CommentNotifier::class)) { $this->markTestSkipped('Comments Notification module is not installed'); } $blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); - $comment = new \SilverStripe\Comments\Model\Comment(); + $comment = new Comment(); $comment->Comment = 'This is a comment'; $comment->write(); $recipients = $blogPost->notificationRecipients( diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index 30bb4e9..899bad5 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -11,16 +11,9 @@ use SilverStripe\Versioned\Versioned; class BlogPostTest extends SapphireTest { - /** - * {@inheritDoc} - * @var string - */ protected static $fixture_file = 'blog.yml'; - /** - * {@inheritdoc} - */ - public function tearDown() + protected function tearDown() { DBDatetime::clear_mock_now(); parent::tearDown(); diff --git a/tests/BlogTagTest.php b/tests/BlogTagTest.php index 237572b..88a48ff 100755 --- a/tests/BlogTagTest.php +++ b/tests/BlogTagTest.php @@ -2,6 +2,7 @@ namespace SilverStripe\Blog\Tests; +use PHPUnit_Framework_TestCase; use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogTag; @@ -17,26 +18,16 @@ use SilverStripe\Security\Security; */ class BlogTagTest extends FunctionalTest { - /** - * {@inheritDoc} - * @var string - */ protected static $fixture_file = 'blog.yml'; - /** - * {@inheritdoc} - */ - public function setUp() + protected function setUp() { parent::setUp(); DBDatetime::set_mock_now('2013-10-10 20:00:00'); } - /** - * {@inheritdoc} - */ - public function tearDown() + protected function tearDown() { DBDatetime::clear_mock_now(); diff --git a/tests/BlogTagsCloudWidgetTest.php b/tests/BlogTagsCloudWidgetTest.php index 6a4290f..00e2ca4 100644 --- a/tests/BlogTagsCloudWidgetTest.php +++ b/tests/BlogTagsCloudWidgetTest.php @@ -7,6 +7,7 @@ use SilverStripe\Blog\Widgets\BlogTagsCloudWidget; use SilverStripe\Dev\SapphireTest; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; +use SilverStripe\Widgets\Model\Widget; class BlogTagsCloudWidgetTest extends SapphireTest { @@ -17,7 +18,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest public function testGetCMSFields() { - if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) { + if (!class_exists(Widget::class)) { $this->markTestSkipped('Widgets module not installed'); } @@ -34,7 +35,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest public function testGetTags() { - if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) { + if (!class_exists(Widget::class)) { $this->markTestSkipped('Widgets module not installed'); } $widget = new BlogTagsCloudWidget(); diff --git a/tests/BlogTest.php b/tests/BlogTest.php index 364062c..55b4d7a 100755 --- a/tests/BlogTest.php +++ b/tests/BlogTest.php @@ -2,6 +2,7 @@ namespace SilverStripe\Blog\Tests; +use PHPUnit_Framework_TestCase; use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\BlogController; use SilverStripe\Blog\Model\BlogPost; @@ -24,36 +25,24 @@ use SilverStripe\Security\Security; */ class BlogTest extends SapphireTest { - /** - * @var string - */ protected static $fixture_file = 'blog.yml'; - /** - * {@inheritdoc} - */ - public function setUp() + protected function setUp() { parent::setUp(); - Config::nest(); DBDatetime::set_mock_now('2013-10-10 20:00:00'); /** * @var Blog $blog */ $blog = $this->objFromFixture(Blog::class, 'FirstBlog'); - - $blog->publish('Stage', 'Live'); + $blog->publishRecursive(); } - /** - * {@inheritdoc} - */ - public function tearDown() + protected function tearDown() { DBDatetime::clear_mock_now(); - Config::unnest(); parent::tearDown(); }