diff --git a/.gitignore b/.gitignore index ffe6ca2a..46624afd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,8 @@ composer.lock .DS_Store .php_cs.cache +/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/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php new file mode 100644 index 00000000..c60cb4f2 --- /dev/null +++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php @@ -0,0 +1,155 @@ +viewFactory = $viewFactory; + //add namespace for views + $this->viewFactory->addNamespace('atrauzzi', realpath(__DIR__ . '/templates/atrauzzi')); + $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); + $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); + + return $unescaped; + } + + 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) { + $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; + } + } + //only do this if all the same driver + if ($hasNamespaces && $sameDriver) { + $driver = $sourceArray['metadata'][0]['driver']; + + foreach ($sourceArray['metadata'] as $item) { + //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 { + 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 { + $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){ + $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('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(); + $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/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; 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..2f730ba1 --- /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..3022e8cd --- /dev/null +++ b/src/Console/ConfigMigrations/templates/atrauzzi/customTypes.blade.php @@ -0,0 +1,7 @@ +@if(isset($sourceArray['custom_types'])) + '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..07a759c5 --- /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/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' => [] +] 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 + ] ]; 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..55944e96 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) }}}', + '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' => [], diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php index 5076cf93..1db493b2 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,23 @@ 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(), storage_path() . '/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; + } } 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/Console/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php new file mode 100644 index 00000000..825914a7 --- /dev/null +++ b/tests/Console/Migrators/AtrauzziMigratorTest.php @@ -0,0 +1,36 @@ +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') + ]); + } +} + +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/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php new file mode 100644 index 00000000..ae504a1c --- /dev/null +++ b/tests/Console/Migrators/MitchellMigratorTest.php @@ -0,0 +1,36 @@ +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') + ]); + } +} + +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/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php new file mode 100644 index 00000000..6e0052b1 --- /dev/null +++ b/tests/Stubs/atrauzzi-config-sample.php @@ -0,0 +1,233 @@ + [ + + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Controller\\Entity', + 'alias' => 'Controller' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Operacoes\\Entity', + 'alias' => 'Operacoes' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Parametros\\Entity', + 'alias' => 'Parametros' + ], + [ + 'driver' => 'annotation', + 'namespace' => 'SysPRO\\Model\\Sistema\\Entity', + 'alias' => 'Sistema' + ] + + ], + /* + + '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' + ], + + ], + + ], +*/ + + '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' => 'array', + + 'file' => [ + 'directory' => '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..17780f3a --- /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_path() . '/proxies', + 'namespace' => null + ], + 'cache_provider' => null, +]; + diff --git a/tests/Stubs/storage/framework/views/.gitkeep b/tests/Stubs/storage/framework/views/.gitkeep new file mode 100644 index 00000000..e69de29b