Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker-hub/backend/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

php bin/wait-for-db.php
vendor/bin/laminas rebuild-database
Expand Down
14 changes: 12 additions & 2 deletions backend/module/eCampLib/src/Command/LoadDataFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
use Laminas\Cli\Input\PathParam;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

class LoadDataFixturesCommand extends AbstractParamAwareCommand {
private $entityManager;
private $fixtureLoader;
private $filesystem;

public function __construct(EntityManager $entityManager, FixtureLoader $fixtureLoader) {
public function __construct(EntityManager $entityManager, FixtureLoader $fixtureLoader, Filesystem $filesystem) {
parent::__construct();
$this->entityManager = $entityManager;
$this->fixtureLoader = $fixtureLoader;
$this->filesystem = $filesystem;
}

protected function configure() {
Expand All @@ -35,7 +38,14 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->entityManager,
new \Doctrine\Common\DataFixtures\Purger\ORMPurger()
);
$executor->execute($this->fixtureLoader->getFixtures(), true);
$fixtures = $this->fixtureLoader->getFixtures();
$executor->execute($fixtures, true);

if (count($fixtures) > 0) {
// Cleaning up the generated Doctrine proxies is necessary because the command might be run by a user other
// than www-data.
$this->filesystem->remove(__DIR__.'/../../../../data/DoctrineORMModule');
}

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use eCamp\LibTest\PHPUnit\AbstractConsoleControllerTestCase;
use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\Constraint\StringContains;
use PHPUnit\Framework\Constraint\StringEndsWith;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* @internal
Expand All @@ -17,12 +19,17 @@ class LoadDataFixturesCommandTest extends AbstractConsoleControllerTestCase {
public function testLoadsFilesFromGivenPath() {
// given
$services = $this->getApplicationServiceLocator();
/** @var LoadDataFixturesCommand $command */
$command = $services->get(LoadDataFixturesCommand::class);

$input = new StringInput('load-data-fixtures --path='.__DIR__.'/../data/fixtures');
$output = new BufferedOutput();
$services->setService(OutputInterface::class, $output);

$mockFilesystem = $this->createMock(Filesystem::class);
$services->setService(Filesystem::class, $mockFilesystem);

/** @var LoadDataFixturesCommand $command */
$command = $services->get(LoadDataFixturesCommand::class);

// when
$result = $this->runCommand($command, $input, $output);

Expand All @@ -36,12 +43,20 @@ public function testLoadsFilesFromGivenPath() {
public function testDoesNotCrashWhenGivenNonexistentLocation() {
// given
$services = $this->getApplicationServiceLocator();
/** @var LoadDataFixturesCommand $command */
$command = $services->get(LoadDataFixturesCommand::class);

$input = new StringInput('load-data-fixtures --path='.__DIR__.'/../data/some-dir-that-does-not-exist');
$output = new BufferedOutput();
$services->setService(OutputInterface::class, $output);

$mockFilesystem = $this->createMock(Filesystem::class);
$services->setService(Filesystem::class, $mockFilesystem);

/** @var LoadDataFixturesCommand $command */
$command = $services->get(LoadDataFixturesCommand::class);

// then
$mockFilesystem->expects($this->never())->method('remove');

// when
$result = $this->runCommand($command, $input, $output);

Expand All @@ -50,4 +65,24 @@ public function testDoesNotCrashWhenGivenNonexistentLocation() {
$consoleOutput = $output->fetch();
$this->assertThat($consoleOutput, new IsEqual(''));
}

public function testCleansUpDoctrineProxies() {
// given
$services = $this->getApplicationServiceLocator();
$input = new StringInput('load-data-fixtures --path='.__DIR__.'/../data/fixtures');
$output = new BufferedOutput();
$services->setService(OutputInterface::class, $output);

$mockFilesystem = $this->createMock(Filesystem::class);
$services->setService(Filesystem::class, $mockFilesystem);

/** @var LoadDataFixturesCommand $command */
$command = $services->get(LoadDataFixturesCommand::class);

// then
$mockFilesystem->expects($this->once())->method('remove')->with(new StringEndsWith('DoctrineORMModule'));

// when
$this->runCommand($command, $input, $output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class RebuildDatabaseSchemaCommandTest extends AbstractConsoleControllerTestCase
public function testRebuildsDatabaseSchema() {
// given
$services = $this->getApplicationServiceLocator();

$mockMetadata = [];
$mockMetadataFactory = $this->createMock(ClassMetadataFactory::class);
$mockMetadataFactory->method('getAllMetadata')->willReturn($mockMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UpdateDatabaseSchemaCommandTest extends AbstractConsoleControllerTestCase
public function testUpdatesDatabaseSchema() {
// given
$services = $this->getApplicationServiceLocator();

$mockMetadata = [];
$mockMetadataFactory = $this->createMock(ClassMetadataFactory::class);
$mockMetadataFactory->method('getAllMetadata')->willReturn($mockMetadata);
Expand Down