From c74fa7955d9392aea954c2e45ed4137fb2bebcbe Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 24 Apr 2019 10:45:00 +0200 Subject: phpunit: Upgrade to version 8, fixed tests, formatting Use `dms/phpunit-arraysubset-asserts` after `assertArraySubset` got deprecated --- tests/Feature/ApplicationFeatureTest.php | 2 +- .../Database/DatabaseServiceProviderTest.php | 6 +++--- tests/Feature/Logger/EngelsystemLoggerTest.php | 25 ++++++++++++++++++---- tests/Feature/Model/LogEntryTest.php | 2 +- tests/Feature/Model/RoomModelTest.php | 11 +++++++++- 5 files changed, 36 insertions(+), 10 deletions(-) (limited to 'tests/Feature') diff --git a/tests/Feature/ApplicationFeatureTest.php b/tests/Feature/ApplicationFeatureTest.php index fc6216f1..3cd8b376 100644 --- a/tests/Feature/ApplicationFeatureTest.php +++ b/tests/Feature/ApplicationFeatureTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; abstract class ApplicationFeatureTest extends TestCase { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $_SERVER['HTTP_HOST'] = 'foo.bar'; require_once __DIR__ . '/../../includes/engelsystem.php'; diff --git a/tests/Feature/Database/DatabaseServiceProviderTest.php b/tests/Feature/Database/DatabaseServiceProviderTest.php index d5fdd108..d66ed25c 100644 --- a/tests/Feature/Database/DatabaseServiceProviderTest.php +++ b/tests/Feature/Database/DatabaseServiceProviderTest.php @@ -5,7 +5,7 @@ namespace Engelsystem\Test\Feature\Database; use Engelsystem\Application; use Engelsystem\Config\Config; use Engelsystem\Database\DatabaseServiceProvider; -use PHPUnit_Framework_MockObject_MockObject as MockObject; +use PHPUnit\Framework\MockObject\MockObject; class DatabaseServiceProviderTest extends DatabaseTest { @@ -14,11 +14,11 @@ class DatabaseServiceProviderTest extends DatabaseTest */ public function testRegister() { - /** @var MockObject|Config $config */ + /** @var Config|MockObject $config */ $config = $this->getMockBuilder(Config::class) ->getMock(); - /** @var MockObject|Application $app */ + /** @var Application|MockObject $app */ $app = $this->getMockBuilder(Application::class) ->setMethods(['get']) ->getMock(); diff --git a/tests/Feature/Logger/EngelsystemLoggerTest.php b/tests/Feature/Logger/EngelsystemLoggerTest.php index 9ec078a3..cb7e18f3 100644 --- a/tests/Feature/Logger/EngelsystemLoggerTest.php +++ b/tests/Feature/Logger/EngelsystemLoggerTest.php @@ -8,10 +8,12 @@ use Engelsystem\Test\Feature\ApplicationFeatureTest; use Psr\Log\InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use stdClass; class EngelsystemLoggerTest extends ApplicationFeatureTest { /** + * @covers \Engelsystem\Logger\EngelsystemLogger::__construct * @return LoggerInterface */ public function getLogger() @@ -20,6 +22,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest return new EngelsystemLogger($logEntry); } + /** + * @covers \Engelsystem\Logger\EngelsystemLogger::__construct + */ public function testImplements() { $this->assertInstanceOf(LoggerInterface::class, $this->getLogger()); @@ -43,6 +48,7 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest } /** + * @covers \Engelsystem\Models\LogEntry * @dataProvider provideLogLevels * @param string $level */ @@ -58,6 +64,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest $this->assertCount(2, $entries); } + /** + * @covers \Engelsystem\Logger\EngelsystemLogger::log + */ public function testContextReplacement() { LogEntry::query()->truncate(); @@ -78,12 +87,13 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest return [ ['Data and {context}', [], 'Data and {context}'], ['Data and {context}', ['context' => null], 'Data and '], - ['Data and {context}', ['context' => new \stdClass()], 'Data and {context}'], + ['Data and {context}', ['context' => new stdClass()], 'Data and {context}'], ['Some user asked: {question}', ['question' => 'Foo?'], 'Some user asked: Foo?'], ]; } /** + * @covers \Engelsystem\Logger\EngelsystemLogger::log * @dataProvider provideContextReplaceValues * * @param string $message @@ -99,6 +109,9 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest $this->assertEquals($expected, $entry['message']); } + /** + * @covers \Engelsystem\Logger\EngelsystemLogger::log + */ public function testContextToString() { LogEntry::query()->truncate(); @@ -119,19 +132,20 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest } /** - * @expectedException InvalidArgumentException + * @covers \Engelsystem\Logger\EngelsystemLogger::log */ public function testThrowExceptionOnInvalidLevel() { $logger = $this->getLogger(); + $this->expectException(InvalidArgumentException::class); $logger->log('This log level should never be defined', 'Some message'); } /** * @return array */ - public function getLastEntry() + protected function getLastEntry() { $entries = LogEntry::all(); $entry = $entries->last(); @@ -139,7 +153,10 @@ class EngelsystemLoggerTest extends ApplicationFeatureTest return $entry; } - public function tearDown() + /** + * Cleanup + */ + protected function tearDown(): void { LogEntry::query()->truncate(); } diff --git a/tests/Feature/Model/LogEntryTest.php b/tests/Feature/Model/LogEntryTest.php index 25b35676..7fad8232 100644 --- a/tests/Feature/Model/LogEntryTest.php +++ b/tests/Feature/Model/LogEntryTest.php @@ -49,7 +49,7 @@ class LogEntryTest extends TestCase /** * This method is called before a test is executed. */ - public function setUp() + protected function setUp(): void { LogEntry::query()->truncate(); } diff --git a/tests/Feature/Model/RoomModelTest.php b/tests/Feature/Model/RoomModelTest.php index 216c87da..9908082a 100644 --- a/tests/Feature/Model/RoomModelTest.php +++ b/tests/Feature/Model/RoomModelTest.php @@ -8,11 +8,17 @@ class RoomModelTest extends TestCase { private $room_id = null; + /** + * @covers \Room_create + */ public function createRoom() { $this->room_id = Room_create('test', false, null, null); } + /** + * @covers \Room + */ public function testRoom() { $this->createRoom(); @@ -26,7 +32,10 @@ class RoomModelTest extends TestCase $this->assertEmpty(Room(-1)); } - public function tearDown() + /** + * Cleanup + */ + protected function tearDown(): void { if ($this->room_id != null) { Room_delete($this->room_id); -- cgit v1.2.3-54-g00ecf