nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

Error when adding disableExceptionHandling method to TestCase class #5

Closed SoyUnEmilio closed 7 years ago

SoyUnEmilio commented 7 years ago

C:\php\php.exe D:/laravel/ticketbeast/vendor/phpunit/phpunit/phpunit --configuration D:\laravel\ticketbeast\phpunit.xml D:\laravel\ticketbeast\tests --teamcity Testing started at 23:37 ... PHP Parse error: syntax error, unexpected 'class' (T_CLASS) in D:\laravel\ticketbeast\tests\TestCase.php on line 25

Parse error: syntax error, unexpected 'class' (T_CLASS) in D:\laravel\ticketbeast\tests\TestCase.php on line 25

Process finished with exit code 255

This is the line 25: $this->app->instance(ExceptionHandler::class, new class extends Handler {

And this is the whole method:

protected function disableExceptionHandling()
{
    $this->app->instance(ExceptionHandler::class, new class extends Handler {
        public function __construct() {}
        public function report(Exception $e) {}
        public function render($request, Exception $e) {
            throw $e;
        }
    });
}

What am I doing wrong?

My php version:

D:\laravel\ticketbeast>php --version PHP 5.6.28 (cli) (built: Nov 9 2016 06:40:27) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

joelclermont commented 7 years ago

Anonymous classes were added in php 7.

SoyUnEmilio commented 7 years ago

Thanks you @joelclermont

Reading composer.json and it says:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "zondicons/blade-bridge": "^0.1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Why in the hell are we using anonymous functions? :(. I decided to install 5.6.28 because it was supported :'(.

adamwathan commented 7 years ago

There's a 5.6 compatible solution here:

https://gist.github.com/adamwathan/c9752f61102dc056d157

I highly recommend switching to PHP 7, my mistake not updating that requirement in the composer.json file.

On Thu, Dec 8, 2016 at 6:02 PM Emilio López Arias notifications@github.com wrote:

Thanks you @joelclermont https://github.com/joelclermont

Reading composer.json and it says:

{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=5.6.4", "laravel/framework": "5.3.", "zondicons/blade-bridge": "^0.1.0" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.", "phpunit/phpunit": "~5.0", "symfony/css-selector": "3.1.", "symfony/dom-crawler": "3.1." }, "autoload": { "classmap": [ "database" ], "psr-4": { "App\": "app/" } }, "autoload-dev": { "classmap": [ "tests/TestCase.php" ] }, "scripts": { "post-root-package-install": [ "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "php artisan key:generate" ], "post-install-cmd": [ "Illuminate\Foundation\ComposerScripts::postInstall", "php artisan optimize" ], "post-update-cmd": [ "Illuminate\Foundation\ComposerScripts::postUpdate", "php artisan optimize" ] }, "config": { "preferred-install": "dist" } }

Why in the hell are we using anonymous functions? :(. I decided to install 5.6.28 because it was supported :'(.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nothingworksinc/ticketbeast/issues/5#issuecomment-265882009, or mute the thread https://github.com/notifications/unsubscribe-auth/AEH3bDbu4Upld2o8SceAa1-uuJBf2-Oeks5rGIyHgaJpZM4LIX9J .