Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Allow version 1.20.0 of spryker/propel-orm #19

Merged
merged 2 commits into from
Jan 15, 2024
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
22 changes: 22 additions & 0 deletions src/FondOfCodeception/Lib/PropelApplicationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace FondOfCodeception\Lib;

use Propel\Generator\Command\ModelBuildCommand;
use Symfony\Component\Console\Application;

class PropelApplicationFactory
{
/**
* @return \Symfony\Component\Console\Application
*/
public function create(): Application
{
$application = new Application();

$application->setAutoExit(false);
$application->add(new ModelBuildCommand());

return $application;
}
}
29 changes: 23 additions & 6 deletions src/FondOfCodeception/Module/Spryker.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use Exception;
use FondOfCodeception\Lib\DevelopmentFactory;
use FondOfCodeception\Lib\NullLoggerFactory;
use FondOfCodeception\Lib\PropelApplicationFactory;
use FondOfCodeception\Lib\PropelFacadeFactory;
use FondOfCodeception\Lib\SearchFacadeFactory;
use FondOfCodeception\Lib\TransferFacadeFactory;
use Psr\Log\LoggerInterface;
use Spryker\Shared\Config\Environment;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

class Spryker extends Module
{
Expand Down Expand Up @@ -49,6 +51,11 @@ class Spryker extends Module
*/
protected PropelFacadeFactory $propelFacadeFactory;

/**
* @var \FondOfCodeception\Lib\PropelApplicationFactory
*/
protected PropelApplicationFactory $propelApplicationFactory;

/**
* @var \Psr\Log\LoggerInterface|null
*/
Expand All @@ -70,6 +77,7 @@ public function __construct(ModuleContainer $moduleContainer, ?array $config = n
$this->nullLoggerFactory = new NullLoggerFactory();
$this->searchFacadeFactory = new SearchFacadeFactory($this->config);
$this->propelFacadeFactory = new PropelFacadeFactory();
$this->propelApplicationFactory = new PropelApplicationFactory();
$this->transferFacadeFactory = new TransferFacadeFactory();
$this->developmentFacadeFactory = new DevelopmentFactory($this->config);
}
Expand Down Expand Up @@ -106,6 +114,7 @@ public function _initialize()
protected function generatePropelClasses(): void
{
$propelFacade = $this->propelFacadeFactory->create();
$propelApplication = $this->propelApplicationFactory->create();

$this->debug('Deleting existing schema files...');
$propelFacade->cleanPropelSchemaDirectory();
Expand All @@ -119,14 +128,22 @@ protected function generatePropelClasses(): void
$configFile = APPLICATION_ROOT_DIR . '/propel.yml';
}

$modelBuildCommand = [APPLICATION_VENDOR_DIR . '/bin/propel', 'model:build', '--config-dir', $configFile];
$loaderScriptDirParams = ['--loader-script-dir', SprykerConstants::PROPEL_LOADER_SCRIPT_DIRECTORY];

$this->debug('Generating propel classes...');
try {
(new Process(array_merge($modelBuildCommand, $loaderScriptDirParams)))->mustRun();
$input = new ArrayInput([
'command' => 'model:build',
'--config-dir' => $configFile,
'--loader-script-dir' => SprykerConstants::PROPEL_LOADER_SCRIPT_DIRECTORY,
]);

$propelApplication->run($input, new NullOutput());
} catch (Exception $exception) {
(new Process($modelBuildCommand))->mustRun();
$input = new ArrayInput([
'command' => 'model:build',
'--config-dir' => $configFile,
]);

$propelApplication->run($input, new NullOutput());
}

if (!file_exists(SprykerConstants::PROPEL_LOADER_SCRIPT)) {
Expand Down
35 changes: 35 additions & 0 deletions tests/FondOfCodeception/Lib/PropelApplicationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace FondOfCodeception\Lib;

use Codeception\Test\Unit;
use Propel\Generator\Command\ModelBuildCommand;

class PropelApplicationFactoryTest extends Unit
{
/**
* @var \FondOfCodeception\Lib\PropelApplicationFactory
*/
protected $propelApplicationFactory;

/**
* @return void
*/
protected function _before(): void
{
parent::_before();

$this->propelApplicationFactory = new PropelApplicationFactory();
}

/**
* @return void
*/
public function testCreate(): void
{
$propelApplication = $this->propelApplicationFactory->create();

static::assertFalse($propelApplication->isAutoExitEnabled());
static::assertInstanceOf(ModelBuildCommand::class, $propelApplication->get('model:build'));
}
}
Loading