Skip to content

Commit

Permalink
Fix creating files in the working directory with AdminMakerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and OskarStark committed Dec 3, 2019
1 parent fee8ccf commit ca65aff
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions tests/Maker/AdminMakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\Util\AutoloaderUtil;
use Symfony\Bundle\MakerBundle\Util\ComposerAutoloaderFinder;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
Expand Down Expand Up @@ -66,6 +65,11 @@ class AdminMakerTest extends TestCase
*/
private $servicesFile;

/**
* @var Filesystem
*/
private $filesystem;

protected function setup(): void
{
$managerOrmProxy = $this->prophesize(ModelManagerInterface::class);
Expand All @@ -74,14 +78,18 @@ protected function setup(): void

$this->modelManagers = ['sonata.admin.manager.orm' => $managerOrmProxy->reveal()];
$this->servicesFile = sprintf('%s.yml', lcg_value());
$this->projectDirectory = sys_get_temp_dir();
$this->projectDirectory = sys_get_temp_dir().'/sonata-admin-bundle/';
$this->filesystem = new Filesystem();
}

protected function tearDown(): void
{
@unlink($this->projectDirectory.'/config/'.$this->servicesFile);
$this->filesystem->remove($this->projectDirectory);
}

/**
* @doesNotPerformAssertions
*/
public function testExecute(): void
{
$maker = new AdminMaker($this->projectDirectory, $this->modelManagers);
Expand All @@ -108,7 +116,14 @@ public function testExecute(): void
$this->output = new StreamOutput(fopen('php://memory', 'w', false));

$this->io = new ConsoleStyle($this->input, $this->output);
$fileManager = new FileManager(new Filesystem(), new AutoloaderUtil(new ComposerAutoloaderFinder('Sonata\AdminBundle\Tests')), $this->projectDirectory.'/config/'.$this->servicesFile);
$autoloaderUtil = $this->createMock(AutoloaderUtil::class);
$autoloaderUtil
->method('getPathForFutureClass')
->willReturnCallback(function (string $className): string {
return $this->projectDirectory.'/'.str_replace('\\', '/', $className).'.php';
});

$fileManager = new FileManager($this->filesystem, $autoloaderUtil, $this->projectDirectory);
$fileManager->setIO($this->io);
$this->generator = new Generator($fileManager, 'Sonata\AdminBundle\Tests');

Expand Down

0 comments on commit ca65aff

Please sign in to comment.