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/.php_cs b/.php_cs
index 3d34b8e3..c2489d19 100644
--- a/.php_cs
+++ b/.php_cs
@@ -8,7 +8,7 @@ return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array(
- 'psr0',
+ 'psr4',
'encoding',
'short_tag',
'blankline_after_open_tag',
diff --git a/.travis.yml b/.travis.yml
index f6aa7e5e..0b545901 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,6 +3,8 @@ language: php
php:
- 5.5
- 5.6
+ - 7.0
+ - hhvm
before_script:
- travis_retry composer self-update
@@ -12,6 +14,8 @@ after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
+sudo: false
+
script: phpunit --coverage-clover=coverage.clover
matrix:
diff --git a/README.md b/README.md
index e76343f1..8efed8f1 100644
--- a/README.md
+++ b/README.md
@@ -2,12 +2,12 @@
-[](https://packagist.org/packages/laravel-doctrine/orm)
-[](https://travis-ci.org/laravel-doctrine/orm)
-[](https://github.com/laravel-doctrine/orm)
-[](https://packagist.org/packages/laravel-doctrine/orm)
-[](https://packagist.org/packages/laravel-doctrine/orm)
-[](https://packagist.org/packages/laravel-doctrine/orm)
+[](https://packagist.org/packages/laravel-doctrine/orm)
+[](https://travis-ci.org/laravel-doctrine/orm)
+[](https://styleci.io/repos/39036008)
+[](https://github.com/laravel-doctrine/orm)
+[](https://packagist.org/packages/laravel-doctrine/orm)
+[](https://packagist.org/packages/laravel-doctrine/orm)
*A drop-in Doctrine ORM 2 implementation for Laravel 5+*
@@ -53,13 +53,13 @@ Require this package
After adding the package, add the ServiceProvider to the providers array in `config/app.php`
```php
-'LaravelDoctrine\ORM\DoctrineServiceProvider',
+LaravelDoctrine\ORM\DoctrineServiceProvider::class,
```
Optionally you can register the EntityManager facade:
```php
-'EntityManager' => 'LaravelDoctrine\ORM\Facades\EntityManager'
+'EntityManager' => LaravelDoctrine\ORM\Facades\EntityManager::class
```
To publish the config use:
diff --git a/composer.json b/composer.json
index 58248450..3a0f77bd 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,8 @@
"illuminate/pagination": "~5.1",
"illuminate/support": "~5.1",
"illuminate/validation": "~5.1",
- "illuminate/view": "~5.1"
+ "illuminate/view": "~5.1",
+ "symfony/serializer": "^2.7"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
@@ -46,6 +47,9 @@
]
},
"suggest": {
+ "laravel-doctrine/acl": "to integrate Doctrine roles & permissions with Laravel's Authorization system (~1.0)",
+ "laravel-doctrine/extensions": "to add Behavioral and Query/Type Extensions for Laravel Doctrine (~1.0)",
+ "laravel-doctrine/migrations": "to add support for migrations in Laravel Doctrine (~1.0)",
"yajra/laravel-oci8": "Support for Laravel native queue and session database drivers in Oracle (~2.0)."
}
}
diff --git a/src/Auth/Authenticatable.php b/src/Auth/Authenticatable.php
index f077ceac..34a93d4d 100644
--- a/src/Auth/Authenticatable.php
+++ b/src/Auth/Authenticatable.php
@@ -14,6 +14,15 @@ trait Authenticatable
*/
protected $rememberToken;
+ /**
+ * Get the column name for the primary key
+ * @return string
+ */
+ public function getAuthIdentifierName()
+ {
+ return 'id';
+ }
+
/**
* Get the unique identifier for the user.
* @return mixed
@@ -25,15 +34,6 @@ public function getAuthIdentifier()
return $this->{$name};
}
- /**
- * Get the column name for the primary key
- * @return string
- */
- public function getAuthIdentifierName()
- {
- return 'id';
- }
-
/**
* @return string
*/
diff --git a/src/Auth/CanResetPassword.php b/src/Auth/CanResetPassword.php
deleted file mode 100644
index b78efa84..00000000
--- a/src/Auth/CanResetPassword.php
+++ /dev/null
@@ -1,15 +0,0 @@
-email;
- }
-}
diff --git a/src/Auth/Passwords/PasswordResetServiceProvider.php b/src/Auth/Passwords/PasswordResetServiceProvider.php
index 41f2c904..02db3131 100644
--- a/src/Auth/Passwords/PasswordResetServiceProvider.php
+++ b/src/Auth/Passwords/PasswordResetServiceProvider.php
@@ -72,7 +72,7 @@ protected function registerTokenRepository()
return new DoctrineTokenRepository(
$this->app->make(ManagerRegistry::class)->getManagerForClass(PasswordReminder::class),
$app['config']['app.key'],
- $app['config']->get('auth.reminder.expire', 60)
+ $app['config']->get('auth.password.expire', 60)
);
});
}
diff --git a/src/Console/ConfigMigrations/AtrauzziMigrator.php b/src/Console/ConfigMigrations/AtrauzziMigrator.php
new file mode 100644
index 00000000..5703a4b8
--- /dev/null
+++ b/src/Console/ConfigMigrations/AtrauzziMigrator.php
@@ -0,0 +1,182 @@
+viewFactory = $viewFactory;
+ $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();
+
+ return $this->unescape($results);
+ }
+
+ /**
+ * @param $sourceArray
+ *
+ * @return string
+ */
+ public function convertManager($sourceArray)
+ {
+ $proxySettings = ArrayUtil::get($sourceArray['proxy_classes']);
+ $defaultRepo = ArrayUtil::get($sourceArray['default_repository']);
+ $namespaces = [];
+ $connection = ArrayUtil::get($sourceArray['default']);
+
+ // Non default configuration
+ if (count($sourceArray['metadata']) > 1) {
+ $hasNamespaces = false;
+ $driver = null;
+ $sameDriver = true;
+
+ foreach ($sourceArray['metadata'] as $key => $item) {
+ if (is_null($driver)) {
+ if (is_array($item)) {
+ $driver = $item['driver'];
+ } elseif ($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'];
+
+ // Convert each metadata entry into a namespace entry
+ foreach ($sourceArray['metadata'] as $item) {
+ 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();
+
+ return $this->unescape($results);
+ }
+
+ /**
+ * @param $sourceArray
+ *
+ * @return string
+ */
+ public function convertCustomTypes($sourceArray)
+ {
+ $results = $this->viewFactory->make('atrauzzi.customTypes', [
+ 'sourceArray' => $sourceArray
+ ])->render();
+
+ return $this->unescape($results);
+ }
+
+ /**
+ * 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();
+
+ return $this->unescape($results);
+ }
+
+ 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();
+
+ return $this->unescape($results);
+ }
+
+ /**
+ * @param $results
+ *
+ * @return string
+ */
+ protected function unescape($results)
+ {
+ return html_entity_decode($results, ENT_QUOTES);
+ }
+}
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'));
}
/**
* Convert a configuration array from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for this project
*
- * @param array $sourceArray
+ * @param array $sourceArray
+ *
* @return string
*/
public function convertConfiguration($sourceArray)
{
- //determine if configuration is from FoxxMD fork or original Mitchell repo
- $isFork = ArrayUtil::get($sourceArray['entity_managers']) !== null;
+ $isFork = $this->isFork($sourceArray);
$managers = [];
- $cache = '';
$dqls = null;
if ($isFork) {
foreach ($sourceArray['entity_managers'] as $key => $manager) {
- $managers[$key] = $this->convertManager($manager, $isFork);
+ $manager['proxy'] = $sourceArray['proxy'];
+ $managers[$key] = $this->convertManager($manager, $isFork);
}
} else {
$managers['default'] = $this->convertManager($sourceArray, $isFork);
@@ -46,10 +49,15 @@ public function convertConfiguration($sourceArray)
$dqls = $this->convertDQL($sourceArray['entity_managers']);
}
- $cache = $this->convertCache($sourceArray);
+ $cache = $this->convertCache($sourceArray);
+
+ $results = $this->viewFactory->make('laraveldoctrine.master', [
+ 'managers' => $managers,
+ 'cache' => $cache,
+ 'dqls' => $dqls
+ ])->render();
- $results = $this->viewFactory->make('mitchell.master', ['managers' => $managers, 'cache' => $cache, 'dqls' => $dqls])->render();
- $unescaped = html_entity_decode($results, ENT_QUOTES);
+ $unescaped = $this->unescape($results);
return $unescaped;
}
@@ -57,14 +65,19 @@ public function convertConfiguration($sourceArray)
/**
* Convert an entity manager section from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for an entity manager for this project
*
- * @param array $sourceArray
- * @param bool $isFork
+ * @param array $sourceArray
+ * @param bool $isFork
+ *
* @return string
*/
public function convertManager($sourceArray, $isFork)
{
- $results = $this->viewFactory->make('mitchell.manager', ['data' => $sourceArray, 'isFork' => $isFork])->render();
- $unescaped = html_entity_decode($results, ENT_QUOTES);
+ $results = $this->viewFactory->make('mitchell.manager', [
+ 'data' => $sourceArray,
+ 'isFork' => $isFork
+ ])->render();
+
+ $unescaped = $this->unescape($results);
return $unescaped;
}
@@ -72,24 +85,27 @@ public function convertManager($sourceArray, $isFork)
/**
* 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
+ * @param array $sourceArray
+ *
* @return string
*/
public function convertCache($sourceArray)
{
$cacheProvider = ArrayUtil::get($sourceArray['cache_provider']);
- $results = $this->viewFactory->make('mitchell.cache', ['cacheProvider' => $cacheProvider])->render();
- $unescaped = html_entity_decode($results, ENT_QUOTES);
- return $unescaped;
+ $results = $this->viewFactory->make('mitchell.cache', [
+ 'cacheProvider' => $cacheProvider
+ ])->render();
+
+ return $this->unescape($results);
}
/**
* Convert the dql sections from the entity managers in a configuration from foxxmd/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 $sourceManagers
+ *
* @return null|string
*/
public function convertDQL($sourceManagers)
@@ -110,12 +126,33 @@ public function convertDQL($sourceManagers)
}
if (!empty($dqls)) {
- $results = $this->viewFactory->make('mitchel.dql', ['dql' => $dqls])->render();
- $unescaped = html_entity_decode($results, ENT_QUOTES);
+ $results = $this->viewFactory->make('mitchel.dql', [
+ 'dql' => $dqls
+ ])->render();
- return $unescaped;
- } else {
- return null;
+ return $this->unescape($results);
}
}
+
+ /**
+ * @param $results
+ *
+ * @return string
+ */
+ protected function unescape($results)
+ {
+ return html_entity_decode($results, ENT_QUOTES);
+ }
+
+ /**
+ * Determine if configuration is from FoxxMD fork or original Mitchell repo
+ *
+ * @param $sourceArray
+ *
+ * @return bool
+ */
+ protected function isFork($sourceArray)
+ {
+ return ArrayUtil::get($sourceArray['entity_managers']) !== null;
+ }
}
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..90003f00
--- /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
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/laraveldoctrine/master.blade.php b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php
new file mode 100644
index 00000000..bf26bb47
--- /dev/null
+++ b/src/Console/ConfigMigrations/templates/laraveldoctrine/master.blade.php
@@ -0,0 +1,102 @@
+return [
+ /*
+ |--------------------------------------------------------------------------
+ | Entity Mangers
+ |--------------------------------------------------------------------------
+ |
+ | 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.
+ |
+ | 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' => [
+ @foreach($managers as $key => $manager)
+ '{{$key}}' => {{$manager}},
+ @endforeach
+
+ ],
+ /*
+ |--------------------------------------------------------------------------
+ | Doctrine Extensions
+ |--------------------------------------------------------------------------
+ |
+ | 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\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 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
+ |--------------------------------------------------------------------------
+ */
+ 'logger' => env('DOCTRINE_LOGGER', false),
+ /*
+ |--------------------------------------------------------------------------
+ | Cache
+ |--------------------------------------------------------------------------
+ |
+ | Configure meta-data, query and result caching here.
+ | Optionally you can enable second level caching.
+ |
+ | Available: acp|array|file|memcached|redis
+ |
+ */
+ 'cache' => {{$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/ConfigMigrations/templates/mitchell/master.blade.php b/src/Console/ConfigMigrations/templates/mitchell/master.blade.php
deleted file mode 100644
index 54deb948..00000000
--- a/src/Console/ConfigMigrations/templates/mitchell/master.blade.php
+++ /dev/null
@@ -1,95 +0,0 @@
-return [
- /*
- |--------------------------------------------------------------------------
- | Development state
- |--------------------------------------------------------------------------
- |
- | If set to false, metadata caching will become active
- |
- */
- 'dev' => config('app.debug'),
- /*
- |--------------------------------------------------------------------------
- | Entity Mangers
- |--------------------------------------------------------------------------
- |
- */
- 'managers' => [
- @foreach($managers as $key => $manager)
- '{{$key}}' => {{$manager}},
- @endforeach
-
- ],
- /*
- |--------------------------------------------------------------------------
- | Doctrine Meta Data
- |--------------------------------------------------------------------------
- |
- | Available: annotations|yaml|xml
- |
- */
- 'meta' => [
- 'namespaces' => [
- 'App'
- ],
- 'drivers' => [
- 'annotations' => [
- 'driver' => 'annotations',
- 'simple' => false
- ],
- 'yaml' => [
- 'driver' => 'yaml'
- ],
- 'xml' => [
- 'driver' => 'xml'
- ],
- 'config' => [
- 'driver' => 'config',
- 'mapping_file' => 'mappings'
- ],
- 'static_php' => [
- 'driver' => 'static_php'
- ]
- ]
- ],
- /*
- |--------------------------------------------------------------------------
- | Doctrine Extensions
- |--------------------------------------------------------------------------
- |
- | Enable/disable Doctrine Extensions by adding or removing them from the list
- |
- */
- 'extensions' => [
- //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
- ],
- /*
- |--------------------------------------------------------------------------
- | Doctrine custom types
- |--------------------------------------------------------------------------
- */
- 'custom_types' => [
- 'json' => LaravelDoctrine\ORM\Types\Json::class
- ],
- @if($dqls !== null)
- {{$dqls}}
- @endif
- /*
- |--------------------------------------------------------------------------
- | Enable Debugbar Doctrine query collection
- |--------------------------------------------------------------------------
- */
- 'debugbar' => env('DOCTRINE_DEBUGBAR', false),
- /*
- |--------------------------------------------------------------------------
- | Cache
- |--------------------------------------------------------------------------
- |
- | By default the Laravel cache setting is used,
- | but it's possible to overrule here
- |
- | Available: acp|array|file|memcached|redis
- |
- */
- {{$cache}}
-];
diff --git a/src/Console/ConvertConfigCommand.php b/src/Console/ConvertConfigCommand.php
index 5076cf93..e7336a16 100644
--- a/src/Console/ConvertConfigCommand.php
+++ b/src/Console/ConvertConfigCommand.php
@@ -2,32 +2,67 @@
namespace LaravelDoctrine\ORM\Console;
-use Illuminate\Contracts\View\Factory;
+use Illuminate\Container\Container as Container;
+use Illuminate\Events\Dispatcher;
+use Illuminate\Filesystem\Filesystem as Filesystem;
+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 Symfony\Component\Console\Command\Command as SymfonyCommand;
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
+class ConvertConfigCommand extends SymfonyCommand
{
+ /**
+ * @var string
+ */
protected $name = 'doctrine:config:convert';
+ /**
+ * @var string
+ */
protected $description = 'Convert the configuration file for another laravel-doctrine implementation into a valid configuration for LaravelDoctrine\ORM.';
- public function fire(Factory $viewFactory)
+ /**
+ * Configure the command
+ */
+ protected function configure()
{
- //add config templates directory to view locations
- $viewFactory->addLocation(realpath(__DIR__ . '/ConfigMigrations/templates'));
+ $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')
+ ]);
+ }
- if (($destPath = $this->option('dest-path')) === null) {
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null|void
+ */
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ 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,62 +93,43 @@ public function fire(Factory $viewFactory)
$sourceArrayConfig = include $sourceFilePath;
- //TODO make this relative
-
- switch ($author) {
- case 'atrauzzi':
- //$convertedConfigString = $this->convertAtrauzzi($sourceArrayConfig, $viewFactory);
- break;
- case 'mitchellvanw':
- $convertedConfigString = $this->convertMitchell($sourceArrayConfig, $viewFactory);
- break;
- default:
- throw new InvalidArgumentException('Author provided was not a valid choice.');
+ $viewFactory = $this->createViewFactory();
+
+ $className = __NAMESPACE__ . '\ConfigMigrations\\' . ucfirst($author) . 'Migrator';
+
+ if (!class_exists($className)) {
+ throw new InvalidArgumentException('Author provided was not a valid choice.');
+ } else {
+ $configMigrator = new $className($viewFactory);
+ $convertedConfigString = $configMigrator->convertConfiguration($sourceArrayConfig);
}
file_put_contents($destFilePath, 'info('Conversion successful. File generated at ' . $destFilePath);
- }
-
- /**
- * Convert a configuration file from mitchellvanw/laravel-doctrine to a string representation of a php array configuration for this project
- *
- * @param array $sourceConfig
- * @param Factory $viewFactory
- * @return string
- */
- private function convertMitchell($sourceConfig, $viewFactory)
- {
- $mMigrator = new MitchellMigrator($viewFactory);
- return $mMigrator->convertConfiguration($sourceConfig);
+ $output->writeln('Conversion successful. File generated at ' . $destFilePath);
}
/**
- * Convert a configuration file from atrauzzi/laravel-doctrine to a string representation of a php array configuration for this project
- *
- * @param array $sourceConfig
- * @param Factory $viewFactory
- * @return string
+ * @return \Illuminate\View\Factory
*/
- private function convertAtrauzzi($sourceConfig, $viewFactory)
+ protected function createViewFactory()
{
- //TODO
- }
+ $FileViewFinder = new FileViewFinder(
+ new Filesystem,
+ [realpath(__DIR__ . '/ConfigMigrations/templates')]
+ );
- public function getArguments()
- {
- return [
- ['author', InputArgument::REQUIRED, 'The name of the author of the repository being migrated from. Options are "atrauzzi" and "mitchellvanw"'],
+ $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;
+ });
- protected function getOptions()
- {
- return [
- ['dest-path', null, InputOption::VALUE_OPTIONAL, 'Where the generated configuration should be placed. Default is config.', 'config'],
- ['source-file', null, InputOption::VALUE_OPTIONAL, 'Where the source configuration file is located. Default is config/doctrine.php', 'config/doctrine.php']
- ];
+ $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher);
+
+ return $viewFactory;
}
}
diff --git a/src/DoctrineServiceProvider.php b/src/DoctrineServiceProvider.php
index cc6406bc..9a1dbf8c 100644
--- a/src/DoctrineServiceProvider.php
+++ b/src/DoctrineServiceProvider.php
@@ -93,17 +93,9 @@ protected function mergeConfig()
*/
protected function registerEntityManager()
{
- $registry = $this->app->make('registry');
-
- // Add all managers into the registry
- foreach ($this->app->make('config')->get('doctrine.managers', []) as $manager => $settings) {
- $registry->addManager($manager, $settings);
- $registry->addConnection($manager);
- }
-
// Bind the default Entity Manager
- $this->app->singleton('em', function () use ($registry) {
- return $registry->getManager();
+ $this->app->singleton('em', function ($app) {
+ return $app->make('registry')->getManager();
});
$this->app->alias('em', EntityManager::class);
@@ -115,9 +107,21 @@ protected function registerEntityManager()
*/
protected function registerManagerRegistry()
{
- $this->app->singleton('registry', IlluminateRegistry::class);
- $this->app->alias('registry', ManagerRegistry::class);
+ $this->app->singleton('registry', function ($app) {
+
+ $registry = new IlluminateRegistry($app, $app->make(EntityManagerFactory::class));
+
+ // Add all managers into the registry
+ foreach ($app->make('config')->get('doctrine.managers', []) as $manager => $settings) {
+ $registry->addManager($manager, $settings);
+ $registry->addConnection($manager);
+ }
+
+ return $registry;
+ });
+
$this->app->alias('registry', ManagerRegistry::class);
+ $this->app->alias('registry', IlluminateRegistry::class);
}
/**
@@ -263,6 +267,9 @@ public function provides()
AuthManager::class,
EntityManager::class,
DoctrineManager::class,
+ ConnectionManager::class,
+ CacheManager::class,
+ MetaDataManager::class,
ClassMetadataFactory::class,
EntityManagerInterface::class,
ExtensionManager::class,
diff --git a/src/IlluminateRegistry.php b/src/IlluminateRegistry.php
index 3fd53c81..76e65393 100644
--- a/src/IlluminateRegistry.php
+++ b/src/IlluminateRegistry.php
@@ -67,11 +67,13 @@ public function __construct(Container $container, EntityManagerFactory $factory)
*/
public function addManager($manager, array $settings = [])
{
- $this->container->singleton($this->getManagerBindingName($manager), function () use ($settings) {
- return $this->factory->create($settings);
- });
+ if (!$this->container->bound($this->getManagerBindingName($manager))) {
+ $this->container->singleton($this->getManagerBindingName($manager), function () use ($settings) {
+ return $this->factory->create($settings);
+ });
- $this->managers[$manager] = $manager;
+ $this->managers[$manager] = $manager;
+ }
}
/**
@@ -79,11 +81,13 @@ public function addManager($manager, array $settings = [])
*/
public function addConnection($connection)
{
- $this->container->singleton($this->getConnectionBindingName($connection), function () use ($connection) {
- return $this->getManager($connection)->getConnection();
- });
+ if (!$this->container->bound($this->getConnectionBindingName($connection))) {
+ $this->container->singleton($this->getConnectionBindingName($connection), function () use ($connection) {
+ return $this->getManager($connection)->getConnection();
+ });
- $this->connections[$connection] = $connection;
+ $this->connections[$connection] = $connection;
+ }
}
/**
diff --git a/src/Loggers/Debugbar/DoctrineCollector.php b/src/Loggers/Debugbar/DoctrineCollector.php
new file mode 100644
index 00000000..42e6b208
--- /dev/null
+++ b/src/Loggers/Debugbar/DoctrineCollector.php
@@ -0,0 +1,22 @@
+debugStack;
+ }
+}
diff --git a/src/Loggers/LaravelDebugbarLogger.php b/src/Loggers/LaravelDebugbarLogger.php
index 6e47aea7..d6655ed8 100644
--- a/src/Loggers/LaravelDebugbarLogger.php
+++ b/src/Loggers/LaravelDebugbarLogger.php
@@ -3,10 +3,10 @@
namespace LaravelDoctrine\ORM\Loggers;
use Barryvdh\Debugbar\LaravelDebugbar;
-use DebugBar\Bridge\DoctrineCollector;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
+use LaravelDoctrine\ORM\Loggers\Debugbar\DoctrineCollector;
class LaravelDebugbarLogger implements Logger
{
@@ -29,10 +29,16 @@ public function __construct(LaravelDebugbar $debugbar)
*/
public function register(EntityManagerInterface $em, Configuration $configuration)
{
- $debugStack = new DebugStack;
+ if ($this->debugbar->hasCollector('doctrine')) {
+ $debugStack = $this->debugbar->getCollector('doctrine')->getDebugStack();
+ } else {
+ $debugStack = new DebugStack;
+
+ $this->debugbar->addCollector(
+ new DoctrineCollector($debugStack)
+ );
+ }
+
$configuration->setSQLLogger($debugStack);
- $this->debugbar->addCollector(
- new DoctrineCollector($debugStack)
- );
}
}
diff --git a/src/Serializers/ArrayEncoder.php b/src/Serializers/ArrayEncoder.php
new file mode 100644
index 00000000..a6231e79
--- /dev/null
+++ b/src/Serializers/ArrayEncoder.php
@@ -0,0 +1,46 @@
+serializer = new Serializer([$this->getNormalizer()], [
+ 'array' => $this->getEncoder(),
+ ]);
+ }
+
+ /**
+ * @param $entity
+ *
+ * @return string
+ */
+ public function serialize($entity)
+ {
+ return $this->serializer->serialize($entity, 'array');
+ }
+
+ /**
+ * @return GetSetMethodNormalizer
+ */
+ protected function getNormalizer()
+ {
+ return new GetSetMethodNormalizer;
+ }
+
+ /**
+ * @return JsonEncoder
+ */
+ protected function getEncoder()
+ {
+ return new ArrayEncoder;
+ }
+}
diff --git a/src/Serializers/Arrayable.php b/src/Serializers/Arrayable.php
new file mode 100644
index 00000000..4200cd7c
--- /dev/null
+++ b/src/Serializers/Arrayable.php
@@ -0,0 +1,14 @@
+serialize($this);
+ }
+}
diff --git a/src/Serializers/JsonSerializer.php b/src/Serializers/JsonSerializer.php
new file mode 100644
index 00000000..05c7ce6b
--- /dev/null
+++ b/src/Serializers/JsonSerializer.php
@@ -0,0 +1,51 @@
+serializer = new Serializer([$this->getNormalizer()], [
+ 'json' => $this->getEncoder(),
+ ]);
+ }
+
+ /**
+ * @param $entity
+ *
+ * @return string
+ */
+ public function serialize($entity)
+ {
+ return $this->serializer->serialize($entity, 'json');
+ }
+
+ /**
+ * @return GetSetMethodNormalizer
+ */
+ protected function getNormalizer()
+ {
+ return new GetSetMethodNormalizer;
+ }
+
+ /**
+ * @return JsonEncoder
+ */
+ protected function getEncoder()
+ {
+ return new JsonEncoder;
+ }
+}
diff --git a/src/Serializers/Jsonable.php b/src/Serializers/Jsonable.php
new file mode 100644
index 00000000..aa50729f
--- /dev/null
+++ b/src/Serializers/Jsonable.php
@@ -0,0 +1,26 @@
+serialize($this);
+ }
+
+ /**
+ * Specify data which should be serialized to JSON
+ * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
+ * @return mixed data which can be serialized by json_encode,
+ * which is a value of any type other than a resource.
+ * @since 5.4.0
+ */
+ public function jsonSerialize()
+ {
+ return (new ArraySerializer)->serialize($this);
+ }
+}
diff --git a/tests/Configuration/Cache/FileCacheProviderTest.php b/tests/Configuration/Cache/FileCacheProviderTest.php
index 4ea93532..bff84632 100644
--- a/tests/Configuration/Cache/FileCacheProviderTest.php
+++ b/tests/Configuration/Cache/FileCacheProviderTest.php
@@ -26,7 +26,9 @@ 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/Connections/MysqlConnectionTest.php b/tests/Configuration/Connections/MysqlConnectionTest.php
index bc1e8ba4..b2835c03 100644
--- a/tests/Configuration/Connections/MysqlConnectionTest.php
+++ b/tests/Configuration/Connections/MysqlConnectionTest.php
@@ -37,15 +37,15 @@ public function test_can_resolve()
$resolved = $this->connection->resolve();
- $this->assertEquals('pdo_mysql', $resolved['driver']);
- $this->assertEquals('host', $resolved['host']);
- $this->assertEquals('database', $resolved['dbname']);
- $this->assertEquals('username', $resolved['user']);
- $this->assertEquals('password', $resolved['password']);
- $this->assertEquals('charset', $resolved['charset']);
- $this->assertEquals('port', $resolved['port']);
- $this->assertEquals('unix_socket', $resolved['unix_socket']);
- $this->assertEquals('prefix', $resolved['prefix']);
+ $this->assertEquals('pdo_mysql', $resolved['driver']);
+ $this->assertEquals('host', $resolved['host']);
+ $this->assertEquals('database', $resolved['dbname']);
+ $this->assertEquals('username', $resolved['user']);
+ $this->assertEquals('password', $resolved['password']);
+ $this->assertEquals('charset', $resolved['charset']);
+ $this->assertEquals('port', $resolved['port']);
+ $this->assertEquals('unix_socket', $resolved['unix_socket']);
+ $this->assertEquals('prefix', $resolved['prefix']);
}
protected function tearDown()
diff --git a/tests/Configuration/Connections/OracleConnectionTest.php b/tests/Configuration/Connections/OracleConnectionTest.php
index 99b26c70..895f8c2a 100644
--- a/tests/Configuration/Connections/OracleConnectionTest.php
+++ b/tests/Configuration/Connections/OracleConnectionTest.php
@@ -36,14 +36,14 @@ public function test_can_resolve()
$resolved = $this->connection->resolve();
- $this->assertEquals('oci8', $resolved['driver']);
- $this->assertEquals('host', $resolved['host']);
- $this->assertEquals('database', $resolved['dbname']);
- $this->assertEquals('username', $resolved['user']);
- $this->assertEquals('password', $resolved['password']);
- $this->assertEquals('charset', $resolved['charset']);
- $this->assertEquals('port', $resolved['port']);
- $this->assertEquals('prefix', $resolved['prefix']);
+ $this->assertEquals('oci8', $resolved['driver']);
+ $this->assertEquals('host', $resolved['host']);
+ $this->assertEquals('database', $resolved['dbname']);
+ $this->assertEquals('username', $resolved['user']);
+ $this->assertEquals('password', $resolved['password']);
+ $this->assertEquals('charset', $resolved['charset']);
+ $this->assertEquals('port', $resolved['port']);
+ $this->assertEquals('prefix', $resolved['prefix']);
}
protected function tearDown()
diff --git a/tests/Configuration/Connections/PgsqlConnectionTest.php b/tests/Configuration/Connections/PgsqlConnectionTest.php
index a3ffae4a..30d77c00 100644
--- a/tests/Configuration/Connections/PgsqlConnectionTest.php
+++ b/tests/Configuration/Connections/PgsqlConnectionTest.php
@@ -37,15 +37,15 @@ public function test_can_resolve()
$resolved = $this->connection->resolve();
- $this->assertEquals('pdo_pgsql', $resolved['driver']);
- $this->assertEquals('host', $resolved['host']);
- $this->assertEquals('database', $resolved['dbname']);
- $this->assertEquals('username', $resolved['user']);
- $this->assertEquals('password', $resolved['password']);
- $this->assertEquals('charset', $resolved['charset']);
- $this->assertEquals('port', $resolved['port']);
- $this->assertEquals('sslmode', $resolved['sslmode']);
- $this->assertEquals('prefix', $resolved['prefix']);
+ $this->assertEquals('pdo_pgsql', $resolved['driver']);
+ $this->assertEquals('host', $resolved['host']);
+ $this->assertEquals('database', $resolved['dbname']);
+ $this->assertEquals('username', $resolved['user']);
+ $this->assertEquals('password', $resolved['password']);
+ $this->assertEquals('charset', $resolved['charset']);
+ $this->assertEquals('port', $resolved['port']);
+ $this->assertEquals('sslmode', $resolved['sslmode']);
+ $this->assertEquals('prefix', $resolved['prefix']);
}
protected function tearDown()
diff --git a/tests/Configuration/Connections/SqlsrvConnectionTest.php b/tests/Configuration/Connections/SqlsrvConnectionTest.php
index e8ac2cb8..796d1c6c 100644
--- a/tests/Configuration/Connections/SqlsrvConnectionTest.php
+++ b/tests/Configuration/Connections/SqlsrvConnectionTest.php
@@ -35,13 +35,13 @@ public function test_can_resolve()
$resolved = $this->connection->resolve();
- $this->assertEquals('pdo_sqlsrv', $resolved['driver']);
- $this->assertEquals('host', $resolved['host']);
- $this->assertEquals('database', $resolved['dbname']);
- $this->assertEquals('username', $resolved['user']);
- $this->assertEquals('password', $resolved['password']);
- $this->assertEquals('port', $resolved['port']);
- $this->assertEquals('prefix', $resolved['prefix']);
+ $this->assertEquals('pdo_sqlsrv', $resolved['driver']);
+ $this->assertEquals('host', $resolved['host']);
+ $this->assertEquals('database', $resolved['dbname']);
+ $this->assertEquals('username', $resolved['user']);
+ $this->assertEquals('password', $resolved['password']);
+ $this->assertEquals('port', $resolved['port']);
+ $this->assertEquals('prefix', $resolved['prefix']);
}
protected function tearDown()
diff --git a/tests/Console/Migrators/AtrauzziMigratorTest.php b/tests/Console/Migrators/AtrauzziMigratorTest.php
new file mode 100644
index 00000000..b7f3d50e
--- /dev/null
+++ b/tests/Console/Migrators/AtrauzziMigratorTest.php
@@ -0,0 +1,26 @@
+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')
+ ]);
+
+ $this->sanityCheck();
+ }
+}
diff --git a/tests/Console/Migrators/MigratorBase.php b/tests/Console/Migrators/MigratorBase.php
new file mode 100644
index 00000000..ee502199
--- /dev/null
+++ b/tests/Console/Migrators/MigratorBase.php
@@ -0,0 +1,48 @@
+assertFileExists(__DIR__ . '/../../Stubs/storage/doctrine.generated.php');
+
+ $generatedConfig = include __DIR__ . '/../../Stubs/storage/doctrine.generated.php';
+
+ //assert at least one manager is present
+ $this->assertArrayHasKey('managers', $generatedConfig);
+ $this->assertTrue(count($generatedConfig['managers']) > 0);
+ }
+}
diff --git a/tests/Console/Migrators/MitchellMigratorTest.php b/tests/Console/Migrators/MitchellMigratorTest.php
new file mode 100644
index 00000000..7db917f9
--- /dev/null
+++ b/tests/Console/Migrators/MitchellMigratorTest.php
@@ -0,0 +1,26 @@
+add($mitchellMigrator);
+
+ $command = $application->find('doctrine:config:convert');
+
+ $commandTester = new CommandTester($command);
+ $commandTester->execute([
+ 'command' => $command->getName(),
+ 'author' => 'mitchell',
+ '--source-file' => realpath(__DIR__ . '/../../Stubs/mitchellvanw-config-sample.php'),
+ '--dest-path' => realpath(__DIR__ . '/../../Stubs/storage')
+ ]);
+
+ $this->sanityCheck();
+ }
+}
diff --git a/tests/Extensions/MappingDriverChainTest.php b/tests/Extensions/MappingDriverChainTest.php
index 83e3990f..5b0341ea 100644
--- a/tests/Extensions/MappingDriverChainTest.php
+++ b/tests/Extensions/MappingDriverChainTest.php
@@ -34,10 +34,10 @@ public function test_can_add_namespace()
$this->chain->addNamespace('NewNamespace2');
$this->chain->addNamespace('NewNamespace3');
- $this->assertArrayHasKey('Namespace', $this->chain->getDrivers());
- $this->assertArrayHasKey('NewNamespace', $this->chain->getDrivers());
- $this->assertArrayHasKey('NewNamespace2', $this->chain->getDrivers());
- $this->assertArrayHasKey('NewNamespace3', $this->chain->getDrivers());
+ $this->assertArrayHasKey('Namespace', $this->chain->getDrivers());
+ $this->assertArrayHasKey('NewNamespace', $this->chain->getDrivers());
+ $this->assertArrayHasKey('NewNamespace2', $this->chain->getDrivers());
+ $this->assertArrayHasKey('NewNamespace3', $this->chain->getDrivers());
$this->assertArrayNotHasKey('NonExisting', $this->chain->getDrivers());
}
diff --git a/tests/IlluminateRegistryTest.php b/tests/IlluminateRegistryTest.php
index d53e27f4..a365538f 100644
--- a/tests/IlluminateRegistryTest.php
+++ b/tests/IlluminateRegistryTest.php
@@ -29,6 +29,7 @@ class IlluminateRegistryTest extends PHPUnit_Framework_TestCase
protected function setUp()
{
$this->container = m::mock(Container::class);
+ $this->container->shouldReceive('bound')->andReturn(false);
$this->factory = m::mock(EntityManagerFactory::class);
$this->registry = new IlluminateRegistry(
diff --git a/tests/Loggers/Formatters/ReplaceQueryParamsTest.php b/tests/Loggers/Formatters/ReplaceQueryParamsTest.php
index e2bde351..93356427 100644
--- a/tests/Loggers/Formatters/ReplaceQueryParamsTest.php
+++ b/tests/Loggers/Formatters/ReplaceQueryParamsTest.php
@@ -41,11 +41,11 @@ public function test_cannot_replace_object_params_without__toString()
{
$this->setExpectedException(
Exception::class,
- 'Given query param is an instance of Object and could not be converted to a string'
+ 'Given query param is an instance of ObjectClass and could not be converted to a string'
);
$sql = 'SELECT * FROM table WHERE column = ?';
- $params = [new Object];
+ $params = [new ObjectClass];
$this->formatter->format($sql, $params);
}
@@ -53,7 +53,7 @@ public function test_cannot_replace_object_params_without__toString()
public function test_can_replace_object_params_with__toString()
{
$sql = 'SELECT * FROM table WHERE column = ?';
- $params = [new String];
+ $params = [new StringClass];
$this->assertEquals(
'SELECT * FROM table WHERE column = "string"',
@@ -79,11 +79,11 @@ protected function tearDown()
}
}
-class Object
+class ObjectClass
{
}
-class String
+class StringClass
{
public function __toString()
{
diff --git a/tests/Loggers/LaravelDebugbarLoggerTest.php b/tests/Loggers/LaravelDebugbarLoggerTest.php
index 54c9d5dc..8cd63e3b 100644
--- a/tests/Loggers/LaravelDebugbarLoggerTest.php
+++ b/tests/Loggers/LaravelDebugbarLoggerTest.php
@@ -17,10 +17,16 @@ public function test_can_register()
$configuration->shouldReceive('setSQLLogger')
->once();
+ $debugbar->shouldReceive('hasCollector')->with('doctrine')->once()->andReturn(false);
$debugbar->shouldReceive('addCollector')->once();
$logger = new LaravelDebugbarLogger($debugbar);
$logger->register($em, $configuration);
}
+
+ protected function tearDown()
+ {
+ m::close();
+ }
}
diff --git a/tests/Serializers/ArraySerializerTest.php b/tests/Serializers/ArraySerializerTest.php
new file mode 100644
index 00000000..a4a287e2
--- /dev/null
+++ b/tests/Serializers/ArraySerializerTest.php
@@ -0,0 +1,46 @@
+serializer = new ArraySerializer;
+ }
+
+ public function test_can_serialize_to_array()
+ {
+ $array = $this->serializer->serialize(new ArrayableEntity);
+
+ $this->assertEquals([
+ 'id' => 'IDVALUE',
+ 'name' => 'NAMEVALUE'
+ ], $array);
+ }
+}
+
+class ArrayableEntity
+{
+ use Arrayable;
+
+ protected $id = 'IDVALUE';
+
+ protected $name = 'NAMEVALUE';
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+}
diff --git a/tests/Serializers/JsonSerializerTest.php b/tests/Serializers/JsonSerializerTest.php
new file mode 100644
index 00000000..972ef751
--- /dev/null
+++ b/tests/Serializers/JsonSerializerTest.php
@@ -0,0 +1,43 @@
+serializer = new JsonSerializer;
+ }
+
+ public function test_can_serialize_to_array()
+ {
+ $array = $this->serializer->serialize(new JsonableEntity);
+
+ $this->assertEquals('{"id":"IDVALUE","name":"NAMEVALUE"}', $array);
+ }
+}
+
+class JsonableEntity
+{
+ use Jsonable;
+
+ protected $id = 'IDVALUE';
+
+ protected $name = 'NAMEVALUE';
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+}
diff --git a/tests/Stubs/atrauzzi-config-sample.php b/tests/Stubs/atrauzzi-config-sample.php
new file mode 100644
index 00000000..13522571
--- /dev/null
+++ b/tests/Stubs/atrauzzi-config-sample.php
@@ -0,0 +1,230 @@
+ [
+
+ [
+ '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..5d8c2761
--- /dev/null
+++ b/tests/Stubs/mitchellvanw-config-sample.php
@@ -0,0 +1,38 @@
+ '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