laravel-doctrine
laravel-doctrine copied to clipboard
Error: Type json already exists.
When trying to execute multiple unit-tests, I am getting the following error: Type json already exists. This happens when the second unit-test is being executed. I assume that the APP is already initialized.
The error happens here. Any idea?
class ServiceProvider extends Base {
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot() {
Type::addType('json', '\Atrauzzi\LaravelDoctrine\Type\Json');
$this->publishes([__DIR__ .'/..'. '/config/doctrine.php'=> config_path('doctrine.php')], 'config');
$this->commands([
'Atrauzzi\LaravelDoctrine\Console\CreateSchemaCommand',
'Atrauzzi\LaravelDoctrine\Console\UpdateSchemaCommand',
'Atrauzzi\LaravelDoctrine\Console\DropSchemaCommand'
]);
}
Testing started at 11:16 AM ...
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.
Type json already exists.
D:\Projects.fms\mapps1\vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php:218
D:\Projects.fms\mapps1\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\Type.php:193
D:\Projects.fms\mapps1\vendor\atrauzzi\laravel-doctrine\src\ServiceProvider.php:27
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Container\Container.php:523
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:701
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:683
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:684
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\BootProviders.php:15
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:181
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:195
D:\Projects.fms\mapps1\tests\TestCase.php:16
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Testing\ApplicationTrait.php:38
D:\Projects.fms\mapps1\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:27
I've locally soved it with this, but I'm not sure if it's the correct solution
if (!Type::hasType('json')) {
Type::addType( 'json', '\Atrauzzi\LaravelDoctrine\Type\Json' );
$this->publishes( [ __DIR__ . '/..' . '/config/doctrine.php' => config_path( 'doctrine.php' ) ], 'config' );
}
Maybe this
doctrine.php
'custom_types' => [
'json' => Atrauzzi\LaravelDoctrine\Type\Json::class
],
In my boot method, there is a couple of code
public function boot() {
$this->registerCustomTypes();
$this->publishes([__DIR__ .'/..'. '/config/doctrine.php'=> config_path('doctrine.php')], 'config');
$this->commands([
'Atrauzzi\LaravelDoctrine\Console\CreateSchemaCommand',
'Atrauzzi\LaravelDoctrine\Console\UpdateSchemaCommand',
'Atrauzzi\LaravelDoctrine\Console\DropSchemaCommand'
]);
$this->extendsAuth();
}
protected function registerCustomTypes() {
foreach(config('doctrine.custom_types',array()) as $name=>$class)
{
if(!Type::hasType($name)){
Type::addType($name, $class);
}
else{
Type::overrideType($name, $class);
}
}
}
@klodoma Did you solve the problem?
Oje, completely forgot about this. I fixed it as mentioned, let me give it a try and come back on this.