phpunit: Upgrade to version 8, fixed tests, formatting

Use `dms/phpunit-arraysubset-asserts` after `assertArraySubset` got deprecated
This commit is contained in:
Igor Scheller 2019-04-24 10:45:00 +02:00 committed by msquare
parent b74835a096
commit c74fa7955d
52 changed files with 191 additions and 124 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
*.DS_Store
.*.swp
*.out
*.cache
Thumbs.db
.project
.buildpath

View File

@ -39,8 +39,9 @@
"twig/twig": "~2.6.0"
},
"require-dev": {
"dms/phpunit-arraysubset-asserts": "^0.1.0",
"filp/whoops": "^2.1",
"phpunit/phpunit": "^6.3",
"phpunit/phpunit": "^8.1",
"symfony/var-dumper": "^3.3"
},
"autoload": {

View File

@ -9,6 +9,11 @@ abstract class Migration
/** @var SchemaBuilder */
protected $schema;
/**
* Migration constructor.
*
* @param SchemaBuilder $schemaBuilder
*/
public function __construct(SchemaBuilder $schemaBuilder)
{
$this->schema = $schemaBuilder;

View File

@ -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';

View File

@ -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();

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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);

View File

@ -6,8 +6,8 @@ use Engelsystem\Application;
use Engelsystem\Config\Config;
use Engelsystem\Container\Container;
use Engelsystem\Container\ServiceProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;
use Psr\Container\ContainerInterface;
use Psr\Http\Server\MiddlewareInterface;
use ReflectionClass;
@ -130,7 +130,7 @@ class ApplicationTest extends TestCase
*/
public function testBootstrap()
{
/** @var PHPUnit_Framework_MockObject_MockObject|Application $app */
/** @var Application|MockObject $app */
$app = $this->getMockBuilder(Application::class)
->setMethods(['register'])
->getMock();
@ -143,6 +143,7 @@ class ApplicationTest extends TestCase
->method('register')
->with($serviceProvider);
/** @var Config|MockObject $config */
$config = $this->getMockBuilder(Config::class)
->getMock();
@ -168,7 +169,7 @@ class ApplicationTest extends TestCase
/**
* @param Application $app
* @param array $methods
* @return PHPUnit_Framework_MockObject_MockObject|ServiceProvider
* @return ServiceProvider|MockObject
*/
protected function mockServiceProvider(Application $app, $methods = [])
{

View File

@ -2,6 +2,7 @@
namespace Engelsystem\Test\Unit\Config;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Application;
use Engelsystem\Config\Config;
use Engelsystem\Config\ConfigServiceProvider;
@ -14,13 +15,15 @@ use PHPUnit\Framework\MockObject\MockObject;
class ConfigServiceProviderTest extends ServiceProviderTest
{
use ArraySubsetAsserts;
/**
* @covers \Engelsystem\Config\ConfigServiceProvider::register
* @covers \Engelsystem\Config\ConfigServiceProvider::getConfigPath
*/
public function testRegister()
{
/** @var MockObject|Config $config */
/** @var Config|MockObject $config */
$config = $this->getMockBuilder(Config::class)
->getMock();
@ -61,7 +64,7 @@ class ConfigServiceProviderTest extends ServiceProviderTest
*/
public function testRegisterException()
{
/** @var MockObject|Config $config */
/** @var Config|MockObject $config */
$config = $this->getMockBuilder(Config::class)
->getMock();

View File

@ -13,7 +13,7 @@ use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Database\Connection;
use PDO;
use PDOException;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
class DatabaseServiceProviderTest extends ServiceProviderTest
{
@ -78,13 +78,13 @@ class DatabaseServiceProviderTest extends ServiceProviderTest
*/
protected function prepare($dbConfigData, $getPdoThrowException = false)
{
/** @var MockObject|Config $config */
/** @var Config|MockObject $config */
$config = $this->getMockBuilder(Config::class)
->getMock();
/** @var MockObject|CapsuleManager $config */
/** @var CapsuleManager|MockObject $config */
$dbManager = $this->getMockBuilder(CapsuleManager::class)
->getMock();
/** @var MockObject|Connection $connection */
/** @var Connection|MockObject $connection */
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();

View File

@ -6,8 +6,8 @@ use Engelsystem\Database\Database;
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Database\Connection as DatabaseConnection;
use PDO;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class DatabaseTest extends TestCase
{
@ -69,7 +69,7 @@ class DatabaseTest extends TestCase
$this->assertEmpty($return);
$return = $db->selectOne('SELECT * FROM test_data WHERE id = ?', [3]);
$this->assertTrue(!is_array($return));
$this->assertIsNotArray($return);
}
/**
@ -114,7 +114,7 @@ class DatabaseTest extends TestCase
/**
* Setup in memory database
*/
protected function setUp()
protected function setUp(): void
{
$dbManager = new CapsuleManager();
$dbManager->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);

View File

@ -6,8 +6,8 @@ use Engelsystem\Database\Db;
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Database\Connection as DatabaseConnection;
use PDO;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
class DbTest extends TestCase
{
@ -17,15 +17,15 @@ class DbTest extends TestCase
*/
public function testSetDbManager()
{
/** @var MockObject|Pdo $pdo */
/** @var Pdo|MockObject $pdo */
$pdo = $this->getMockBuilder(Pdo::class)
->disableOriginalConstructor()
->getMock();
/** @var MockObject|CapsuleManager $dbManager */
/** @var CapsuleManager|MockObject $dbManager */
$dbManager = $this->getMockBuilder(CapsuleManager::class)
->disableOriginalConstructor()
->getMock();
/** @var MockObject|DatabaseConnection $dbManager */
/** @var DatabaseConnection|MockObject $dbManager */
$databaseConnection = $this->getMockBuilder(DatabaseConnection::class)
->disableOriginalConstructor()
->getMock();
@ -69,7 +69,7 @@ class DbTest extends TestCase
$return = Db::selectOne('SELECT * FROM test_data WHERE id = ?', [3]);
$return = array_pop($return);
$this->assertTrue(!is_array($return));
$this->assertIsNotArray($return);
}
/**
@ -117,7 +117,7 @@ class DbTest extends TestCase
/**
* Setup in memory database
*/
protected function setUp()
protected function setUp(): void
{
$dbManager = new CapsuleManager();
$dbManager->addConnection(['driver' => 'sqlite', 'database' => ':memory:']);

View File

@ -21,15 +21,15 @@ class MigrateTest extends TestCase
*/
public function testRun()
{
/** @var MockObject|Application $app */
/** @var Application|MockObject $app */
$app = $this->getMockBuilder(Application::class)
->setMethods(['instance'])
->getMock();
/** @var MockObject|SchemaBuilder $builder */
/** @var SchemaBuilder|MockObject $builder */
$builder = $this->getMockBuilder(SchemaBuilder::class)
->disableOriginalConstructor()
->getMock();
/** @var MockObject|Migrate $migration */
/** @var Migrate|MockObject $migration */
$migration = $this->getMockBuilder(Migrate::class)
->setConstructorArgs([$builder, $app])
->setMethods(['initMigration', 'getMigrationFiles', 'getMigrated', 'migrate', 'setMigrated'])

View File

@ -8,7 +8,7 @@ use Engelsystem\Database\Migration\MigrationServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
class MigrationServiceProviderTest extends ServiceProviderTest
{
@ -17,7 +17,7 @@ class MigrationServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
/** @var MockObject|Migrate $migration */
/** @var Migrate|MockObject $migration */
$migration = $this->getMockBuilder(Migrate::class)
->disableOriginalConstructor()
->getMock();
@ -25,11 +25,11 @@ class MigrationServiceProviderTest extends ServiceProviderTest
$database = $this->getMockBuilder(Database::class)
->disableOriginalConstructor()
->getMock();
/** @var MockObject|Connection $dbConnection */
/** @var Connection|MockObject $dbConnection */
$dbConnection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
/** @var MockObject|SchemaBuilder $schemaBuilder */
/** @var SchemaBuilder|MockObject $schemaBuilder */
$schemaBuilder = $this->getMockBuilder(SchemaBuilder::class)
->disableOriginalConstructor()
->getMock();

View File

@ -19,6 +19,6 @@ class MigrationTest extends TestCase
->getMock();
$instance = new AnotherStuff($schemaBuilder);
$this->assertAttributeEquals($schemaBuilder, 'schema', $instance);
$this->assertEquals($schemaBuilder, $instance->getSchema());
}
}

View File

@ -3,6 +3,7 @@
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Builder as SchemaBuilder;
class AnotherStuff extends Migration
{
@ -21,4 +22,12 @@ class AnotherStuff extends Migration
{
// nope
}
/**
* @return SchemaBuilder
*/
public function getSchema()
{
return $this->schema;
}
}

View File

@ -10,7 +10,7 @@ use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
use Engelsystem\Exceptions\Handlers\Whoops;
use Engelsystem\Http\Request;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
class ExceptionsServiceProviderTest extends ServiceProviderTest
{
@ -23,7 +23,7 @@ class ExceptionsServiceProviderTest extends ServiceProviderTest
{
$app = $this->getApp(['make', 'instance', 'bind']);
/** @var MockObject|Handler $handler */
/** @var Handler|MockObject $handler */
$handler = $this->createMock(Handler::class);
$this->setExpects($handler, 'register');
/** @var Legacy|MockObject $legacyHandler */
@ -81,10 +81,10 @@ class ExceptionsServiceProviderTest extends ServiceProviderTest
*/
public function testBoot()
{
/** @var MockObject|Handler $handler */
/** @var Handler|MockObject $handler */
$handler = $this->createMock(Handler::class);
/** @var MockObject|Request $request */
/** @var Request|MockObject $request */
$request = $this->createMock(Request::class);
$handler->expects($this->once())

View File

@ -7,8 +7,8 @@ use Engelsystem\Exceptions\Handlers\HandlerInterface;
use Engelsystem\Http\Request;
use ErrorException;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as Mock;
class HandlerTest extends TestCase
{
@ -17,7 +17,7 @@ class HandlerTest extends TestCase
*/
public function testCreate()
{
/** @var Handler|Mock $handler */
/** @var Handler|MockObject $handler */
$handler = new Handler();
$this->assertInstanceOf(Handler::class, $handler);
$this->assertEquals(Handler::ENV_PRODUCTION, $handler->getEnvironment());
@ -31,7 +31,7 @@ class HandlerTest extends TestCase
*/
public function testErrorHandler()
{
/** @var Handler|Mock $handler */
/** @var Handler|MockObject $handler */
$handler = $this->getMockBuilder(Handler::class)
->setMethods(['exceptionHandler'])
->getMock();
@ -51,7 +51,7 @@ class HandlerTest extends TestCase
$exception = new Exception();
$errorMessage = 'Oh noes, an error!';
/** @var HandlerInterface|Mock $handlerMock */
/** @var HandlerInterface|MockObject $handlerMock */
$handlerMock = $this->getMockForAbstractClass(HandlerInterface::class);
$handlerMock->expects($this->atLeastOnce())
->method('report')
@ -63,7 +63,7 @@ class HandlerTest extends TestCase
echo $errorMessage;
});
/** @var Handler|Mock $handler */
/** @var Handler|MockObject $handler */
$handler = $this->getMockBuilder(Handler::class)
->setMethods(['terminateApplicationImmediately'])
->getMock();
@ -84,7 +84,7 @@ class HandlerTest extends TestCase
*/
public function testRegister()
{
/** @var Handler|Mock $handler */
/** @var Handler|MockObject $handler */
$handler = $this->getMockForAbstractClass(Handler::class);
$handler->register();
@ -120,9 +120,9 @@ class HandlerTest extends TestCase
public function testHandler()
{
$handler = new Handler();
/** @var HandlerInterface|Mock $devHandler */
/** @var HandlerInterface|MockObject $devHandler */
$devHandler = $this->getMockForAbstractClass(HandlerInterface::class);
/** @var HandlerInterface|Mock $prodHandler */
/** @var HandlerInterface|MockObject $prodHandler */
$prodHandler = $this->getMockForAbstractClass(HandlerInterface::class);
$handler->setHandler(Handler::ENV_DEVELOPMENT, $devHandler);
@ -139,7 +139,7 @@ class HandlerTest extends TestCase
public function testRequest()
{
$handler = new Handler();
/** @var Request|Mock $request */
/** @var Request|MockObject $request */
$request = $this->createMock(Request::class);
$handler->setRequest($request);

View File

@ -6,8 +6,8 @@ namespace Engelsystem\Test\Unit\Exceptions\handlers;
use Engelsystem\Exceptions\Handlers\LegacyDevelopment;
use Engelsystem\Http\Request;
use ErrorException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as Mock;
class LegacyDevelopmentTest extends TestCase
{
@ -18,7 +18,7 @@ class LegacyDevelopmentTest extends TestCase
public function testRender()
{
$handler = new LegacyDevelopment();
/** @var Request|Mock $request */
/** @var Request|MockObject $request */
$request = $this->createMock(Request::class);
$exception = new ErrorException('Lorem Ipsum', 4242, 1, 'foo.php', 9999);

View File

@ -6,8 +6,8 @@ namespace Engelsystem\Test\Unit\Exceptions\handlers;
use Engelsystem\Exceptions\Handlers\Legacy;
use Engelsystem\Http\Request;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as Mock;
class LegacyTest extends TestCase
{
@ -17,9 +17,9 @@ class LegacyTest extends TestCase
public function testRender()
{
$handler = new Legacy();
/** @var Request|Mock $request */
/** @var Request|MockObject $request */
$request = $this->createMock(Request::class);
/** @var Exception|Mock $exception */
/** @var Exception|MockObject $exception */
$exception = $this->createMock(Exception::class);
$this->expectOutputRegex('/.*error occurred.*/i');
@ -45,11 +45,11 @@ class LegacyTest extends TestCase
$logContent = file_get_contents($log);
unset($log);
$this->assertContains('4242', $logContent);
$this->assertContains('Lorem Ipsum', $logContent);
$this->assertContains(basename(__FILE__), $logContent);
$this->assertContains((string)$line, $logContent);
$this->assertContains(__FUNCTION__, $logContent);
$this->assertContains(json_encode(__CLASS__), $logContent);
$this->assertStringContainsString('4242', $logContent);
$this->assertStringContainsString('Lorem Ipsum', $logContent);
$this->assertStringContainsString(basename(__FILE__), $logContent);
$this->assertStringContainsString((string)$line, $logContent);
$this->assertStringContainsString(__FUNCTION__, $logContent);
$this->assertStringContainsString(json_encode(__CLASS__), $logContent);
}
}

View File

@ -8,8 +8,8 @@ use Engelsystem\Exceptions\Handlers\Whoops;
use Engelsystem\Helpers\Authenticator;
use Engelsystem\Http\Request;
use Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as Mock;
use Whoops\Handler\JsonResponseHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run as WhoopsRunner;
@ -22,19 +22,19 @@ class WhoopsTest extends TestCase
*/
public function testRender()
{
/** @var Application|Mock $app */
/** @var Application|MockObject $app */
$app = $this->createMock(Application::class);
/** @var Authenticator|Mock $auth */
/** @var Authenticator|MockObject $auth */
$auth = $this->createMock(Authenticator::class);
/** @var Request|Mock $request */
/** @var Request|MockObject $request */
$request = $this->createMock(Request::class);
/** @var WhoopsRunnerInterface|Mock $whoopsRunner */
/** @var WhoopsRunnerInterface|MockObject $whoopsRunner */
$whoopsRunner = $this->getMockForAbstractClass(WhoopsRunnerInterface::class);
/** @var PrettyPageHandler|Mock $prettyPageHandler */
/** @var PrettyPageHandler|MockObject $prettyPageHandler */
$prettyPageHandler = $this->createMock(PrettyPageHandler::class);
/** @var JsonResponseHandler|Mock $jsonResponseHandler */
/** @var JsonResponseHandler|MockObject $jsonResponseHandler */
$jsonResponseHandler = $this->createMock(JsonResponseHandler::class);
/** @var Exception|Mock $exception */
/** @var Exception|MockObject $exception */
$exception = $this->createMock(Exception::class);
$request->expects($this->once())

View File

@ -39,11 +39,11 @@ class AuthenticatorTest extends ServiceProviderTest
$auth = new Authenticator($request, $session, $userRepository);
// Not in session
$this->assertEquals(null, $auth->user());
$this->assertNull($auth->user());
// Unknown user
UserModelImplementation::$id = 42;
$this->assertEquals(null, $auth->user());
$this->assertNull($auth->user());
// User found
UserModelImplementation::$id = 1337;
@ -83,11 +83,11 @@ class AuthenticatorTest extends ServiceProviderTest
$auth = new Authenticator($request, $session, $userRepository);
// No key
$this->assertEquals(null, $auth->apiUser());
$this->assertNull($auth->apiUser());
// Unknown user
UserModelImplementation::$apiKey = 'iMaNot3xiSt1nGAp1Key!';
$this->assertEquals(null, $auth->apiUser());
$this->assertNull($auth->apiUser());
// User found
UserModelImplementation::$apiKey = 'SomeSecretApiKey';

View File

@ -11,8 +11,8 @@ use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
use Engelsystem\Http\UrlGeneratorInterface;
use Engelsystem\Renderer\Renderer;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface as StorageInterface;
@ -59,7 +59,7 @@ class HelpersTest extends TestCase
*/
public function testBasePath()
{
/** @var MockObject|Application $app */
/** @var Application|MockObject $app */
$app = $this->getMockBuilder(Container::class)
->getMock();
Application::setInstance($app);
@ -103,7 +103,7 @@ class HelpersTest extends TestCase
*/
public function testConfigPath()
{
/** @var MockObject|Application $app */
/** @var Application|MockObject $app */
$app = $this->getMockBuilder(Container::class)
->getMock();
Application::setInstance($app);
@ -155,7 +155,7 @@ class HelpersTest extends TestCase
*/
public function testResponse()
{
/** @var MockObject|Response $response */
/** @var Response|MockObject $response */
$response = $this->getMockBuilder(Response::class)->getMock();
$this->getAppMock('psr7.response', $response);

View File

@ -2,12 +2,15 @@
namespace Engelsystem\Test\Unit\Http;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Test\Unit\Http\Stub\MessageTraitRequestImplementation;
use Nyholm\Psr7\Stream;
use PHPUnit\Framework\TestCase;
class MessageTraitRequestTest extends TestCase
{
use ArraySubsetAsserts;
/**
* @covers \Engelsystem\Http\MessageTrait::withProtocolVersion
*/

View File

@ -2,6 +2,7 @@
namespace Engelsystem\Test\Unit\Http;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Test\Unit\Http\Stub\MessageTraitResponseImplementation;
use Nyholm\Psr7\Stream;
use PHPUnit\Framework\TestCase;
@ -11,6 +12,8 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class MessageTraitResponseTest extends TestCase
{
use ArraySubsetAsserts;
/**
* @covers \Engelsystem\Http\MessageTrait
*/

View File

@ -7,7 +7,7 @@ use Engelsystem\Container\ServiceProvider;
use Engelsystem\Http\Request;
use Engelsystem\Http\RequestServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class RequestServiceProviderTest extends ServiceProviderTest

View File

@ -4,8 +4,8 @@ namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Http\Request;
use Nyholm\Psr7\UploadedFile;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Psr\Http\Message\UriInterface;
@ -90,7 +90,7 @@ class RequestTest extends TestCase
*/
public function testPath()
{
/** @var MockObject|Request $request */
/** @var Request|MockObject $request */
$request = $this
->getMockBuilder(Request::class)
->setMethods(['getPathInfo'])
@ -113,7 +113,7 @@ class RequestTest extends TestCase
*/
public function testUrl()
{
/** @var MockObject|Request $request */
/** @var Request|MockObject $request */
$request = $this
->getMockBuilder(Request::class)
->setMethods(['getUri'])
@ -368,7 +368,7 @@ class RequestTest extends TestCase
$request = new Request([], [], $attributes);
$this->assertEquals($attributes['ipsum'], $request->getAttribute('ipsum'));
$this->assertEquals(null, $request->getAttribute('dolor'));
$this->assertNull($request->getAttribute('dolor'));
$this->assertEquals(1234, $request->getAttribute('test', 1234));
}

View File

@ -5,7 +5,7 @@ namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Http\Response;
use Engelsystem\Http\ResponseServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class ResponseServiceProviderTest extends ServiceProviderTest
@ -15,7 +15,7 @@ class ResponseServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
/** @var MockObject|Response $response */
/** @var Response|MockObject $response */
$response = $this->getMockBuilder(Response::class)
->getMock();

View File

@ -2,8 +2,10 @@
namespace Engelsystem\Test\Unit\Http;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Http\Response;
use Engelsystem\Renderer\Renderer;
use InvalidArgumentException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
@ -11,6 +13,8 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
class ResponseTest extends TestCase
{
use ArraySubsetAsserts;
/**
* @covers \Engelsystem\Http\Response
*/
@ -76,7 +80,7 @@ class ResponseTest extends TestCase
*/
public function testWithViewNoRenderer()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$response = new Response();
$response->withView('foo');

View File

@ -88,7 +88,7 @@ class DatabaseHandlerTest extends TestCase
/**
* Prepare tests
*/
protected function setUp()
protected function setUp(): void
{
$this->initDatabase();
}

View File

@ -7,7 +7,7 @@ use Engelsystem\Http\Request;
use Engelsystem\Http\SessionHandlers\DatabaseHandler;
use Engelsystem\Http\SessionServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
@ -33,7 +33,7 @@ class SessionServiceProviderTest extends ServiceProviderTest
$session = $this->getSessionMock();
$request = $this->getRequestMock();
/** @var MockObject|SessionServiceProvider $serviceProvider */
/** @var SessionServiceProvider|MockObject $serviceProvider */
$serviceProvider = $this->getMockBuilder(SessionServiceProvider::class)
->setConstructorArgs([$app])
->setMethods(['isCli'])

View File

@ -5,7 +5,7 @@ namespace Engelsystem\Test\Unit\Http;
use Engelsystem\Http\UrlGenerator;
use Engelsystem\Http\UrlGeneratorServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
class UrlGeneratorServiceProviderTest extends ServiceProviderTest
{
@ -14,7 +14,7 @@ class UrlGeneratorServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
/** @var PHPUnit_Framework_MockObject_MockObject|UrlGenerator $urlGenerator */
/** @var UrlGenerator|MockObject $urlGenerator */
$urlGenerator = $this->getMockBuilder(UrlGenerator::class)
->getMock();

View File

@ -5,7 +5,7 @@ namespace Engelsystem\Test\Unit\Logger;
use Engelsystem\Logger\EngelsystemLogger;
use Engelsystem\Logger\LoggerServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class LoggerServiceProviderTest extends ServiceProviderTest
@ -15,7 +15,7 @@ class LoggerServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
/** @var PHPUnit_Framework_MockObject_MockObject|EngelsystemLogger $logger */
/** @var EngelsystemLogger|MockObject $logger */
$logger = $this->getMockBuilder(EngelsystemLogger::class)
->disableOriginalConstructor()
->getMock();

View File

@ -35,13 +35,13 @@ class LogTransportTest extends TestCase
->method('debug')
->willReturnCallback(function ($message, $context = []) {
foreach (array_keys($context) as $key) {
$this->assertContains(sprintf('{%s}', $key), $message);
$this->assertStringContainsString(sprintf('{%s}', $key), $message);
}
$this->assertEquals('Some subject', $context['title']);
$this->assertEquals('foo@bar.batz,Lorem Ipsum <lor@em.ips>', $context['recipients']);
$this->assertContains('Head: er', $context['content']);
$this->assertContains('Message body', $context['content']);
$this->assertStringContainsString('Head: er', $context['content']);
$this->assertStringContainsString('Message body', $context['content']);
});
/** @var LogTransport|MockObject $transport */

View File

@ -2,16 +2,19 @@
namespace Engelsystem\Test\Unit\Middleware;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Config\Config;
use Engelsystem\Http\Response;
use Engelsystem\Middleware\AddHeaders;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class AddHeadersTest extends TestCase
{
use ArraySubsetAsserts;
/**
* @covers \Engelsystem\Middleware\AddHeaders::__construct
* @covers \Engelsystem\Middleware\AddHeaders::process

View File

@ -7,8 +7,8 @@ use Engelsystem\Middleware\Dispatcher;
use Engelsystem\Test\Unit\Middleware\Stub\NotARealMiddleware;
use InvalidArgumentException;
use LogicException;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;

View File

@ -9,8 +9,8 @@ use Engelsystem\Middleware\ExceptionHandler;
use Engelsystem\Test\Unit\Middleware\Stub\ExceptionMiddlewareHandler;
use Engelsystem\Test\Unit\Middleware\Stub\ReturnResponseMiddlewareHandler;
use Illuminate\Contracts\Container\Container as ContainerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -22,13 +22,13 @@ class ExceptionHandlerTest extends TestCase
*/
public function testRegister()
{
/** @var MockObject|ContainerInterface $container */
/** @var ContainerInterface|MockObject $container */
$container = $this->getMockForAbstractClass(ContainerInterface::class);
/** @var MockObject|ServerRequestInterface $request */
/** @var ServerRequestInterface|MockObject $request */
$request = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
/** @var MockObject|ResponseInterface $response */
/** @var ResponseInterface|MockObject $response */
$response = $this->getMockBuilder(Response::class)->getMock();
/** @var MockObject|Handler $errorHandler */
/** @var Handler|MockObject $errorHandler */
$errorHandler = $this->getMockBuilder(Handler::class)->getMock();
$returnResponseHandler = new ReturnResponseMiddlewareHandler($response);
$throwExceptionHandler = new ExceptionMiddlewareHandler();

View File

@ -6,8 +6,8 @@ use Engelsystem\Helpers\Authenticator;
use Engelsystem\Helpers\Translator;
use Engelsystem\Http\Request;
use Engelsystem\Middleware\LegacyMiddleware;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

View File

@ -3,8 +3,8 @@
namespace Engelsystem\Test\Unit\Middleware;
use Engelsystem\Middleware\SendResponseHandler;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

View File

@ -34,7 +34,7 @@ class SessionHandlerServiceProviderTest extends ServiceProviderTest
->willReturnCallback(function (callable $callable) {
$paths = $callable();
$this->assertTrue(is_array($paths));
$this->assertIsArray($paths);
$this->assertTrue(in_array('/metrics', $paths));
});

View File

@ -3,8 +3,8 @@
namespace Engelsystem\Test\Unit\Middleware;
use Engelsystem\Middleware\SessionHandler;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

View File

@ -4,8 +4,8 @@ namespace Engelsystem\Test\Unit\Middleware;
use Engelsystem\Helpers\Translator;
use Engelsystem\Middleware\SetLocale;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

View File

@ -121,7 +121,7 @@ class EventConfigTest extends TestCase
/**
* Prepare test
*/
protected function setUp()
protected function setUp(): void
{
$this->initDatabase();
}

View File

@ -26,7 +26,7 @@ class HasUserModelTest extends TestCase
/**
* Prepare test
*/
protected function setUp()
protected function setUp(): void
{
$this->initDatabase();
}

View File

@ -2,6 +2,7 @@
namespace Engelsystem\Test\Unit\Models;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Engelsystem\Models\User\Contact;
use Engelsystem\Models\User\HasUserModel;
use Engelsystem\Models\User\PersonalData;
@ -13,6 +14,7 @@ use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
use ArraySubsetAsserts;
use HasDatabase;
protected $data = [
@ -91,7 +93,7 @@ class UserTest extends TestCase
/**
* Prepare test
*/
protected function setUp()
protected function setUp(): void
{
$this->initDatabase();
}

View File

@ -58,7 +58,10 @@ class HtmlEngineTest extends TestCase
return $fileName;
}
public function tearDown()
/**
* Remove files
*/
protected function tearDown(): void
{
foreach ($this->tmpFileNames as $fileName) {
unlink($fileName);

View File

@ -7,7 +7,7 @@ use Engelsystem\Renderer\HtmlEngine;
use Engelsystem\Renderer\Renderer;
use Engelsystem\Renderer\RendererServiceProvider;
use Engelsystem\Test\Unit\ServiceProviderTest;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit\Framework\MockObject\MockObject;
class RendererServiceProviderTest extends ServiceProviderTest
{
@ -18,10 +18,10 @@ class RendererServiceProviderTest extends ServiceProviderTest
*/
public function testRegister()
{
/** @var PHPUnit_Framework_MockObject_MockObject|Renderer $renderer */
/** @var Renderer|MockObject $renderer */
$renderer = $this->getMockBuilder(Renderer::class)
->getMock();
/** @var PHPUnit_Framework_MockObject_MockObject|HtmlEngine $htmlEngine */
/** @var HtmlEngine|MockObject $htmlEngine */
$htmlEngine = $this->getMockBuilder(HtmlEngine::class)
->getMock();
@ -57,12 +57,12 @@ class RendererServiceProviderTest extends ServiceProviderTest
*/
public function testBoot()
{
/** @var PHPUnit_Framework_MockObject_MockObject|Renderer $renderer */
/** @var Renderer|MockObject $renderer */
$renderer = $this->getMockBuilder(Renderer::class)
->getMock();
/** @var PHPUnit_Framework_MockObject_MockObject|EngineInterface $engine1 */
/** @var EngineInterface|MockObject $engine1 */
$engine1 = $this->getMockForAbstractClass(EngineInterface::class);
/** @var PHPUnit_Framework_MockObject_MockObject|EngineInterface $engine2 */
/** @var EngineInterface|MockObject $engine2 */
$engine2 = $this->getMockForAbstractClass(EngineInterface::class);
$app = $this->getApp(['get', 'tagged']);

View File

@ -4,8 +4,8 @@ namespace Engelsystem\Test\Unit\Renderer;
use Engelsystem\Renderer\EngineInterface;
use Engelsystem\Renderer\Renderer;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Psr\Log\LoggerInterface;
class RendererTest extends TestCase
@ -14,7 +14,7 @@ class RendererTest extends TestCase
{
$renderer = new Renderer();
/** @var MockObject|EngineInterface $nullRenderer */
/** @var EngineInterface|MockObject $nullRenderer */
$nullRenderer = $this->getMockForAbstractClass(EngineInterface::class);
$nullRenderer->expects($this->atLeastOnce())
@ -22,7 +22,7 @@ class RendererTest extends TestCase
->willReturn(false);
$renderer->addRenderer($nullRenderer);
/** @var MockObject|EngineInterface $mockRenderer */
/** @var EngineInterface|MockObject $mockRenderer */
$mockRenderer = $this->getMockForAbstractClass(EngineInterface::class);
$mockRenderer->expects($this->atLeastOnce())
@ -45,7 +45,7 @@ class RendererTest extends TestCase
{
$renderer = new Renderer();
/** @var MockObject|LoggerInterface $loggerMock */
/** @var LoggerInterface|MockObject $loggerMock */
$loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
$loggerMock
->expects($this->once())

View File

@ -2,6 +2,7 @@
namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Twig_Function as TwigFunction;
@ -9,6 +10,8 @@ use Twig_Node as TwigNode;
abstract class ExtensionTest extends TestCase
{
use ArraySubsetAsserts;
/**
* Assert that a twig filter was registered
*

View File

@ -3,7 +3,7 @@
namespace Engelsystem\Test\Unit;
use Engelsystem\Application;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject;
abstract class ServiceProviderTest extends TestCase
{
@ -13,7 +13,7 @@ abstract class ServiceProviderTest extends TestCase
*/
protected function getApp($methods = ['make', 'instance'])
{
/** @var MockObject|Application $app */
/** @var Application|MockObject $app */
return $this->getMockBuilder(Application::class)
->setMethods($methods)
->getMock();

View File

@ -3,8 +3,8 @@
namespace Engelsystem\Test\Unit;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
abstract class TestCase extends PHPUnitTestCase
{