Skip to content

Commit

Permalink
Remove projectRepository from ImportProjectController
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants committed Nov 24, 2023
1 parent f669002 commit 0935c5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
5 changes: 1 addition & 4 deletions app/Project/ProjectControllerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ public function connect(Application $app)
};

$app['import_project_controller'] = function (Application $app) {
return new ImportProjectController(
$app['command_bus'],
$app['project_repository']
);
return new ImportProjectController($app['command_bus']);
};

$app['open_project_controller'] = function (Application $app) {
Expand Down
15 changes: 4 additions & 11 deletions src/Project/Controller/ImportProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace CultuurNet\ProjectAanvraag\Project\Controller;

use CultuurNet\ProjectAanvraag\Project\Command\ImportProject;
use Doctrine\ORM\EntityRepository;
use GuzzleHttp\Psr7\Response;
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class ImportProjectController
Expand All @@ -17,18 +16,12 @@ class ImportProjectController
*/
private $commandBus;

/**
* @var EntityRepository
*/
protected $projectRepository;

public function __construct(MessageBusSupportingMiddleware $commandBus, EntityRepository $projectRepository)
public function __construct(MessageBusSupportingMiddleware $commandBus)
{
$this->commandBus = $commandBus;
$this->projectRepository = $projectRepository;
}

public function importProject(string $uuid, Request $request): Response
public function importProject(string $uuid, Request $request): JsonResponse
{
$postedProject = json_decode($request->getContent());

Expand All @@ -49,6 +42,6 @@ public function importProject(string $uuid, Request $request): Response
)
);

return new Response();
return new JsonResponse();
}
}
22 changes: 2 additions & 20 deletions test/Project/Controller/ImportProjectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace CultuurNet\ProjectAanvraag\Project\Controller;

use CultuurNet\ProjectAanvraag\Entity\Project;
use CultuurNet\ProjectAanvraag\Project\Command\ImportProject;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware;
Expand All @@ -23,11 +21,6 @@ class ImportProjectControllerTest extends TestCase
*/
private $messageBus;

/**
* @var EntityRepository & MockObject
*/
private $projectRepository;

/**
* @var Request & MockObject
*/
Expand All @@ -39,12 +32,7 @@ public function setUp()

$this->request = $this->createMock(Request::class);

$this->projectRepository = $this->createMock(EntityRepository::class);

$this->controller = new ImportProjectController(
$this->messageBus,
$this->projectRepository
);
$this->controller = new ImportProjectController($this->messageBus);
}

public function testImportProject()
Expand Down Expand Up @@ -79,13 +67,7 @@ public function testImportProject()
->method('handle')
->with($importProject);

$this->projectRepository
->expects($this->once())
->method('findOneBy')
->with(['platformUuid' => $platformUuid])
->willReturn((new Project())->setId(123));

$response = $this->controller->importProject($platformUuid, $this->request);
$this->assertEquals(new JsonResponse(['databaseId' => 123]), $response, 'It correctly handles the request');
$this->assertEquals(new JsonResponse(), $response, 'It correctly handles the request');
}
}

0 comments on commit 0935c5e

Please sign in to comment.