lucidarch / laravel

[DEPRECATED] See https://github.com/lucidarch/lucid

Home Page:https://lucidarch.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while executing Unittests

websmurf opened this issue · comments

Hi there,

Based on your presentatie we started to build an application using the Lucid principe.
I'm running into an issue while executing the unittests from the services.

The error I'm getting is:

adam@mpb-adam api (master) $ vendor/bin/phpunit
PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

III.PHP Fatal error:  Cannot declare class Lucid\Console\Controller, because the name is already in use in /Users/adam/Sites/customers.dev/api/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 107
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:763
Stack trace:
#0 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/adam/Sit in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 763

Fatal error: Cannot declare class Lucid\Console\Controller, because the name is already in use in /Users/adam/Sites/customers.dev/api/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 107

Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:763
Stack trace:
#0 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('Illuminate\\Cont...', Array)
#1 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#2 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(154): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#3 /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(79): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#4 /Users/adam/Sit in /Users/adam/Sites/customers.dev/api/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 763

I've narrowed it down to /vendor/lucid-arch/laravel-console/src/Http/routes.php, there is a class "Controller" defined there. The unit tests load this file more than one time, resulting in the duplicate class error. Any thoughts on how to resolve this?

This issue exists in an older version of the package. What is the version of the lucid-arch/console package in your composer.lock?

Hi Abed,

Generated the project ± 2 weeks ago. I don't have lucid-arch/console, but I do have lucid-arch/laravel-console:

{
            "name": "lucid-arch/laravel-console",
            "version": "dev-master",
            "source": {
                "type": "git",
                "url": "https://github.com/lucid-architecture/console-laravel.git",
                "reference": "f6b396fb01400116c8af5d609d7ab273c19f9984"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/lucid-architecture/console-laravel/zipball/f6b396fb01400116c8af5d609d7ab273c19f9984",
                "reference": "f6b396fb01400116c8af5d609d7ab273c19f9984",
                "shasum": ""
            },
            "require": {
                "phploc/phploc": "^3.0",
                "stevebauman/log-reader": "^1.1",
                "symfony/console": "^2.7|^3.0",
                "symfony/filesystem": "^2.7|^3.0",
                "symfony/finder": "^2.7|^3.0",
                "symfony/process": "^2.7|^3.0"
            },
            "bin": [
                "lucid"
            ],
            "type": "library",
            "autoload": {
                "psr-4": {
                    "Lucid\\Console\\": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Abed Halawi",
                    "email": "abed.halawi@vinelab.com"
                }
            ],
            "description": "The Command Line Interface for the Lucid Architecture",
            "keywords": [
                "architecture",
                "ddd",
                "domains",
                "laravel",
                "lucid",
                "mvc"
            ],
            "time": "2016-09-13 16:43:27"
        }

In the current master branch, this piece is still there: https://github.com/lucid-architecture/console-laravel/blob/master/src/Http/routes.php

@websmurf couldn't re-produce that honestly, are you still facing this issue?

@websmurf Have you had anymore issues with this? I came across a similar error with the same routes file but in my case the controller class couldn't be re-declared.

vagrant@homestead:~/projects/work/lvr$ phpunit
PHPUnit 5.1.7 by Sebastian Bergmann and contributors.

IPHP Fatal error:  Cannot redeclare class Lucid\Console\Controller in /home/vagrant/projects/work/lvr/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 108
PHP Stack trace:
PHP   1. {main}() /home/vagrant/projects/work/lvr/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/vagrant/projects/work/lvr/vendor/phpunit/phpunit/phpunit:47
PHP   3. PHPUnit_TextUI_Command->run() /home/vagrant/projects/work/lvr/vendor/phpunit/phpunit/src/TextUI/Command.php:106
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /home/vagrant/projects/work/lvr/vendor/phpunit/phpunit/src/TextUI/Command.php:155
PHP   5. PHPUnit_Framework_TestSuite->run() 
...

I noticed that in laravel-console/src/LucidServiceProvider.php where the routes file is being required that when set to require_once I didn't get any errors. I also noticed that the if (! $this->app->routesAreCached()) surrounding it so I tried reverting the require edit and ran php artisan route:cache but I got the same "Cannot redeclare class" error.

@Mulkave If it helps, this was originally happening on a new project on Laravel 5.2 which was installed via composer. I've composer updated Laravel to 5.3 as well as Lucid to the latest and the issue still exists.

PHP 5.6.23
Laravel 5.3.21
Lucid 5.3.1
Lucid Console 0.5.0

I've managed to reproduce this error on a fresh project doing the following;

  1. composer create-project lucid-arch/laravel test-project
  2. phpunit runs fine
  3. vendor/bin/lucid make:service Test
  4. Added $this->app->register(TestServiceProvider::class); to test-project/src/Foundation/ServiceProvider.php (even though the output from the previous command advised to register it as $this->app->register('App\Services\Test\Providers\TestServiceProvider’);)
  5. composer dump-autoload
  6. phpunit runs fine
  7. vendor/bin/lucid make:feature TestFeature Test
  8. phpunit get the error PHP Fatal error: Cannot redeclare class Lucid\Console\Controller in /home/vagrant/projects/work/test-project/vendor/lucid-arch/laravel-console/src/Http/routes.php on line 108...

Thanks @Paradiddley will look into it.

It appeared to be a silly fix for a rookie mistake 😅. Please update the console package for the fix

composer update lucid-arch/laravel-console

Great! Thanks @Mulkave