Skip to content
Closed
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 src/Maker/MakeCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Common\Inflector\Inflector;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
Expand Down
16 changes: 14 additions & 2 deletions src/Test/MakerTestDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ public function getAssert()

public function getDependencies()
{
$depBuilder = new DependencyBuilder();
$this->maker->configureDependencies($depBuilder);
$depBuilder = $this->getDependencyBuilder();

return array_merge(
$depBuilder->getAllRequiredDependencies(),
Expand All @@ -336,6 +335,19 @@ public function getDependencies()
);
}

public function getExtraDependencies()
{
return $this->extraDependencies;
}

public function getDependencyBuilder(): DependencyBuilder
{
$depBuilder = new DependencyBuilder();
$this->maker->configureDependencies($depBuilder);

return $depBuilder;
}

public function getArgumentsString(): string
{
return $this->argumentsString;
Expand Down
35 changes: 34 additions & 1 deletion src/Test/MakerTestEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function prepare()
$this->fs->mirror($this->flexPath, $this->path);

// install any missing dependencies
if ($dependencies = $this->testDetails->getDependencies()) {
$dependencies = $this->determineMissingDependencies();
if ($dependencies) {
MakerTestProcess::create(sprintf('composer require %s', implode(' ', $dependencies)), $this->path)
->run();
}
Expand Down Expand Up @@ -381,4 +382,36 @@ private function processReplacements(array $replacements, $rootDir)
file_put_contents($path, str_replace($replacement['find'], $replacement['replace'], $contents));
}
}

/**
* Executes the DependencyBuilder for the Maker command inside the
* actual project, so we know exactly what dependencies we need or
* don't need.
*/
private function determineMissingDependencies(): array
{
$depBuilder = $this->testDetails->getDependencyBuilder();
file_put_contents($this->path.'/dep_builder', serialize($depBuilder));
file_put_contents($this->path.'/dep_runner.php', '<?php

require __DIR__."/vendor/autoload.php";
$depBuilder = unserialize(file_get_contents("dep_builder"));
$missingDependencies = array_merge(
$depBuilder->getMissingDependencies(),
$depBuilder->getMissingDevDependencies()
);
echo json_encode($missingDependencies);
');

$process = MakerTestProcess::create('php dep_runner.php', $this->path)->run();
$data = json_decode($process->getOutput(), true);
if (null === $data) {
throw new \Exception('Could not determine dependencies');
}

unlink($this->path.'/dep_builder');
unlink($this->path.'/dep_runner.php');

return array_merge($data, $this->testDetails->getExtraDependencies());
}
}
6 changes: 3 additions & 3 deletions src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private function changeValueInYaml($value)
$endValuePosition = $this->findEndPositionOfValue($originalVal);

$newYamlValue = $this->convertToYaml($value);
if (!is_array($originalVal) && is_array($value)) {
if (!\is_array($originalVal) && \is_array($value)) {
// we're converting from a scalar to a (multiline) array
// this means we need to break onto the next line

Expand Down Expand Up @@ -798,7 +798,7 @@ private function advanceCurrentPosition(int $newPosition)
* to look for indentation.
*/
if ($this->isCharLineBreak(substr($this->contents, $originalPosition - 1, 1))) {
$originalPosition--;
--$originalPosition;
}

// look for empty lines and track the current indentation
Expand Down Expand Up @@ -890,7 +890,7 @@ private function guessNextArrayTypeAndAdvance(): string
// because we are either moving along one line until [ {
// or we are finding a line break and stopping: indentation
// should not be calculated
$this->currentPosition++;
++$this->currentPosition;

if ($this->isCharLineBreak($nextCharacter)) {
return self::ARRAY_FORMAT_MULTILINE;
Expand Down
1 change: 1 addition & 0 deletions tests/Maker/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function getCommandTests()
->addExtraDependencies('doctrine')
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeUserEntityPassword')
->configureDatabase()
->addExtraDependencies('doctrine')
->setGuardAuthenticator('main', 'App\\Security\\AutomaticAuthenticator')
->setRequiredPhpVersion(70100)
->updateSchemaAfterCommand()
Expand Down