From da05347ced34aadfea28b7de435b033853ec7001 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:15:42 -0400 Subject: [PATCH 01/13] Implement templates for Attrauzi config building --- .../templates/atrauzzi/cache.blade.php | 4 ++ .../templates/atrauzzi/customTypes.blade.php | 7 ++ .../templates/atrauzzi/dql.blade.php | 21 ++++++ .../master.blade.php | 65 +++++++++++++++---- 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php rename src/Console/ConfigMigrations/templates/{mitchell => laraveldoctrine}/master.blade.php (56%) diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php new file mode 100644 index 00000000..73ca37c1 --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php @@ -0,0 +1,4 @@ +[ + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\','.$cacheProvider.')'}}}, + 'second_level' => false, +], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php new file mode 100644 index 00000000..a81e3a38 --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -0,0 +1,7 @@ +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($sourceArray['custom_types']) !== null) + 'custom_types' => [ + @foreach($sourceArray['custom_Types'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif \ No newline at end of file diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php new file mode 100644 index 00000000..f02f69cf --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php @@ -0,0 +1,21 @@ +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_datetime_functions']) !== null) + 'custom_datetime_functions' => [ + @foreach($dql['custom_datetime_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_numeric_functions']) !== null) + 'custom_numeric_functions' => [ + @foreach($dql['custom_numeric_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif +@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_string_functions']) !== null) + 'custom_string_functions' => [ + @foreach($dql['custom_string_functions'] as $key => $val) + '{{$key}}' => '{{$val}}' + @endforeach + ], +@endif diff --git a/src/Console/ConfigMigrations/templates/mitchell/master.blade.php b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php similarity index 56% rename from src/Console/ConfigMigrations/templates/mitchell/master.blade.php rename to src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php index 54deb948..de6089bd 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/master.blade.php +++ b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php @@ -1,17 +1,20 @@ return [ /* |-------------------------------------------------------------------------- - | Development state + | Entity Mangers |-------------------------------------------------------------------------- | - | If set to false, metadata caching will become active + | Configure your Entity Managers here. You can set a different connection + | and driver per manager and configure events and filters. Change the + | paths setting to the appropriate path and replace App namespace + | by your own namespace. | - */ - 'dev' => config('app.debug'), - /* - |-------------------------------------------------------------------------- - | Entity Mangers - |-------------------------------------------------------------------------- + | Available meta drivers: annotations|yaml|xml|config|static_php + | + | Available connections: mysql|oracle|pgsql|sqlite|sqlsrv + | (Connections can be configured in the database config) + | + | --> Warning: Proxy auto generation should only be enabled in dev! | */ 'managers' => [ @@ -59,37 +62,73 @@ | | Enable/disable Doctrine Extensions by adding or removing them from the list | + | If you want to require custom extensions you will have to require + | laravel-doctrine/extensions in your composer.json + | */ 'extensions' => [ - //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, + //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, + //LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class, + //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class, + //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class, + //LaravelDoctrine\Extensions\Sortable\SortableExtension::class, + //LaravelDoctrine\Extensions\Tree\TreeExtension::class, + //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class, + //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class, + //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class, + //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class ], /* |-------------------------------------------------------------------------- | Doctrine custom types |-------------------------------------------------------------------------- */ + @if(isset($customTypes)) + {{$customTypes}} + @else 'custom_types' => [ 'json' => LaravelDoctrine\ORM\Types\Json::class ], + @endif @if($dqls !== null) {{$dqls}} @endif /* |-------------------------------------------------------------------------- - | Enable Debugbar Doctrine query collection + | Enable query logging with laravel file logging, + | debugbar, clockwork or an own implementation. + | Setting it to false, will disable logging + | + | Available: + | - LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger + | - LaravelDoctrine\ORM\Loggers\ClockworkLogger + | - LaravelDoctrine\ORM\Loggers\FileLogger |-------------------------------------------------------------------------- */ - 'debugbar' => env('DOCTRINE_DEBUGBAR', false), + 'logger' => env('DOCTRINE_LOGGER', false), /* |-------------------------------------------------------------------------- | Cache |-------------------------------------------------------------------------- | - | By default the Laravel cache setting is used, - | but it's possible to overrule here + | Configure meta-data, query and result caching here. + | Optionally you can enable second level caching. | | Available: acp|array|file|memcached|redis | */ {{$cache}} + /* + |-------------------------------------------------------------------------- + | Gedmo extensions + |-------------------------------------------------------------------------- + | + | Settings for Gedmo extensions + | If you want to use this you will have to require + | laravel-doctrine/extensions in your composer.json + | + */ + 'gedmo' => [ + 'all_mappings' => false + ] ]; From 89b3b2b57f92a570654cfa78a9a1f6632e27f785 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:16:31 -0400 Subject: [PATCH 02/13] Refactor some templates to use escaped single quotes Prevents code from being evaluated when it should just be output as text --- .../ConfigMigrations/templates/mitchell/cache.blade.php | 4 ++-- .../templates/mitchell/manager.blade.php | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php b/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php index 8ec6d8a5..2d5f3a9c 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/cache.blade.php @@ -1,4 +1,4 @@ [ - 'default' => {{{is_null($cacheProvider) ? 'config("cache.default")' : 'config("cache.'.$cacheProvider.'")'}}}, + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'config(\'cache.'.$cacheProvider.'\')'}}}, 'second_level' => false, -] +], diff --git a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php index 1f32c645..c7837313 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php @@ -1,12 +1,13 @@ [ - 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'annotations' }}}', - 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config("database.default")' }}}, + 'dev' => env('APP_DEBUG'), + 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'env(\'DOCTRINE_METADATA\', \'annotations\')' }}}', + 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config(\'database.default\')' }}}, 'paths' => {{ var_export(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['metadata']['paths'], $data['metadata']), true) }}, 'repository' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], \LaravelDoctrine\ORM\EntityRepository::class) }}}', 'proxies' => [ 'namespace' => {{{ isset($data['proxy']['namespace']) ? '\'' . $data['proxy']['namespace'] .'\'' : 'false' }}}, - 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], storage_path('proxies')) }}}', - 'auto_generate' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['auto_generate'], env('DOCTRINE_PROXY_AUTOGENERATE', 'false')) }}}' + 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], 'storage_path(\'proxies\')') }}}', + 'auto_generate' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['auto_generate'], 'env(\'DOCTRINE_PROXY_AUTOGENERATE\', \'false\')') }}}' ], 'events' => [ 'listeners' => [], From d2b539ea4d6ce7db79bd1d7ea66565733ae9a621 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:18:23 -0400 Subject: [PATCH 03/13] Refactor commands with right namespace (and for templates) * Use Console namespace for migrator classes * Refactor master tempalte into it's own namespace for better reuse --- .gitignore | 1 + src/Console/ConfigMigrations/ConfigurationMigrator.php | 2 +- src/Console/ConfigMigrations/MitchellMigrator.php | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ffe6ca2a..b65f6a06 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,6 @@ composer.lock .DS_Store .php_cs.cache +/tests/Stubs/storage .idea laravel-doctrine-orm.iml \ No newline at end of file diff --git a/src/Console/ConfigMigrations/ConfigurationMigrator.php b/src/Console/ConfigMigrations/ConfigurationMigrator.php index a59cddcd..18e04281 100644 --- a/src/Console/ConfigMigrations/ConfigurationMigrator.php +++ b/src/Console/ConfigMigrations/ConfigurationMigrator.php @@ -1,6 +1,6 @@ viewFactory = $viewFactory; //add namespace for views $this->viewFactory->addNamespace('mitchell', realpath(__DIR__ . '/templates/mitchell')); + $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } /** @@ -36,6 +37,7 @@ public function convertConfiguration($sourceArray) if ($isFork) { foreach ($sourceArray['entity_managers'] as $key => $manager) { + $manager['proxy'] = $sourceArray['proxy']; $managers[$key] = $this->convertManager($manager, $isFork); } } else { @@ -48,7 +50,7 @@ public function convertConfiguration($sourceArray) $cache = $this->convertCache($sourceArray); - $results = $this->viewFactory->make('mitchell.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render(); + $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); return $unescaped; From 30cefd0d3ae00bb514e66cbc8f663dac6462184d Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:19:05 -0400 Subject: [PATCH 04/13] Implement Atrauzzi config migrator --- .../ConfigMigrations/AtrauzziMigrator.php | 131 ++++++++++++++++++ src/Console/ConvertConfigCommand.php | 73 ++++++++-- 2 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 src/Console/ConfigMigrations/AtrauzziMigrator.php diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php new file mode 100644 index 00000000..27f633bb --- /dev/null +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -0,0 +1,131 @@ +viewFactory = $viewFactory; + //add namespace for views + $this->viewFactory->addNamespace('atruazzi', realpath(__DIR__ . '/templates/atruazzi')); + $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); + } + + /** + * Convert a configuration array from another laravel-doctrine project in to a string representation of a php array configuration for this project + * + * @param array $sourceArray + * @return string + */ + public function convertConfiguration($sourceArray) + { + $dqls = $this->convertDQL($sourceArray['entity_managers']); + $cache = $this->convertCache($sourceArray); + $customTypes = $this->convertCustomTypes($sourceArray); + + $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + + return $unescaped; + } + + public function convertManager($sourceArray) + { + $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); + $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); + + //non default configuration + if (count($sourceArray['metadata']) > 1) { + $isChained = false; + foreach ($sourceArray['metadata'] as $item) { + if (is_array($item)) { + $isChained = true; + } + } + //if it's chained we need to treat each chain as a separate EM + if ($isChained) { + foreach ($sourceArray['metadata'] as $item) { + //convert each chained metadata array EM + } + } //only specifying one non-default EM + else { + //convert metadata array to EM + } + } //one EM, default + else { + + } + } + + protected function getProxySettings($sourceArray) + { + if (isset($sourceArray['proxy_classes'])) { + return [ + 'auto_generate' => ArrayUtil::get($sourceArray['proxy_classes']['auto_generate']), + 'namespace' => ArrayUtil::get($sourceArray['proxy_classes']['namespace']), + 'path' => ArrayUtil::get($sourceArray['proxy_classes']['directory']) + ]; + } else { + return null; + } + } + + public function convertCustomTypes($sourceArray){ + $results = $this->viewFactory->make('atrauzzi.customTypes', ['sourceArray' => $sourceArray])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } + + /** + * Convert a cache section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for a cache section for this project + * + * @param array $sourceArray + * @return string + */ + public function convertCache($sourceArray) + { + if (isset($sourceArray['cache']['provider'])) { + $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); + $results = $this->viewFactory->make('atruazzi.cache', [ + 'cacheProvider' => $cacheProvider, + 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php + ])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } + return null; + + } + + /** + * Convert the dql sections from the entity managers in a configuration from atruazzi/laravel-doctrine into a string representation of a php array configuration for custom string/numeric/datetime functions + * + * Returns null if no dql sections were found. + * + * @param $sourceArray + * @return null|string + */ + public function convertDQL($sourceArray) + { + $results = $this->viewFactory->make('atrauzzi.dql', ['dql' => $sourceArray])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; + } +} \ No newline at end of file diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 5076cf93..a5b4537e 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -3,10 +3,22 @@ namespace LaravelDoctrine\ORM\Console; use Illuminate\Contracts\View\Factory; +use Illuminate\Filesystem\Filesystem as Filesystem; +use Illuminate\Events\Dispatcher; +use Illuminate\Container\Container as Container; +use Illuminate\Support\Facades\Input; +use Illuminate\View\Compilers\BladeCompiler; +use Illuminate\View\Engines\CompilerEngine; +use Illuminate\View\Engines\EngineResolver; +use Illuminate\View\FileViewFinder; use InvalidArgumentException; -use LaravelDoctrine\ORM\ConfigMigrations\MitchellMigrator; +use LaravelDoctrine\ORM\Console\ConfigMigrations\AtrauzziMigrator; +use LaravelDoctrine\ORM\Console\ConfigMigrations\MitchellMigrator; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; class ConvertConfigCommand extends Command { @@ -14,20 +26,32 @@ class ConvertConfigCommand extends Command protected $description = 'Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM.'; - public function fire(Factory $viewFactory) + protected function configure(){ + $this->setName('doctrine:config:convert') + ->setAliases(['doctrine:config:convert']) + ->setDescription('Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM') + ->setDefinition([ + new InputArgument('author', InputArgument::REQUIRED, 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'), + new InputOption('dest-path', null, InputOption::VALUE_OPTIONAL, 'Where the generated configuration should be placed', 'config'), + new InputOption('source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located.','config/doctrine.php') + ]); + } + + public function execute(InputInterface $input, OutputInterface $output) { + //add config templates directory to view locations - $viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); + //$viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates')); - if (($destPath = $this->option('dest-path')) === null) { + if (($destPath = $input->getOption('dest-path')) === null) { $destPath = 'config'; } - if (($author = $this->argument('author')) === null) { + if (($author = $input->getArgument('author')) === null) { throw new InvalidArgumentException('Missing author option'); } - if (($sourceFilePath = $this->option('source-file')) === null) { + if (($sourceFilePath = $input->getOption('source-file')) === null) { $sourceFilePath = 'config/doctrine.php'; } @@ -58,11 +82,13 @@ public function fire(Factory $viewFactory) $sourceArrayConfig = include $sourceFilePath; + $viewFactory = $this->createViewFactory(); + //TODO make this relative switch ($author) { case 'atrauzzi': - //$convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); + $convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory); break; case 'mitchellvanw': $convertedConfigString = $this->convertMitchell($sourceArrayConfig, $viewFactory); @@ -72,7 +98,7 @@ public function fire(Factory $viewFactory) } file_put_contents($destFilePath, 'info('Conversion successful. File generated at ' . $destFilePath); + $output->writeln('Conversion successful. File generated at ' . $destFilePath); } /** @@ -98,7 +124,9 @@ private function convertMitchell($sourceConfig, $viewFactory) */ private function convertAtrauzzi($sourceConfig, $viewFactory) { - //TODO + $aMigrator = new AtrauzziMigrator($viewFactory); + + return $aMigrator->convertConfiguration($sourceConfig); } public function getArguments() @@ -116,4 +144,31 @@ protected function getOptions() ['source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located. Default is config/doctrine.php', 'config/doctrine.php'] ]; } + + protected function createViewFactory(){ + $FileViewFinder = new FileViewFinder( + new Filesystem, + array(realpath(__DIR__ . '/ConfigMigrations/templates')) + ); + + $dispatcher = new Dispatcher(new Container); + + $compiler = new BladeCompiler(new Filesystem(), $this->getCachePath() . '/framework/views'); + $bladeEngine = new CompilerEngine($compiler); + $engineResolver = new EngineResolver(); + $engineResolver->register('blade', function() use(&$bladeEngine){ + return $bladeEngine; + }); + + $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); + return $viewFactory; + } + + protected function getCachePath(){ + if(!function_exists('storage_path')){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; + } else { + return storage_path(); + } + } } From fd8494b2c48d7d4fecd82d2ff69be0e93b7fc5ec Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 13:19:34 -0400 Subject: [PATCH 05/13] Implement tests for migrator commands * Include sample code files to run tests on --- .../Migrators/MitchellMigratorTest.php | 30 +++ tests/Stubs/atrauzzi-config-sample.php | 250 ++++++++++++++++++ tests/Stubs/mitchellvanw-config-sample.php | 39 +++ 3 files changed, 319 insertions(+) create mode 100644 tests/Configuration/Migrators/MitchellMigratorTest.php create mode 100644 tests/Stubs/atrauzzi-config-sample.php create mode 100644 tests/Stubs/mitchellvanw-config-sample.php diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php new file mode 100644 index 00000000..d10df5b7 --- /dev/null +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -0,0 +1,30 @@ +add($mitchellMigrator); + + $command = $application->find('doctrine:config:convert'); + + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'command' => $command->getName(), + 'author' => 'mitchellvanw', + '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'), + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + ]); + } +} \ No newline at end of file diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php new file mode 100644 index 00000000..6805770a --- /dev/null +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -0,0 +1,250 @@ + [ + + 'driver' => 'config', + + // + // Alternatively, if you want to use a chain, specify multiple drivers as nested arrays. + // + [ + 'driver' => 'config' + ], + [ + 'driver' => 'annotation', + // 'namespace' => 'App' + // 'alias' => 'DoctrineModel' + ], + [ + 'driver'=>'yaml', + ], + [ + 'driver'=>'xml' + ], + [ + 'driver'=>'static' + ] + // + // ...accepting PRs for more! + + ], + /* + + 'mappings' => [ + + 'App\MyModel' => [ + + 'table' => 'my_model', + + 'abstract' => false, + + 'repository' => 'App\Repository\MyModel', + + 'fields' => [ + + 'id' => [ + 'type' => 'integer', + 'strategy' => 'identity' + ], + + 'name' => [ + 'type' => 'string', + 'nullable' => false, + ] + + ], + + 'indexes' => [ + 'name' + ], + + ], + + ], +*/ + /* + * By default, this package mimics the database configuration from Laravel. + * + * You can override it in whole or in part here. The 'database' and 'username' + * laravel settings will be automatically converted to the proper doctrine 'dbname' + * and 'user' settings. Other custom laravel to doctrine mappings can be added on + * a per configuration basis by including a 'mappings' entry with 'laravel'=>'doctrine' + * mappings (see the sqlite configuration for an example). + * + * This array passes right through to the EntityManager factory. For + * example, here you can set additional connection details like "charset". + * + * http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html#connection-details + */ + 'connections' => [ + // Override your laravel environment database selection here if desired + // 'default' => 'mysql', + + // Override your laravel values here if desired. + /*'mysql' => [ + 'driver' => 'mysqli', + 'host' => env('DB_HOST', 'localhost'), + 'dbname' => env('DB_DATABASE', 'forge'), + 'user' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'prefix' => '' + ],*/ + + // Some preset configurations to map laravel sqlite configs to doctrine + 'sqlite' => [ + 'driver' => 'pdo_sqlite', + 'mappings' => [ + 'database' => 'path' + ] + ] + + + ], + + /* + | --------------------------------- + | By default, this package mimics the cache configuration from Laravel. + | + | You can create your own cache provider by extending the + | Atrauzzi\LaravelDoctrine\CacheProvider\CacheProvider class. + | + | Each provider requires a like named section with an array of configuration options. + | ---------------------------------- + */ + 'cache' => [ + // Remove or set to null for no cache + 'provider' => env('CACHE_DRIVER', 'array'), + + 'file' => [ + 'directory' => storage_path('framework/cache'), + 'extension' => '.doctrinecache.data' + ], + + 'redis' => [ + 'host' => '127.0.0.1', + 'port' => 6379, + 'database' => 1 + ], + + 'memcache' => [ + 'host' => '127.0.0.1', + 'port' => 11211 + ], + + 'providers' => [ + 'memcache' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcacheProvider::class, + 'memcached' => Atrauzzi\LaravelDoctrine\CacheProvider\MemcachedProvider::class, + 'couchbase' => Atrauzzi\LaravelDoctrine\CacheProvider\CouchbaseProvider::class, + 'redis' => Atrauzzi\LaravelDoctrine\CacheProvider\RedisProvider::class, + 'apc' => Atrauzzi\LaravelDoctrine\CacheProvider\ApcCacheProvider::class, + 'xcache' => Atrauzzi\LaravelDoctrine\CacheProvider\XcacheProvider::class, + 'array' => Atrauzzi\LaravelDoctrine\CacheProvider\ArrayCacheProvider::class, + 'file' => Atrauzzi\LaravelDoctrine\CacheProvider\FilesystemCacheProvider::class, + //'custom' => 'Path\To\Your\Class' + ] + ], + + + /* + |-------------------------------------------------------------------------- + | Sets the directory where Doctrine generates any proxy classes, including + | with which namespace. + |-------------------------------------------------------------------------- + | + | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html + | + */ + /* + 'proxy_classes' => [ + 'auto_generate' => false, + 'directory' => null, + 'namespace' => null, + ], + */ + + + 'migrations' => [ + 'directory' => '/database/doctrine-migrations', + 'namespace' => 'DoctrineMigrations', + 'table_name' => 'doctrine_migration_versions' + ], + + /* + |-------------------------------------------------------------------------- + | Use to specify the default repository + | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories + |-------------------------------------------------------------------------- + */ + /* + 'default_repository' => '\Doctrine\ORM\EntityRepository', + */ + + /* + |-------------------------------------------------------------------------- + | Use to specify the SQL Logger + | To use with \Doctrine\DBAL\Logging\EchoSQLLogger, do: + | 'sqlLogger' => new \Doctrine\DBAL\Logging\EchoSQLLogger(); + | + | http://doctrine-orm.readthedocs.org/en/latest/reference/advanced-configuration.html#sql-logger-optional + |-------------------------------------------------------------------------- + */ + /* + 'sql_logger' => null, + */ + + /* + * In some circumstances, you may wish to diverge from what's configured in Laravel. + */ + //'debug' => false, + + /* + | --------------------------------- + | Add custom Doctrine types here + | For more information: http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types + | --------------------------------- + */ + 'custom_types' => [ + 'json' => 'Atrauzzi\LaravelDoctrine\Type\Json' + ], + + 'custom_datetime_functions' => [ + 'DATEADD' => 'DoctrineExtensions\Query\Mysql\DateAdd', + 'DATEDIFF' => 'DoctrineExtensions\Query\Mysql\DateDiff', + 'DATESUB' => 'DoctrineExtensions\Query\Mysql\DateSub', + 'FROM_UNIXTIME' => 'DoctrineExtensions\Query\Mysql\FromUnixtime' + ], + + 'custom_numeric_functions' => [ + 'ACOS' => 'DoctrineExtensions\Query\Mysql\Acos', + 'ASIN' => 'DoctrineExtensions\Query\Mysql\Asin', + 'ATAN' => 'DoctrineExtensions\Query\Mysql\Atan', + 'ATAN2' => 'DoctrineExtensions\Query\Mysql\Atan2', + 'COS' => 'DoctrineExtensions\Query\Mysql\Cos', + 'COT' => 'DoctrineExtensions\Query\Mysql\Cot', + 'DEGREES' => 'DoctrineExtensions\Query\Mysql\Degrees', + 'RADIANS' => 'DoctrineExtensions\Query\Mysql\Radians', + 'SIN' => 'DoctrineExtensions\Query\Mysql\Sin', + 'TAN' => 'DoctrineExtensions\Query\Mysql\Tan' + ], + + 'custom_string_functions' => [ + 'CHAR_LENGTH' => 'DoctrineExtensions\Query\Mysql\CharLength', + 'CONCAT_WS' => 'DoctrineExtensions\Query\Mysql\ConcatWs', + 'FIELD' => 'DoctrineExtensions\Query\Mysql\Field', + 'FIND_IN_SET' => 'DoctrineExtensions\Query\Mysql\FindInSet', + 'REPLACE' => 'DoctrineExtensions\Query\Mysql\Replace', + 'SOUNDEX' => 'DoctrineExtensions\Query\Mysql\Soundex', + 'STR_TO_DATE' => 'DoctrineExtensions\Query\Mysql\StrToDate', + 'SUBSTRING_INDEX' => 'DoctrineExtensions\Query\Mysql\SubstringIndex' + ], + + 'auth' => [ + //'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator', + //'model' => 'App\Models\User', + ] + +]; diff --git a/tests/Stubs/mitchellvanw-config-sample.php b/tests/Stubs/mitchellvanw-config-sample.php new file mode 100644 index 00000000..fe67d882 --- /dev/null +++ b/tests/Stubs/mitchellvanw-config-sample.php @@ -0,0 +1,39 @@ + 'default', + 'entity_managers' => [ + 'default' => [ + 'connection' => 'sqlite', + 'cache_provider' => null, + 'repository' => 'Doctrine\ORM\EntityRepository', + 'simple_annotations' => false, + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', + 'extension' => '.dcm.yml' + ], + ], + 'production' => [ + 'connection' => 'mysql', + 'cache_provider' => 'file', + 'repository' => 'Doctrine\ORM\EntityRepository', + 'logger' => null, + 'metadata' => [ + 'simple' => false, + 'driver' => 'yaml', + 'paths' => 'app/Models/mappings', + 'extension' => '.dcm.yml' + ], + ], + ], + 'proxy' => [ + 'auto_generate' => true, + 'directory' => 'storage/proxies', + 'namespace' => null + ], + 'cache_provider' => null, +]; + From c60de73c4cd19f8939c23dc30504366b797a31c1 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:11:55 -0400 Subject: [PATCH 06/13] Modify config sample to include more options --- tests/Stubs/atrauzzi-config-sample.php | 57 +++++++++----------------- 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php index 6805770a..6e0052b1 100644 --- a/tests/Stubs/atrauzzi-config-sample.php +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -6,30 +6,26 @@ 'metadata' => [ - 'driver' => 'config', - - // - // Alternatively, if you want to use a chain, specify multiple drivers as nested arrays. - // - [ - 'driver' => 'config' - ], [ 'driver' => 'annotation', - // 'namespace' => 'App' - // 'alias' => 'DoctrineModel' + 'namespace' => 'SysPRO\\Model\\Controller\\Entity', + 'alias' => 'Controller' ], [ - 'driver'=>'yaml', + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Operacoes\\Entity', + 'alias' => 'Operacoes' ], [ - 'driver'=>'xml' + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Parametros\\Entity', + 'alias' => 'Parametros' ], [ - 'driver'=>'static' + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Sistema\\Entity', + 'alias' => 'Sistema' ] - // - // ...accepting PRs for more! ], /* @@ -66,20 +62,7 @@ ], */ - /* - * By default, this package mimics the database configuration from Laravel. - * - * You can override it in whole or in part here. The 'database' and 'username' - * laravel settings will be automatically converted to the proper doctrine 'dbname' - * and 'user' settings. Other custom laravel to doctrine mappings can be added on - * a per configuration basis by including a 'mappings' entry with 'laravel'=>'doctrine' - * mappings (see the sqlite configuration for an example). - * - * This array passes right through to the EntityManager factory. For - * example, here you can set additional connection details like "charset". - * - * http://doctrine-dbal.readthedocs.org/en/latest/reference/configuration.html#connection-details - */ + 'connections' => [ // Override your laravel environment database selection here if desired // 'default' => 'mysql', @@ -117,13 +100,13 @@ */ 'cache' => [ // Remove or set to null for no cache - 'provider' => env('CACHE_DRIVER', 'array'), + 'provider' => 'array', 'file' => [ - 'directory' => storage_path('framework/cache'), + 'directory' => 'framework/cache', 'extension' => '.doctrinecache.data' ], - + 'redis' => [ 'host' => '127.0.0.1', 'port' => 6379, @@ -158,13 +141,13 @@ | http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/configuration.html | */ - /* + 'proxy_classes' => [ 'auto_generate' => false, 'directory' => null, 'namespace' => null, ], - */ + 'migrations' => [ @@ -179,9 +162,9 @@ | http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html#custom-repositories |-------------------------------------------------------------------------- */ - /* + 'default_repository' => '\Doctrine\ORM\EntityRepository', - */ + /* |-------------------------------------------------------------------------- @@ -199,7 +182,7 @@ /* * In some circumstances, you may wish to diverge from what's configured in Laravel. */ - //'debug' => false, + 'debug' => false, /* | --------------------------------- From 21b162b7a85ca27fee89f5745d6adf520c37d759 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:12:31 -0400 Subject: [PATCH 07/13] Bug fixes and manager section implementation for atrauzzi migrator --- .../ConfigMigrations/AtrauzziMigrator.php | 76 ++++++++++++------- .../templates/atrauzzi/cache.blade.php | 2 +- .../templates/atrauzzi/customTypes.blade.php | 4 +- .../templates/atrauzzi/dql.blade.php | 6 +- .../templates/atrauzzi/manager.blade.php | 28 +++++++ 5 files changed, 84 insertions(+), 32 deletions(-) create mode 100644 src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php index 27f633bb..c60cb4f2 100644 --- a/src/Console/ConfigMigrations/AtrauzziMigrator.php +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -24,7 +24,7 @@ public function __construct(Factory $viewFactory) { $this->viewFactory = $viewFactory; //add namespace for views - $this->viewFactory->addNamespace('atruazzi', realpath(__DIR__ . '/templates/atruazzi')); + $this->viewFactory->addNamespace('atrauzzi', realpath(__DIR__ . '/templates/atrauzzi')); $this->viewFactory->addNamespace('laraveldoctrine', realpath(__DIR__ . '/templates/laraveldoctrine')); } @@ -36,9 +36,10 @@ public function __construct(Factory $viewFactory) */ public function convertConfiguration($sourceArray) { - $dqls = $this->convertDQL($sourceArray['entity_managers']); + $dqls = $this->convertDQL($sourceArray); $cache = $this->convertCache($sourceArray); $customTypes = $this->convertCustomTypes($sourceArray); + $managers = [$this->convertManager($sourceArray)]; $results = $this->viewFactory->make('laraveldoctrine.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls, 'customTypes' => $customTypes])->render(); $unescaped = html_entity_decode($results, ENT_QUOTES); @@ -50,41 +51,64 @@ public function convertManager($sourceArray) { $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']); $defaultRepo = ArrayUtil::get($sourceArray['default_repository']); + $namespaces = []; + $driver = null; + $connection = ArrayUtil::get($sourceArray['default']); //non default configuration if (count($sourceArray['metadata']) > 1) { - $isChained = false; - foreach ($sourceArray['metadata'] as $item) { - if (is_array($item)) { - $isChained = true; + $hasNamespaces = false; + $index = 0; + $driver = null; + $sameDriver = true; + + foreach ($sourceArray['metadata'] as $key => $item) { + //get first driver + if(is_null($driver)){ + if(is_array($item)){ + $driver = $item['driver']; + } else if($key == 'driver') { + $driver = $item; + } + + } else { + if(is_array($item) && $item['driver'] != $driver){ + $sameDriver = false; + } + } + if (is_array($item) && isset($item['namespace'])) { + $hasNamespaces = true; } } - //if it's chained we need to treat each chain as a separate EM - if ($isChained) { + //only do this if all the same driver + if ($hasNamespaces && $sameDriver) { + $driver = $sourceArray['metadata'][0]['driver']; + foreach ($sourceArray['metadata'] as $item) { - //convert each chained metadata array EM + //convert each metadata entry into a namespace entry + if(isset($item['alias'])){ + $namespaces[$item['alias']] = $item['namespace']; + } else{ + array_push($namespaces, $item['namespace']); + } } } //only specifying one non-default EM - else { - //convert metadata array to EM + else { + if(isset($sourceArray['metadata']['namespace'])){ + if(isset($sourceArray['metadata']['alias'])){ + $namespaces[$sourceArray['metadata']['alias']] = $sourceArray['metadata']['namespace']; + } else { + $namespaces[] = $sourceArray['metadata']['namespace']; + } + } } } //one EM, default else { - - } - } - - protected function getProxySettings($sourceArray) - { - if (isset($sourceArray['proxy_classes'])) { - return [ - 'auto_generate' => ArrayUtil::get($sourceArray['proxy_classes']['auto_generate']), - 'namespace' => ArrayUtil::get($sourceArray['proxy_classes']['namespace']), - 'path' => ArrayUtil::get($sourceArray['proxy_classes']['directory']) - ]; - } else { - return null; + $driver = $sourceArray['metadata']['driver']; } + $results = $this->viewFactory->make('atrauzzi.manager', ['namespaces' => $namespaces, 'proxySettings' => $proxySettings, 'defaultRepo' => $defaultRepo, 'driver' => $driver, 'connection' => $connection])->render(); + $unescaped = html_entity_decode($results, ENT_QUOTES); + return $unescaped; } public function convertCustomTypes($sourceArray){ @@ -103,7 +127,7 @@ public function convertCache($sourceArray) { if (isset($sourceArray['cache']['provider'])) { $cacheProvider = ArrayUtil::get($sourceArray['cache']['provider']); - $results = $this->viewFactory->make('atruazzi.cache', [ + $results = $this->viewFactory->make('atrauzzi.cache', [ 'cacheProvider' => $cacheProvider, 'extras' => count($sourceArray['cache']) > 1 //if user is mimicking cache arrays here we need to tell them to move these to cache.php ])->render(); diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php index 73ca37c1..2f730ba1 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/cache.blade.php @@ -1,4 +1,4 @@ [ - 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\','.$cacheProvider.')'}}}, + 'default' => {{{is_null($cacheProvider) ? 'env(\'DOCTRINE_CACHE\', \'array\')' : 'env(\'CACHE_DRIVER\',\''.$cacheProvider.'\')'}}}, 'second_level' => false, ], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php index a81e3a38..3022e8cd 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -1,6 +1,6 @@ -@if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($sourceArray['custom_types']) !== null) +@if(isset($sourceArray['custom_types'])) 'custom_types' => [ - @foreach($sourceArray['custom_Types'] as $key => $val) + @foreach($sourceArray['custom_types'] as $key => $val) '{{$key}}' => '{{$val}}' @endforeach ], diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php index f02f69cf..07a759c5 100644 --- a/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php +++ b/src/Console/ConfigMigrations/templates/atrauzzi/dql.blade.php @@ -1,21 +1,21 @@ @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_datetime_functions']) !== null) 'custom_datetime_functions' => [ @foreach($dql['custom_datetime_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_numeric_functions']) !== null) 'custom_numeric_functions' => [ @foreach($dql['custom_numeric_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif @if(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($dql['custom_string_functions']) !== null) 'custom_string_functions' => [ @foreach($dql['custom_string_functions'] as $key => $val) - '{{$key}}' => '{{$val}}' + '{{$key}}' => '{{$val}}', @endforeach ], @endif diff --git a/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php b/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php new file mode 100644 index 00000000..e03cd1af --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/manager.blade.php @@ -0,0 +1,28 @@ +[ + 'dev' => env('APP_DEBUG'), + 'meta' => env('DOCTRINE_METADATA', '{{$driver}}'), + 'connection' => {{{ $connection != null ? $connection : 'config(\'database.default\')' }}}, + @if(!empty($namespaces)) + 'namespaces' => [ + @foreach($namespaces as $key => $val) + '{{$key}}' => '{{$val}}', + @endforeach + ], + @endif + 'paths' => [app_path()], + @if($defaultRepo != null) + 'repository' => {{$defaultRepo}}::class, + @endif + @if($proxySettings != null) + 'proxies' => [ + 'namespace' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($proxySettings['namespace'],'false') }}}, + 'path' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['directory'], 'storage_path(\'proxies\')') }}}, + 'auto_generate' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['auto_generate'], 'env(\'DOCTRINE_PROXY_AUTOGENERATE\', \'false\')') }}} + ], + @endif + 'events' => [ + 'listeners' => [], + 'subscribers' => [] + ], + 'filters' => [] +] From ed5b266b9408621c5392e3d2471873c8bb364378 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:13:27 -0400 Subject: [PATCH 08/13] Bug fix on mitchell migrator when specifying a repository --- .../templates/mitchell/manager.blade.php | 2 +- .../Migrators/AtrauzziMigratorTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/Configuration/Migrators/AtrauzziMigratorTest.php diff --git a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php index c7837313..55944e96 100644 --- a/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php +++ b/src/Console/ConfigMigrations/templates/mitchell/manager.blade.php @@ -3,7 +3,7 @@ 'meta' => '{{{ $isFork ? $data['metadata']['driver'] : 'env(\'DOCTRINE_METADATA\', \'annotations\')' }}}', 'connection' => {{{ $isFork ? '\''.$data['connection'].'\'' : 'config(\'database.default\')' }}}, 'paths' => {{ var_export(\LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['metadata']['paths'], $data['metadata']), true) }}, - 'repository' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], \LaravelDoctrine\ORM\EntityRepository::class) }}}', + 'repository' => {{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['repository'], '\LaravelDoctrine\ORM\EntityRepository') }}}::class, 'proxies' => [ 'namespace' => {{{ isset($data['proxy']['namespace']) ? '\'' . $data['proxy']['namespace'] .'\'' : 'false' }}}, 'path' => '{{{ \LaravelDoctrine\ORM\Utilities\ArrayUtil::get($data['proxy']['directory'], 'storage_path(\'proxies\')') }}}', diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php new file mode 100644 index 00000000..4fb7a2c3 --- /dev/null +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -0,0 +1,30 @@ +add($mitchellMigrator); + + $command = $application->find('doctrine:config:convert'); + + $commandTester = new CommandTester($command); + $commandTester->execute([ + 'command' => $command->getName(), + 'author' => 'atrauzzi', + '--source-file' => realpath(__DIR__ . '/../../Stubs/atrauzzi-config-sample.php'), + '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') + ]); + } +} \ No newline at end of file From f665fe27445c6b7725002eb4b50198187c7987e3 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:22:47 -0400 Subject: [PATCH 09/13] Use storage_path variable included in tests --- src/Console/ConvertConfigCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index a5b4537e..d71d097c 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -168,7 +168,7 @@ protected function getCachePath(){ if(!function_exists('storage_path')){ return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; } else { - return storage_path(); + return storage_path(''); } } } From 12bca960d912c840dec6462cce81d1dade564c9a Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:36:37 -0400 Subject: [PATCH 10/13] Cleaner storage_path solution Thanks patrick --- src/Console/ConvertConfigCommand.php | 10 +--------- tests/Configuration/Migrators/AtrauzziMigratorTest.php | 4 ++++ tests/Configuration/Migrators/MitchellMigratorTest.php | 3 +++ tests/Stubs/mitchellvanw-config-sample.php | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index d71d097c..1db493b2 100644 --- a/src/Console/ConvertConfigCommand.php +++ b/src/Console/ConvertConfigCommand.php @@ -153,7 +153,7 @@ protected function createViewFactory(){ $dispatcher = new Dispatcher(new Container); - $compiler = new BladeCompiler(new Filesystem(), $this->getCachePath() . '/framework/views'); + $compiler = new BladeCompiler(new Filesystem(), storage_path() . '/framework/views'); $bladeEngine = new CompilerEngine($compiler); $engineResolver = new EngineResolver(); $engineResolver->register('blade', function() use(&$bladeEngine){ @@ -163,12 +163,4 @@ protected function createViewFactory(){ $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); return $viewFactory; } - - protected function getCachePath(){ - if(!function_exists('storage_path')){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../tests/Stubs/storage'; - } else { - return storage_path(''); - } - } } diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php index 4fb7a2c3..b438a96c 100644 --- a/tests/Configuration/Migrators/AtrauzziMigratorTest.php +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -27,4 +27,8 @@ public function test_convert_atrauzzi_config(){ '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } +} + +function storage_path(){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } \ No newline at end of file diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php index d10df5b7..5dc4c45e 100644 --- a/tests/Configuration/Migrators/MitchellMigratorTest.php +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -27,4 +27,7 @@ public function test_convert_mitchell_config(){ '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage') ]); } +} +function storage_path(){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; } \ No newline at end of file diff --git a/tests/Stubs/mitchellvanw-config-sample.php b/tests/Stubs/mitchellvanw-config-sample.php index fe67d882..17780f3a 100644 --- a/tests/Stubs/mitchellvanw-config-sample.php +++ b/tests/Stubs/mitchellvanw-config-sample.php @@ -31,7 +31,7 @@ ], 'proxy' => [ 'auto_generate' => true, - 'directory' => 'storage/proxies', + 'directory' => storage_path() . '/proxies', 'namespace' => null ], 'cache_provider' => null, From 81f28f793fcd37ea1def9f564edd2ca7a91f7527 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:49:17 -0400 Subject: [PATCH 11/13] storage_path where everyone plays nicely --- tests/Configuration/Cache/FileCacheProviderTest.php | 5 +++-- tests/Configuration/Migrators/AtrauzziMigratorTest.php | 6 ++++-- tests/Configuration/Migrators/MitchellMigratorTest.php | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/Configuration/Cache/FileCacheProviderTest.php b/tests/Configuration/Cache/FileCacheProviderTest.php index 4ea93532..8f4f8036 100644 --- a/tests/Configuration/Cache/FileCacheProviderTest.php +++ b/tests/Configuration/Cache/FileCacheProviderTest.php @@ -26,7 +26,8 @@ public function getExpectedInstance() } } -function storage_path($path) +function storage_path($path = null) { - return $path; + $storage = __DIR__ . DIRECTORY_SEPARATOR . '../../Stubs/storage'; + return is_null($path) ? $storage : $storage . DIRECTORY_SEPARATOR . $path; } diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Configuration/Migrators/AtrauzziMigratorTest.php index b438a96c..825914a7 100644 --- a/tests/Configuration/Migrators/AtrauzziMigratorTest.php +++ b/tests/Configuration/Migrators/AtrauzziMigratorTest.php @@ -29,6 +29,8 @@ public function test_convert_atrauzzi_config(){ } } -function storage_path(){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; +if(!function_exists('storage_path')){ + function storage_path($path = null){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + } } \ No newline at end of file diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Configuration/Migrators/MitchellMigratorTest.php index 5dc4c45e..ae504a1c 100644 --- a/tests/Configuration/Migrators/MitchellMigratorTest.php +++ b/tests/Configuration/Migrators/MitchellMigratorTest.php @@ -28,6 +28,9 @@ public function test_convert_mitchell_config(){ ]); } } -function storage_path(){ - return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + +if(!function_exists('storage_path')){ + function storage_path($path = null){ + return __DIR__ . DIRECTORY_SEPARATOR . '../../../tests/Stubs/storage'; + } } \ No newline at end of file From 05bcfa2abce382e1c538ce24d091d1354305f065 Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 14 Sep 2015 14:57:58 -0400 Subject: [PATCH 12/13] Update gitignore for cached files directory during tests --- .gitignore | 4 +++- tests/Stubs/storage/framework/views/.gitkeep | 0 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 tests/Stubs/storage/framework/views/.gitkeep diff --git a/.gitignore b/.gitignore index b65f6a06..46624afd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ composer.lock .DS_Store .php_cs.cache -/tests/Stubs/storage +/tests/Stubs/storage/framework/views/* +!/tests/Stubs/storage/framework/views/.gitkeep +/tests/Stubs/storage/doctrine.generated.php .idea laravel-doctrine-orm.iml \ No newline at end of file diff --git a/tests/Stubs/storage/framework/views/.gitkeep b/tests/Stubs/storage/framework/views/.gitkeep new file mode 100644 index 00000000..e69de29b From 466db27bf8f814bee03284d978e990332cee7371 Mon Sep 17 00:00:00 2001 From: Patrick Brouwers Date: Mon, 14 Sep 2015 23:36:55 +0200 Subject: [PATCH 13/13] Move migrator tests into Console folder --- .../{Configuration => Console}/Migrators/AtrauzziMigratorTest.php | 0 .../{Configuration => Console}/Migrators/MitchellMigratorTest.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/{Configuration => Console}/Migrators/AtrauzziMigratorTest.php (100%) rename tests/{Configuration => Console}/Migrators/MitchellMigratorTest.php (100%) diff --git a/tests/Configuration/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php similarity index 100% rename from tests/Configuration/Migrators/AtrauzziMigratorTest.php rename to tests/Console/Migrators/AtrauzziMigratorTest.php diff --git a/tests/Configuration/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php similarity index 100% rename from tests/Configuration/Migrators/MitchellMigratorTest.php rename to tests/Console/Migrators/MitchellMigratorTest.php