fsilva1985's avatar

Mockery_1_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified

Hello. I have a problem with php-unit's job pipeline gilab.

My local server its works very well.

Anybody help me?

Tnx

.gitlab-ci.yml

image: my_company/build:php-7.3

# Select what we should cache
cache:
  paths:
  - vendor/

before_script:
# Install composer
- composer install --optimize-autoloader

stages:
- test

Code Sniffer:
  stage: test
  script:
  - vendor/bin/phpcbf --version
  - vendor/bin/phpcbf --standard=PSR1,PSR2 --extensions=php app
  - vendor/bin/phpcbf --standard=PSR1,PSR2 --extensions=php tests
  only:
  - branches

Unit Test:
  stage: test
  script:
  - vendor/bin/phpunit --version
  - vendor/bin/phpunit --stop-on-error --colors=always tests
  only:
  - branches

Console:

Running with gitlab-ci-multi-runner 9.5.1 (96b34cc)
  on melancia (5874ee3c)
Using Docker executor with image folha/build:php-7.3 ...
Using docker image sha256:798184b8cab9c692e1f2b4df7ca46da224f43215fcfb306d93d4f1eb0df40881 for predefined container...
Pulling docker image folha/build:php-7.3 ...
Using docker image folha/build:php-7.3 ID=sha256:3ac6fc3f5db6cd0cce49adef26e3ddb685ddd1e6b6c4c152de1daa11121799b7 for build container...
Running on runner-5874ee3c-project-4505-concurrent-0 via melancia...
Fetching changes...
Removing .phpunit.result.cache
Removing bootstrap/cache/packages.php
Removing bootstrap/cache/services.php
Removing composer.lock
Removing vendor/
HEAD is now at 3b66326 corrigido teste unitario
From http://gitlab.corp.folha.com.br/boilerplate-laravel/api
   3b66326..8f8d059  fix/gitlabci-phpunit -> origin/fix/gitlabci-phpunit
Checking out cbabe680 as fix/gitlabci-phpunit...
Skipping Git submodules setup
Checking cache for default...
Successfully extracted cache
$ composer install --optimize-autoloader
    1/12:   http://repo.packagist.org/p/provider-archived$f87c6b240bff8b508c75240fba1a80bd37b4e866f18cfcad053e9dec578da551.json
    2/12:   http://repo.packagist.org/p/provider-2019-01dbec7466f292fc2a905782faeef7e3c41d57525fca11bf98a1f1b8453e2a4a.json
    3/12:   http://repo.packagist.org/p/provider-2014$a94f22575d2bc5a09c2079fab06f35f2c3b8105d59639ca8685d5f18354cf7d3.json
    4/12:   http://repo.packagist.org/p/provider-201303c4461d002a56aecb25720bc47e6f0bcdfce9f6818a12999ff76c9a4da3a2.json
    5/12:   http://repo.packagist.org/p/provider-2015a5ac8e4f6d2f35a4c91f7f16fdfc0e2543ae66c074d4fe7fbba3e9166972f53.json
    6/12:   http://repo.packagist.org/p/provider-2019-07d0f52e7660f59883b7c5db4dd61bd8c886526ad48dc0de9baa10cf77b496e0.json
    7/12:   http://repo.packagist.org/p/provider-latest791d61eaf5661174b1aa75f599656a25cd596281726c82ab4145c766876253.json
    8/12:   http://repo.packagist.org/p/provider-2017c03cf33c1233f8432baf447a8f040b7cac8dccab9b305d105b42d0ebb6f3f8.json
    9/12:   http://repo.packagist.org/p/provider-2019-10$aa6c68abca92a998d2227be87807aedaae850ee70cb083a695c0fce2e23d2353.json
    10/12:  http://repo.packagist.org/p/provider-2019-04697fa09d1b60a963029fc4024408790227c94983b13d627f540967108fe0a9.json
    11/12:  http://repo.packagist.org/p/provider-20164a0fd6eb214903c62b4af3ced6b08d0b584e5d74c727652a36875f7f5eeaf5.json
    12/12:  http://repo.packagist.org/p/provider-2018$efaec423ba24fd1864bbe4c9e2e977b922569f57f6401ed78cc5e8a9c75e89d6.json
    Finished: success: 12, skipped: 0, failure: 0, total: 12
Loading composer repositories with package information
                                                      Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
$ php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!
$ vendor/bin/phpunit --version
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.

$ vendor/bin/phpunit --stop-on-error --colors=always tests
PHPUnit 8.4.3 by Sebastian Bergmann and contributors.

E

Time: 197 ms, Memory: 20.00 MB

There was 1 error:

1) App\AbstractModelTest::testLogInsert
Mockery\Exception\BadMethodCallException: Received Mockery_1_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified

/builds/boilerplate-laravel/api/vendor/symfony/console/Style/SymfonyStyle.php:222
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:385
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/ConfirmableTrait.php:29
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/FreshCommand.php:34
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Support/helpers.php:522
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:90
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:34
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:591
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:202
/builds/boilerplate-laravel/api/vendor/symfony/console/Command/Command.php:255
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:189
/builds/boilerplate-laravel/api/vendor/symfony/console/Application.php:934
/builds/boilerplate-laravel/api/vendor/symfony/console/Application.php:273
/builds/boilerplate-laravel/api/vendor/symfony/console/Application.php:149
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/Application.php:90
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Console/Application.php:182
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:273
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/PendingCommand.php:136
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/PendingCommand.php:220
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithConsole.php:56
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/DatabaseMigrations.php:16
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:119
/builds/boilerplate-laravel/api/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:82

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
ERROR: Job failed: exit code 1

My test

<?php

namespace App;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Folha\Laravel\AbstractModel;
use Folha\Laravel\Log;
use Tests\TestCase;

class ActionAbstractModelTest extends Abst-ciractModel
{
    const CRUDL_YES = 'yes';
    const CRUDL_NO = 'no';

    const CRUDL_LIST = [
        self::CRUDL_YES,
        self::CRUDL_NO
    ];

    protected $table = 'permission_actions';
    protected $primaryKey = 'permission_action_id';
    protected $fillable = ['slug', 'name', 'crudl'];
    protected $hidden = [];
    public $log = true;
    public $softDelete = false;
}

class AbstractModelTest extends TestCase
{
    use DatabaseMigrations;

    public function seeder()
    {
        ActionAbstractModelTest::create(
            [
                'name' => 'manter usuário',
                'crudl' => 'yes',
                'slug' => 'manter-usuario'
            ]
        );
    }

    public function testLogInsert(): void
    {
        $this->seeder();

        $log = Log::find(1)->toArray();

        $this->assertEquals(
            $log['action'],
            'insert'
        );
    }

    public function testLogUpdate(): void
    {
        $this->seeder();
        $model = ActionAbstractModelTest::find(1);
        $model->update([
            'crudl' => 'no'
        ]);

        $log = Log::find(2)->toArray();

        $this->assertEquals(
            $log['action'],
            'update'
        );
    }

    public function testLogDelete(): void
    {
        $this->seeder();
        $model = ActionAbstractModelTest::find(1);
        $model->delete();

        $log = Log::find(2)->toArray();

        $this->assertEquals(
            $log['action'],
            'remove'
        );
    }
}
0 likes
6 replies
fsilva1985's avatar

Solution

Before phpunit command

php artisan config:cache
php artisan config:clear

phpunit

<php>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="MAIL_DRIVER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
    </php>

tnx for nothing...

5 likes
Sinnbeck's avatar

Tip of the day: Don't cache config/routes etc. on development/testing server! :)

1 like
dillonkavanagh's avatar

Oddly I just had this in a client's external project, I've not dug into any further than the fix came from altering the following in the config/app.php file. It was set as production when the error was occuring.

    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services your application utilizes. Set this in your ".env" file.
    |
    */

    'env' => 'local',
2 likes
Scott's avatar

I ran into this with dusk, the answer was to delete the temporary .env file and rename .env.backup to .env

My guess is the tests were interrupted and failed to restore the file, which caused this cryptic error on subsequent runs.

gilbitron's avatar

For anyone else who comes across this issue, it seems to be happening when no APP_ENV is set in your .env file when trying to run dusk while using DatabaseMigrations. When no APP_ENV is set, the env defaults to production, which will cause the migrate command to prompt you to confirm if you want to run migrations in production. This seems to be what causes the "Mockery_1_Illuminate_Console_OutputStyle::askQuestion(), but no expectations were specified" error.

3 likes

Please or to participate in this conversation.