Commit e38c461f authored by François Agneray's avatar François Agneray
Browse files

Fixed bugs phpunit tests

parent 23908a15
Pipeline #5174 passed with stages
in 2 minutes and 39 seconds
......@@ -13,12 +13,10 @@ declare(strict_types=1);
namespace App\Tests\Action;
use PHPUnit\Framework\TestCase;
use Slim\Exception\HttpNotFoundException;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Response;
use App\tests\EntityManagerBuilder;
use App\Search\DBALConnectionFactory;
use App\Search\Operator\OperatorFactory;
final class AttributeDistinctActionTest extends TestCase
{
......
......@@ -15,7 +15,6 @@ namespace App\Tests\Action;
use PHPUnit\Framework\TestCase;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Response;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException;
use App\tests\EntityManagerBuilder;
use App\Entity\Database;
......
......@@ -215,11 +215,7 @@ final class DatasetListActionTest extends TestCase
private function getConnectionFactory(): DBALConnectionFactory
{
$schemaManager = $this->getMockBuilder(SqliteSchemaManager::class)
->disableOriginalConstructor()
->setMethods(['listTableColumns'])
->getMock();
$schemaManager = $this->createMock(SqliteSchemaManager::class);
$schemaManager->method('listTableColumns')
->will($this->returnValue(array(
new Column('id', Type::getType(Type::INTEGER)),
......@@ -227,19 +223,11 @@ final class DatasetListActionTest extends TestCase
new Column('dec', Type::getType(TYPE::FLOAT))
)));
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->setMethods(['getSchemaManager'])
->getMock();
$connection = $this->createMock(Connection::class);
$connection->method('getSchemaManager')
->will($this->returnValue($schemaManager));
$connectionFactory = $this->getMockBuilder(DBALConnectionFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$connectionFactory = $this->createMock(DBALConnectionFactory::class);
$connectionFactory->method('create')
->will($this->returnValue($connection));
......
......@@ -15,7 +15,6 @@ namespace App\Tests\Action;
use PHPUnit\Framework\TestCase;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Response;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException;
use App\tests\EntityManagerBuilder;
use App\Entity\Database;
......
......@@ -15,7 +15,6 @@ namespace App\Tests\Action;
use PHPUnit\Framework\TestCase;
use Nyholm\Psr7\ServerRequest;
use Nyholm\Psr7\Response;
use Slim\Exception\HttpBadRequestException;
use Slim\Exception\HttpNotFoundException;
use App\tests\EntityManagerBuilder;
use App\Entity\Database;
......
......@@ -73,30 +73,17 @@ final class TableListActionTest extends TestCase
private function getConnectionFactory(): DBALConnectionFactory
{
$schemaManager = $this->getMockBuilder(SqliteSchemaManager::class)
->disableOriginalConstructor()
->setMethods(['listTables', 'listViews'])
->getMock();
$schemaManager = $this->createMock(SqliteSchemaManager::class);
$schemaManager->method('listTables')
->will($this->returnValue(array(new Table('table1'), new Table('table2'))));
$schemaManager->method('listViews')
->will($this->returnValue(array(new View('view1', ''), new View('view2', ''))));
$connection = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->setMethods(['getSchemaManager'])
->getMock();
$connection = $this->createMock(Connection::class);
$connection->method('getSchemaManager')
->will($this->returnValue($schemaManager));
$connectionFactory = $this->getMockBuilder(DBALConnectionFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$connectionFactory = $this->createMock(DBALConnectionFactory::class);
$connectionFactory->method('create')
->will($this->returnValue($connection));
......
......@@ -15,7 +15,6 @@ namespace App\Tests;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use App\Entity\User;
abstract class EntityManagerBuilder
{
......
......@@ -23,11 +23,7 @@ final class AuthorizationMiddlewareTest extends TestCase
{
$request = new ServerRequest('OPTIONS', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response(200, [], 'Hello world')));
......
......@@ -23,11 +23,7 @@ final class ContentTypeJsonMiddlewareTest extends TestCase
{
$request = new ServerRequest('GET', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response()));
......@@ -43,11 +39,7 @@ final class ContentTypeJsonMiddlewareTest extends TestCase
'Content-Type' => 'text/html'
));
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue((new Response())->withHeader('Content-Type', 'text/html')));
......
......@@ -23,11 +23,7 @@ final class CorsMiddlewareTest extends TestCase
{
$request = new ServerRequest('OPTIONS', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response()));
......@@ -45,11 +41,7 @@ final class CorsMiddlewareTest extends TestCase
{
$request = new ServerRequest('GET', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response()));
......
......@@ -27,11 +27,7 @@ final class MetamodelSqlLoggerMiddlewareTest extends TestCase
{
$request = new ServerRequest('GET', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response(200, [], 'Hello world')));
......@@ -50,18 +46,11 @@ final class MetamodelSqlLoggerMiddlewareTest extends TestCase
$sqlLogger = $this->createMock(SQLLogger::class);
$sqlLogger->queries = [1 => 'sql1', 2 => 'sql2'];
$configuration = $this->getMockBuilder(Configuration::class)
->setMethods(['getSQLLogger'])
->getMock();
$configuration = $this->createMock(Configuration::class);
$configuration->method('getSQLLogger')
->will($this->returnValue($sqlLogger));
$em = $this->getMockBuilder(EntityManager::class)
->disableOriginalConstructor()
->setMethods(['getConfiguration'])
->getMock();
$em = $this->createMock(EntityManager::class);
$em->method('getConfiguration')
->will($this->returnValue($configuration));
......
......@@ -23,11 +23,7 @@ final class RouteGuardMiddlewareTest extends TestCase
{
$request = new ServerRequest('OPTIONS', '/');
$requestHandler = $this->getMockBuilder(RequestHandler::class)
->disableOriginalConstructor()
->setMethods(['handle'])
->getMock();
$requestHandler = $this->createMock(RequestHandler::class);
$requestHandler->method('handle')
->with($this->identicalTo($request))
->will($this->returnValue(new Response(200, [], 'Hello world')));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment