Summer Sale! All accounts are 50% off this week.

PetroGromovo's avatar

Setting APP_ENV = testing in phpunit.xml I got errors

Making tests for laravel site I want to use .env.testing file

I managed to make it code in phpunit.xml :

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
             bootstrap="vendor/autoload.php"
             colors="true"
             printerClass="Sempro\PHPUnitPrettyPrinter\PrettyPrinterForPhpUnit9"
    >
        <testsuites>
            <testsuite name="Pages CRUD tests">
                <directory suffix="Test.php">./tests/Feature</directory>
            </testsuite>
        </testsuites>
        <coverage processUncoveredFiles="true">
            <include>
                <directory suffix=".php">./app</directory>
            </include>
        </coverage>
        <php>
            <env name="APP_ENV" value="testing"/>
            <env name="BCRYPT_ROUNDS" value="4"/>
            <env name="CACHE_DRIVER" value="array"/>
            <env name="TELESCOPE_ENABLED" value="true"/>

            <!--         <env name="DB_CONNECTION" value="sqlite"/>-->
            <!--         <env name="DB_DATABASE" value=":memory:"/>-->
            <env name="MAIL_MAILER" value="array"/>
            <env name="QUEUE_CONNECTION" value="sync"/>
            <env name="SESSION_DRIVER" value="array"/>
            <env name="TELESCOPE_ENABLED" value="false"/>
        </php>
    </phpunit>

clearing cache with command :

    php artisan config:clear

I got errors on test run on any test in my file:

    ...
    12) Tests\Feature\PagesCrudTest::testGetFilteredOnlyIsHomepage
    Illuminate\Contracts\Container\BindingResolutionException: Target class [env] does not exist.

    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Container.php:877
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Container.php:756
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:857
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Container.php:692
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:842
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Container.php:1415
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:575
    ProjectPath/app/Providers/TelescopeServiceProvider.php:24
    ProjectPath/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60
    ProjectPath/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60
    ProjectPath/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php:299
    ProjectPath/vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61
    ProjectPath/vendor/laravel/telescope/src/Telescope.php:326
    ProjectPath/vendor/laravel/telescope/src/Telescope.php:284
    ProjectPath/vendor/laravel/telescope/src/Telescope.php:333
    ProjectPath/vendor/laravel/telescope/src/Telescope.php:445
    ProjectPath/vendor/laravel/telescope/src/Watchers/LogWatcher.php:41
    ProjectPath/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:421
    ProjectPath/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php:249
    ProjectPath/vendor/laravel/framework/src/Illuminate/Log/Logger.php:245
    ProjectPath/vendor/laravel/framework/src/Illuminate/Log/Logger.php:186
    ProjectPath/vendor/laravel/framework/src/Illuminate/Log/Logger.php:130
    ProjectPath/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:677
    ProjectPath/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:338
    ProjectPath/app/Providers/RouteServiceProvider.php:50
    ProjectPath/app/Providers/RouteServiceProvider.php:29
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Util.php:41
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
    ProjectPath/vendor/laravel/framework/src/Illuminate/Container/Container.php:651
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:930
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:911
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:912
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:239
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:310
    ProjectPath/tests/CreatesApplication.php:18
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:110
    ProjectPath/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:87
    ProjectPath/tests/Feature/PagesCrudTest.php:25

    ERRORS!
    Tests: 12, Assertions: 0, Errors: 12.

But all the rests are running ok I suppose that it is related that that now .env.testing is used, but how can it be fixed?

"phpunit/phpunit": "^9.5.10"
"laravel/framework": "^9.2"

Thanks in advance!

0 likes
4 replies
Nakov's avatar

Remove this line <env name="TELESCOPE_ENABLED" value="true"/> you have it twice, it should be set to false.

1 like

Please or to participate in this conversation.