mockery | simple yet flexible PHP mock object framework for use | Mock library

 by   mockery PHP Version: 1.5.1 License: Non-SPDX

kandi X-RAY | mockery Summary

mockery is a PHP library typically used in Testing, Mock applications. mockery has no bugs, it has no vulnerabilities and it has medium support. However mockery has a Non-SPDX License. You can download it from GitHub.
[Total Downloads] Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit’s phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending. Mockery is released under a New BSD License.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        mockery has a medium active ecosystem.
                        summary
                        It has 10368 star(s) with 460 fork(s). There are 76 watchers for this library.
                        summary
                        There were 2 major release(s) in the last 12 months.
                        summary
                        There are 103 open issues and 511 have been closed. On average issues are closed in 201 days. There are 14 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of mockery is 1.5.1
                        mockery Support
                          Best in #Mock
                            Average in #Mock
                            mockery Support
                              Best in #Mock
                                Average in #Mock

                                  kandi-Quality Quality

                                    summary
                                    mockery has 0 bugs and 0 code smells.
                                    mockery Quality
                                      Best in #Mock
                                        Average in #Mock
                                        mockery Quality
                                          Best in #Mock
                                            Average in #Mock

                                              kandi-Security Security

                                                summary
                                                mockery has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                mockery code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                mockery Security
                                                  Best in #Mock
                                                    Average in #Mock
                                                    mockery Security
                                                      Best in #Mock
                                                        Average in #Mock

                                                          kandi-License License

                                                            summary
                                                            mockery has a Non-SPDX License.
                                                            summary
                                                            Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
                                                            mockery License
                                                              Best in #Mock
                                                                Average in #Mock
                                                                mockery License
                                                                  Best in #Mock
                                                                    Average in #Mock

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        mockery releases are available to install and integrate.
                                                                        summary
                                                                        Installation instructions, examples and code snippets are available.
                                                                        summary
                                                                        mockery saves you 2152 person hours of effort in developing the same functionality from scratch.
                                                                        summary
                                                                        It has 4772 lines of code, 575 functions and 98 files.
                                                                        summary
                                                                        It has medium code complexity. Code complexity directly impacts maintainability of the code.
                                                                        mockery Reuse
                                                                          Best in #Mock
                                                                            Average in #Mock
                                                                            mockery Reuse
                                                                              Best in #Mock
                                                                                Average in #Mock
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed mockery and discovered the below as its top functions. This is intended to give you an instant insight into mockery implemented functionality, and help decide if they suit your requirements.
                                                                                  • Handles mocked method calls .
                                                                                    • Get type information
                                                                                      • Render method body .
                                                                                        • Build the mock chain .
                                                                                          • Get methods to mock
                                                                                            • Check if the expected argument matches the expected value .
                                                                                              • Attempt to instantiate a class via unserialization .
                                                                                                • Get method declaration .
                                                                                                  • Return an instance of the mock class
                                                                                                    • Validate the number of times a number of times .
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      mockery Key Features

                                                                                                      Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).

                                                                                                      mockery Examples and Code Snippets

                                                                                                      No Code Snippets are available at this moment for mockery.
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on mockery

                                                                                                      syntax error, unexpected '@', expecting variable (T_VARIABLE) or '{' or '$'
                                                                                                      chevron right
                                                                                                      Unable to install laravel/sail due to incompatible versions it seems
                                                                                                      chevron right
                                                                                                      Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found on Laravel 9
                                                                                                      chevron right
                                                                                                      How to mock a non-deterministic method?
                                                                                                      chevron right
                                                                                                      laravel/passport for laravel lumen support
                                                                                                      chevron right
                                                                                                      Upgrading laravel into 8 I got illuminate/support support?
                                                                                                      chevron right
                                                                                                      mockery::mock and mockery::stub do not work properly with quasiquotation?
                                                                                                      chevron right
                                                                                                      Laravel model can't be named 'Match'
                                                                                                      chevron right
                                                                                                      Is the code actually executed when using a Mockery spy?
                                                                                                      chevron right
                                                                                                      Heroku deploy failure, requested package composer-plugin-api could not be found in any version
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      syntax error, unexpected '@', expecting variable (T_VARIABLE) or '{' or '$'
                                                                                                      Asked 2022-Apr-10 at 20:07

                                                                                                      I'am using php 7.4.27, laravel framework 8.83.7 and installed Laravel Jetstream. Login & Register can show. After registered, Then an error notification appears in Laravel: syntax error, unexpected '@', expecting variable (T_VARIABLE) or '{' or '$' and in code line 12 :

                                                                                                      getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'jetstream::components.dropdown-link','data' => ['href' => $href,'@click.prevent' => $@clickPrevent]]); ?>
                                                                                                      

                                                                                                      I won't update to php 8. What should i do?

                                                                                                      =====edited=====

                                                                                                      composer.json file :

                                                                                                      {
                                                                                                      "name": "laravel/laravel",
                                                                                                      "type": "project",
                                                                                                      "description": "The Laravel Framework.",
                                                                                                      "keywords": ["framework", "laravel"],
                                                                                                      "license": "MIT",
                                                                                                      "require": {
                                                                                                          "php": "^7.3|^8.0",
                                                                                                          "fruitcake/laravel-cors": "^2.0",
                                                                                                          "guzzlehttp/guzzle": "^7.0.1",
                                                                                                          "laravel/framework": "^8.75",
                                                                                                          "laravel/jetstream": "^2.7",
                                                                                                          "laravel/sanctum": "^2.11",
                                                                                                          "laravel/tinker": "^2.5",
                                                                                                          "livewire/livewire": "^2.5"
                                                                                                      },
                                                                                                      "require-dev": {
                                                                                                          "facade/ignition": "^2.5",
                                                                                                          "fakerphp/faker": "^1.9.1",
                                                                                                          "laravel/sail": "^1.0.1",
                                                                                                          "mockery/mockery": "^1.4.4",
                                                                                                          "nunomaduro/collision": "^5.10",
                                                                                                          "phpunit/phpunit": "^9.5.10"
                                                                                                      },
                                                                                                      "autoload": {
                                                                                                          "psr-4": {
                                                                                                              "App\\": "app/",
                                                                                                              "Database\\Factories\\": "database/factories/",
                                                                                                              "Database\\Seeders\\": "database/seeders/"
                                                                                                          }
                                                                                                      },
                                                                                                      "autoload-dev": {
                                                                                                          "psr-4": {
                                                                                                              "Tests\\": "tests/"
                                                                                                          }
                                                                                                      },
                                                                                                      "scripts": {
                                                                                                          "post-autoload-dump": [
                                                                                                              "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                                                                                                              "@php artisan package:discover --ansi"
                                                                                                          ],
                                                                                                          "post-update-cmd": [
                                                                                                              "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
                                                                                                          ],
                                                                                                          "post-root-package-install": [
                                                                                                              "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                          ],
                                                                                                          "post-create-project-cmd": [
                                                                                                              "@php artisan key:generate --ansi"
                                                                                                          ]
                                                                                                      },
                                                                                                      "extra": {
                                                                                                          "laravel": {
                                                                                                              "dont-discover": []
                                                                                                          }
                                                                                                      },
                                                                                                      "config": {
                                                                                                          "optimize-autoloader": true,
                                                                                                          "preferred-install": "dist",
                                                                                                          "sort-packages": true
                                                                                                      },
                                                                                                      "minimum-stability": "dev",
                                                                                                      "prefer-stable": true
                                                                                                      

                                                                                                      }

                                                                                                      ANSWER

                                                                                                      Answered 2022-Apr-10 at 20:07
                                                                                                      Explanation:

                                                                                                      The issue comes from the fact that the compiled view version under storage/framework/views is failing to evaluate $@clickPrevent.

                                                                                                      getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'jetstream::components.dropdown-link','data' => ['href' => $href,'@click.prevent' => $@clickPrevent]]); ?>
                                                                                                      

                                                                                                      This has nothing to do with your current PHP version.

                                                                                                      Solution:

                                                                                                      I managed to locally reproduce the issue. Here is how I solved it.

                                                                                                      Steps:
                                                                                                      1. Publish the Jetstream Livewire components.

                                                                                                        Command:

                                                                                                        php artisan vendor:publish --tag=jetstream-views

                                                                                                      2. Open the file resources/views/vendor/jetstream/components/switchable-team.blade.php

                                                                                                        In the file contents,

                                                                                                        Instead of:

                                                                                                      Use this:

                                                                                                      Disclaimer:

                                                                                                      Note that this is a temporary solution. Everything works fine for me. As lamented by @IMSoP in a comment, I'm afraid it may affect some unknown functionality. I've opened an issue against the library here:

                                                                                                      switchable-team.blade.php compiled Jetstream component throwing an error: syntax error, unexpected token "@", expecting variable or "{" or "$"

                                                                                                      Update 10th/April/2022:

                                                                                                      Another "more stable" solution stated by @fabpl on the opened Github issue:

                                                                                                      I think it's the same bug like [2.x] Fix parse error caused by alpine shorthand on dynamic-component #1032

                                                                                                      Try to replace @click with x-on:click

                                                                                                      Addendum:

                                                                                                      The issue seems to have been introduced in laravel/jetstream v2.7.2. More specifically Use Alpine's @click.prevent for switching teams.

                                                                                                      The good news is that this has been resolved beginning from laravel/jetstream v2.7.3 onwards. More specifically [2.x] Fix parse error caused by alpine shorthand on dynamic-component.

                                                                                                      I just tagged v2.7.3 which should fix this. Thanks all 👍

                                                                                                      Hence, you may simply just upgrade your Jetstream version to v2.7.3 to get the fix. I.e:

                                                                                                      Command:

                                                                                                      composer update laravel/jetstream:2.7.3

                                                                                                      *Sample Output:

                                                                                                      PS C:\Users\Ivan\Documents\SteveContents\GITHUB\Laravel-8.83.7\laravel-8.83.7> composer update laravel/jetstream:2.7.3
                                                                                                      Loading composer repositories with package information
                                                                                                      Info from https://repo.packagist.org: #StandWithUkraine
                                                                                                      Updating dependencies
                                                                                                      Lock file operations: 0 installs, 1 update, 0 removals
                                                                                                        - Upgrading laravel/jetstream (v2.7.2 => v2.7.3)
                                                                                                      Writing lock file
                                                                                                      Installing dependencies from lock file (including require-dev)
                                                                                                      Package operations: 0 installs, 1 update, 0 removals
                                                                                                        - Downloading laravel/jetstream (v2.7.3)
                                                                                                        - Downloading laravel/jetstream (v2.7.3)
                                                                                                        - Downloading laravel/jetstream (v2.7.3)
                                                                                                        - Downloading laravel/jetstream (v2.7.3)
                                                                                                        - Upgrading laravel/jetstream (v2.7.2 => v2.7.3): Extracting archive
                                                                                                      ...
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/71805796

                                                                                                      QUESTION

                                                                                                      Unable to install laravel/sail due to incompatible versions it seems
                                                                                                      Asked 2022-Mar-31 at 10:29

                                                                                                      I'm trying to install laravel/sail into an existing project, which doesn't appear to have had it installed before. This project is normally run on vagrant I believe.

                                                                                                      I'm trying to get it running on WSL2, using Laravel Sail. I'm also not entirely sure if that's the best approach in my case.

                                                                                                      My understanding is that I can use sail to get the project running via docker, with minimal setup and configuration.

                                                                                                      I seem to be getting an error when I try to install sail via composer. These are the instructions I'm following: https://laravel.com/docs/9.x/sail#installing-sail-into-existing-applications

                                                                                                      Here's the error:

                                                                                                      $ composer require laravel/sail --dev
                                                                                                      PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20190902/pdo_mysql (/usr/lib/php/20190902/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
                                                                                                      Using version ^1.13 for laravel/sail
                                                                                                      ./composer.json has been updated
                                                                                                      Running composer update laravel/sail
                                                                                                      Loading composer repositories with package information
                                                                                                      Updating dependencies
                                                                                                      Your requirements could not be resolved to an installable set of packages.
                                                                                                      
                                                                                                        Problem 1
                                                                                                          - Root composer.json requires laravel/sail ^1.13 -> satisfiable by laravel/sail[v1.13.0, ..., 1.x-dev].
                                                                                                          - laravel/sail[v1.13.0, ..., 1.x-dev] require illuminate/contracts ^8.0|^9.0 -> found illuminate/contracts[v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.
                                                                                                      
                                                                                                      You can also try re-running composer require with an explicit version constraint, e.g. "composer require laravel/sail:*" to figure out if any version is installable, or "composer require laravel/sail:^2.1" if you know which you need.
                                                                                                      
                                                                                                      Installation failed, reverting ./composer.json and ./composer.lock to their original content.
                                                                                                      

                                                                                                      I'm not entirely sure how to interpret this, but it looks like the version that is attempting to be installed is not compatible with another required package.

                                                                                                      composer.json file:
                                                                                                      {
                                                                                                              "name": "laravel/laravel",
                                                                                                              "description": "The Laravel Framework.",
                                                                                                              "keywords": [
                                                                                                                      "framework",
                                                                                                                      "laravel"
                                                                                                              ],
                                                                                                              "license": "MIT",
                                                                                                              "type": "project",
                                                                                                              "require": {
                                                                                                                      "php": "^7.4",
                                                                                                                      "composer-runtime-api": "^2.0",
                                                                                                                      "aws/aws-sdk-php-laravel": "^3.6",
                                                                                                                      "doctrine/dbal": "^2.8",
                                                                                                                      "fideloper/proxy": "^4.0",
                                                                                                                      "guzzlehttp/guzzle": "^7.3",
                                                                                                                      "laravel/framework": "6.*",
                                                                                                                      "laravel/nexmo-notification-channel": "^2.5",
                                                                                                                      "laravel/passport": "9.4.*",
                                                                                                                      "laravel/tinker": "^1.0",
                                                                                                                      "maatwebsite/excel": "^3.1",
                                                                                                                      "nexmo/laravel": "^2.4",
                                                                                                                      "rap2hpoutre/laravel-log-viewer": "1.7.*",
                                                                                                                      "spatie/laravel-uptime-monitor": "^3.7",
                                                                                                                      "vonage/client": "^2.4"
                                                                                                              },
                                                                                                              "require-dev": {
                                                                                                                      "barryvdh/laravel-debugbar": "^3.2",
                                                                                                                      "barryvdh/laravel-ide-helper": "^2.8",
                                                                                                                      "filp/whoops": "^2.0",
                                                                                                                      "fzaninotto/faker": "^1.4",
                                                                                                                      "mockery/mockery": "^1.0",
                                                                                                                      "nunomaduro/collision": "^3.0",
                                                                                                                      "phpunit/phpunit": "^7.1"
                                                                                                              },
                                                                                                              "autoload": {
                                                                                                                      "classmap": [
                                                                                                                              "database",
                                                                                                                              "app/Http/Controllers",
                                                                                                                              "app/Console/Commands"
                                                                                                                      ],
                                                                                                                      "psr-4": {
                                                                                                                              "App\\": "app/"
                                                                                                                      }
                                                                                                              },
                                                                                                              "autoload-dev": {
                                                                                                                      "psr-4": {
                                                                                                                              "Tests\\": "tests/"
                                                                                                                      }
                                                                                                              },
                                                                                                              "extra": {
                                                                                                                      "laravel": {
                                                                                                                              "dont-discover": []
                                                                                                                      }
                                                                                                              },
                                                                                                              "scripts": {
                                                                                                                      "post-root-package-install": [
                                                                                                                              "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                                      ],
                                                                                                                      "post-create-project-cmd": [
                                                                                                                              "@php artisan key:generate"
                                                                                                                      ],
                                                                                                                      "post-autoload-dump": [
                                                                                                                              "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                                                                                                                              "@php artisan package:discover"
                                                                                                                      ]
                                                                                                              },
                                                                                                              "config": {
                                                                                                                      "platform": {
                                                                                                                              "php": "7.4"
                                                                                                                      },
                                                                                                                      "preferred-install": "dist",
                                                                                                                      "sort-packages": true,
                                                                                                                      "optimize-autoloader": true
                                                                                                              },
                                                                                                              "minimum-stability": "dev",
                                                                                                              "prefer-stable": true
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Mar-28 at 21:44

                                                                                                      To fix this and avoid the incompatibility of certain dependencies, you can run:

                                                                                                      composer require laravel/sail --dev --ignore-platform-reqs
                                                                                                      

                                                                                                      But it's not a very good practice.

                                                                                                      Source https://stackoverflow.com/questions/71652070

                                                                                                      QUESTION

                                                                                                      Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found on Laravel 9
                                                                                                      Asked 2022-Mar-24 at 14:34

                                                                                                      I just wanted to use Mailgun to send E-mail from my Laravel project and followed this steps from official document: https://laravel.com/docs/9.x/mail#mailgun-driver

                                                                                                      composer require symfony/mailgun-mailer symfony/http-client

                                                                                                      When I try to send password reset e-mail to test it, it throws an excepiton:

                                                                                                      Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found

                                                                                                      Here is the full stack trace: https://flareapp.io/share/oPRKqyZ7#share

                                                                                                      I don't know but maybe it's because this project started as a Laravel 8 project and I updated it to Laravel 9 one week ago. Is it trying to find something comes with Laravel 9 into app directory or something but my project doesn't have that? I didn't understand.

                                                                                                      By the way if it helps; this project uses Jetstream with Inertia.js and Vue.js. So the composer.json looks like this now:

                                                                                                      {
                                                                                                          "name": "laravel/laravel",
                                                                                                          "type": "project",
                                                                                                          "description": "The Laravel Framework.",
                                                                                                          "keywords": ["framework", "laravel"],
                                                                                                          "license": "MIT",
                                                                                                          "require": {
                                                                                                              "php": "^8.0.2",
                                                                                                              "fruitcake/laravel-cors": "^2.0",
                                                                                                              "guzzlehttp/guzzle": "^7.2",
                                                                                                              "inertiajs/inertia-laravel": "^0.5.4",
                                                                                                              "laravel/framework": "^9.2",
                                                                                                              "laravel/jetstream": "^2.4",
                                                                                                              "laravel/octane": "^1.0",
                                                                                                              "laravel/sanctum": "^2.14.1",
                                                                                                              "laravel/tinker": "^2.7",
                                                                                                              "sentry/sentry-laravel": "^2.11",
                                                                                                              "symfony/http-client": "^6.0",
                                                                                                              "symfony/mailgun-mailer": "^6.0",
                                                                                                              "tightenco/ziggy": "^1.0"
                                                                                                          },
                                                                                                          "require-dev": {
                                                                                                              "spatie/laravel-ignition": "^1.0",
                                                                                                              "fakerphp/faker": "^1.9.1",
                                                                                                              "laravel/sail": "^1.12",
                                                                                                              "mockery/mockery": "^1.4.4",
                                                                                                              "nunomaduro/collision": "^6.1",
                                                                                                              "phpunit/phpunit": "^9.5.10"
                                                                                                          },
                                                                                                          "autoload": {
                                                                                                              "psr-4": {
                                                                                                                  "App\\": "app/",
                                                                                                                  "Database\\Factories\\": "database/factories/",
                                                                                                                  "Database\\Seeders\\": "database/seeders/"
                                                                                                              }
                                                                                                          },
                                                                                                          "autoload-dev": {
                                                                                                              "psr-4": {
                                                                                                                  "Tests\\": "tests/"
                                                                                                              }
                                                                                                          },
                                                                                                          "scripts": {
                                                                                                              "post-autoload-dump": [
                                                                                                                  "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                                                                                                                  "@php artisan package:discover --ansi"
                                                                                                              ],
                                                                                                              "post-update-cmd": [
                                                                                                                  "@php artisan vendor:publish --tag=laravel-assets --ansi"
                                                                                                              ],
                                                                                                              "post-root-package-install": [
                                                                                                                  "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                              ],
                                                                                                              "post-create-project-cmd": [
                                                                                                                  "@php artisan key:generate --ansi"
                                                                                                              ]
                                                                                                          },
                                                                                                          "extra": {
                                                                                                              "laravel": {
                                                                                                                  "dont-discover": []
                                                                                                              }
                                                                                                          },
                                                                                                          "config": {
                                                                                                              "optimize-autoloader": true,
                                                                                                              "preferred-install": "dist",
                                                                                                              "sort-packages": true
                                                                                                          },
                                                                                                          "minimum-stability": "dev",
                                                                                                          "prefer-stable": true
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Mar-24 at 09:18

                                                                                                      From the upgrade guide:

                                                                                                      To continue using the Mailgun transport, your application should require the symfony/mailgun-mailer and symfony/http-client Composer packages:

                                                                                                      so use:

                                                                                                      composer require symfony/mailgun-mailer symfony/http-client
                                                                                                      

                                                                                                      More information here Upgrade to laravel 9

                                                                                                      Source https://stackoverflow.com/questions/71527656

                                                                                                      QUESTION

                                                                                                      How to mock a non-deterministic method?
                                                                                                      Asked 2022-Mar-03 at 23:14

                                                                                                      Consider class with non-deterministic method:

                                                                                                      class Foo
                                                                                                      {
                                                                                                          public function getSome(): int
                                                                                                          {
                                                                                                              static $int = 0;
                                                                                                              return ++$int;
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      How can I mock same behaviour using Mockery?

                                                                                                      class Bar
                                                                                                      {
                                                                                                          public function useFoo(Foo $foo)
                                                                                                          {
                                                                                                              echo $foo->getSome() . ", ";
                                                                                                              echo $foo->getSome() . ", ";
                                                                                                              echo $foo->getSome();
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      $mock = Mockery::mock(Foo::class);
                                                                                                      $mock->shouldReceive('getSome')->andReturn(1);
                                                                                                      $mock->shouldReceive('getSome')->andReturn(2);
                                                                                                      $mock->shouldReceive('getSome')->andReturn(3);
                                                                                                      
                                                                                                      // Should display 1, 2, 3
                                                                                                      $bar = new Bar();
                                                                                                      $bar->useFoo($mock);
                                                                                                      
                                                                                                      
                                                                                                      Another example:
                                                                                                      class Clock
                                                                                                      {
                                                                                                          public function getTime(): int
                                                                                                          {
                                                                                                              return time();
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      class Sleeper 
                                                                                                      {
                                                                                                          public function sleep(int $seconds): void
                                                                                                          {
                                                                                                              sleep($seconds);
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      How can I mock same behaviour using Mockery?

                                                                                                      class Stoper
                                                                                                      {
                                                                                                          private Clock $clock;
                                                                                                          private Sleeper $sleeper;
                                                                                                      
                                                                                                          public function __construct(Clock $clock, Sleeper $sleeper)
                                                                                                          {
                                                                                                              $this->clock = $clock;
                                                                                                              $this->sleeper = $sleeper;
                                                                                                          }
                                                                                                      
                                                                                                          public function measure(int $seconds): int
                                                                                                          {
                                                                                                              $start = $this->clock->getTime();
                                                                                                              $this->sleeper->sleep($seconds);
                                                                                                      
                                                                                                              return $this->clock->getTime();
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      $clockMock = Mockery::mock(Clock::class);
                                                                                                      $clockMock->shouldReceive('getTime')->andReturn(1000000001);
                                                                                                      $clockMock->shouldReceive('getTime')->andReturn(1000000011);
                                                                                                      
                                                                                                      $sleeperMock = Mockery::mock(Sleeper::class);
                                                                                                      $sleeperMock->shouldReceive('sleep');
                                                                                                      
                                                                                                      $stoper = new Stoper($clockMock, $sleeperMock);
                                                                                                      $this->assertEquals(10, $stoper->measure(10));
                                                                                                      
                                                                                                      
                                                                                                      Dirty solution

                                                                                                      I figured out I can make dirty trick

                                                                                                      class ClockCaller
                                                                                                      {
                                                                                                          public function getTime(int $callNumber)
                                                                                                          {
                                                                                                              return (new Clock())->getTime();
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      class Stoper
                                                                                                      {
                                                                                                          private ClockCaller $clockCaller;
                                                                                                          private Sleeper $sleeper;
                                                                                                      
                                                                                                          public function __construct(ClockCaller $clockCaller, Sleeper $sleeper)
                                                                                                          {
                                                                                                              $this->clockCaller = $clockCaller;
                                                                                                              $this->sleeper = $sleeper;
                                                                                                          }
                                                                                                      
                                                                                                          public function measure(int $seconds): int
                                                                                                          {
                                                                                                              $start = $this->clockCaller->getTime(1);
                                                                                                              $this->sleeper->sleep($seconds);
                                                                                                      
                                                                                                              return $this->clockCaller->getTime(2);
                                                                                                          }
                                                                                                      }
                                                                                                      
                                                                                                      $clockMock = Mockery::mock(ClockCaller::class);
                                                                                                      $clockMock->shouldReceive('getTime')->withArgs([1])->andReturn(1000000001);
                                                                                                      $clockMock->shouldReceive('getTime')->withArgs([2])->andReturn(1000000011);
                                                                                                      

                                                                                                      But it seems very nasty

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-26 at 13:08

                                                                                                      The answer to your question is given by the Simple Example in the Mockery documentation. A temperature service that should return successively 10, 12 and 14 degrees can be mocked like this:

                                                                                                      $service = Mockery::mock('service');
                                                                                                      $service->shouldReceive('readTemp')
                                                                                                               ->times(3)
                                                                                                               ->andReturn(10, 12, 14);
                                                                                                      

                                                                                                      So, for your Foo class:

                                                                                                      $mock = Mockery::mock(Foo::class);
                                                                                                      $mock->shouldReceive('getSome')
                                                                                                           ->times(3)
                                                                                                           ->andReturn(1, 2, 3);
                                                                                                      

                                                                                                      and for your Clock:

                                                                                                      $clockMock = Mockery::mock(Clock::class);
                                                                                                      $clockMock->shouldReceive('getTime')
                                                                                                                ->times(2)
                                                                                                                ->andReturn(1000000001, 1000000011);
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/71157233

                                                                                                      QUESTION

                                                                                                      laravel/passport for laravel lumen support
                                                                                                      Asked 2022-Feb-28 at 06:27

                                                                                                      Currently i'm using laravel lumen version 8 for API and i want to integrate laravel/passport for OAuth authorization for the API but when i try to install laravel/passport i get the following error and cannot install laravel/passport for the project. I tried installing dusterio/lumen library for laravel/passport but the package had also some issue with lumen 8.

                                                                                                      Problem 1
                                                                                                          - lcobucci/jwt[3.3.0, ..., 3.4.x-dev] require php ^5.6 || ^7.0 -> your php version (8.0.14) does not satisfy that requirement.
                                                                                                          - lcobucci/jwt 4.0.0-alpha1 requires php ^7.1 -> your php version (8.0.14) does not satisfy that requirement.
                                                                                                          - lcobucci/jwt[4.0.0-alpha2, ..., 4.0.0-alpha3] require php ^7.2 -> your php version (8.0.14) does not satisfy that requirement.
                                                                                                          - Conclusion: don't install laravel/passport v10.3.2 (conflict analysis result)
                                                                                                          - Root composer.json requires tymon/jwt-auth dev-develop -> satisfiable by tymon/jwt-auth[dev-develop].
                                                                                                          - Root composer.json requires laravel/passport ^10.3 -> satisfiable by laravel/passport[v10.3.0, v10.3.1, v10.3.2, 10.x-dev].
                                                                                                          - tymon/jwt-auth dev-develop requires lcobucci/jwt <3.4 -> satisfiable by lcobucci/jwt[1.0.0, 1.0.1, 1.0.2, 1.1.0, 2.0.0, ..., 2.1.x-dev, 3.0.0, ..., 3.3.x-dev].
                                                                                                          - You can only install one version of a package, so only one of these can be installed: lcobucci/jwt[1.0.0, 1.0.1, 1.0.2, 1.1.0, 2.0.0, ..., 2.1.x-dev, 3.0.0, ..., 3.4.x-dev, 4.0.0-alpha1, ..., 4.2.x-dev].
                                                                                                          - laravel/passport 10.x-dev requires lcobucci/jwt ^3.4|^4.0 -> satisfiable by lcobucci/jwt[3.4.0, ..., 3.4.x-dev, 4.0.0-alpha1, ..., 4.2.x-dev].
                                                                                                          - Conclusion: don't install lcobucci/jwt 4.1.5 (conflict analysis result)
                                                                                                      
                                                                                                      You can also try re-running composer require with an explicit version constraint, e.g. "composer require laravel/passport:*" to figure out if any version is installable, or "composer require laravel/passport:^2.1" if you know which you need.
                                                                                                      

                                                                                                      Following is the composer.json of my project.

                                                                                                      {
                                                                                                          "require": {
                                                                                                              "php": "^7.3|^8.0",
                                                                                                              "dingo/api": "^3.0.0",
                                                                                                              "doctrine/dbal": "^3.1",
                                                                                                              "fruitcake/laravel-cors": "^2.0",
                                                                                                              "guzzlehttp/guzzle": "^7.0",
                                                                                                              "illuminate/notifications": "^8.49",
                                                                                                              "illuminate/redis": "^8.49",
                                                                                                              "intervention/image": "^2.6",
                                                                                                              "laravel-notification-channels/onesignal": "^2.3",
                                                                                                              "laravel/lumen-framework": "^8.0",
                                                                                                              "league/flysystem-aws-s3-v3": "^1.0",
                                                                                                              "maatwebsite/excel": "^3.1",
                                                                                                              "pusher/pusher-php-server": "^7.0",
                                                                                                              "simplesoftwareio/simple-qrcode": "^4.2",
                                                                                                              "spatie/data-transfer-object": "^3.7",
                                                                                                              "spatie/laravel-activitylog": "^4.4",
                                                                                                              "spatie/laravel-permission": "^4.0",
                                                                                                              "spatie/laravel-query-builder": "^3.4",
                                                                                                              "spatie/laravel-settings": "^2.1",
                                                                                                              "thiagoalessio/tesseract_ocr": "^2.12",
                                                                                                              "tymon/jwt-auth": "dev-develop",
                                                                                                              "williamcruzme/laravel-fcm": "^1.0"
                                                                                                          },
                                                                                                          "require-dev": {
                                                                                                              "fakerphp/faker": "^1.9.1",
                                                                                                              "flipbox/lumen-generator": "^8.2",
                                                                                                              "knuckleswtf/scribe": "^3.21",
                                                                                                              "mockery/mockery": "^1.3.1",
                                                                                                              "phpunit/phpunit": "^9.3"
                                                                                                          },
                                                                                                          "autoload": {
                                                                                                              "psr-4": {
                                                                                                                  "App\\": "app/",
                                                                                                                  "Database\\Factories\\": "database/factories/",
                                                                                                                  "Database\\Seeders\\": "database/seeders/"
                                                                                                              },
                                                                                                              "files": [
                                                                                                                  "app/helpers.php"
                                                                                                              ]
                                                                                                          },
                                                                                                          "autoload-dev": {
                                                                                                              "classmap": [
                                                                                                                  "database/migrations",
                                                                                                                  "tests/"
                                                                                                              ]
                                                                                                          },
                                                                                                          "config": {
                                                                                                              "preferred-install": "dist",
                                                                                                              "sort-packages": true,
                                                                                                              "optimize-autoloader": true,
                                                                                                              "allow-plugins": {
                                                                                                                  "composer/package-versions-deprecated": true
                                                                                                              }
                                                                                                          },
                                                                                                          "minimum-stability": "dev",
                                                                                                          "prefer-stable": true,
                                                                                                          "scripts": {
                                                                                                              "post-root-package-install": [
                                                                                                                  "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                              ]
                                                                                                          }
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-28 at 06:27

                                                                                                      Main problem is the tymon/jwt-auth removing this package and clean install fixed the problem.

                                                                                                      Source https://stackoverflow.com/questions/71290571

                                                                                                      QUESTION

                                                                                                      Upgrading laravel into 8 I got illuminate/support support?
                                                                                                      Asked 2022-Feb-15 at 07:54

                                                                                                      I try to upgrade my laravel 8 as I read here https://laravel.com/docs/9.x/upgrade

                                                                                                      But after I applyid some changes in composer.json I got error :

                                                                                                       $ composer update
                                                                                                       Loading composer repositories with package information
                                                                                                       Updating dependencies
                                                                                                       Your requirements could not be resolved to an installable set of packages.
                                                                                                       Problem 1
                                                                                                          - illuminate/support[v5.8.0, ..., 5.8.x-dev] require php ^7.1.3 -> your php version (8.1.2) does not satisfy that requirement.
                                                                                                          - illuminate/support[v6.0.0, ..., v6.19.1] require php ^7.2 -> your php version (8.1.2) does not satisfy that requirement.
                                                                                                          - illuminate/support[v7.0.0, ..., v7.28.4] require php ^7.2.5 -> your php version (8.1.2) does not satisfy that requirement.
                                                                                                          - illuminate/support[v8.0.0, ..., v8.11.2] require php ^7.3 -> your php version (8.1.2) does not satisfy that requirement.
                                                                                                          - Root composer.json requires artesaos/seotools ^0.20.2 -> satisfiable by artesaos/seotools[v0.20.2].
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0-beta.2 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0-beta.3 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0-beta.4 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0-beta.5 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.1 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.2 (conflict analysis result)
                                                                                                          - Conclusion: don't install laravel/framework v9.0.0-beta.1 (conflict analysis result)
                                                                                                          - artesaos/seotools v0.20.2 requires illuminate/support 5.8.* || ^6.0 || ^7.0 || ^8.0 -> satisfiable by illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev].
                                                                                                          - Only one of these can be installed: illuminate/support[v5.8.0, ..., 5.8.x-dev, v6.0.0, ..., 6.x-dev, v7.0.0, ..., 7.x-dev, v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev], laravel/framework[v9.0.0-beta.1, ..., 9.x-dev]. laravel/framework replaces illuminate/support and thus cannot coexist with it.
                                                                                                          - Root composer.json requires laravel/framework ^v9.0 -> satisfiable by laravel/framework[v9.0.0-beta.1, ..., 9.x-dev].
                                                                                                          Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
                                                                                                      

                                                                                                      Now composer.json has :

                                                                                                      {
                                                                                                          "name": "laravel/laravel",
                                                                                                          "type": "project",
                                                                                                          "description": "The Laravel Framework.",
                                                                                                          "keywords": ["framework", "laravel"],
                                                                                                          "license": "MIT",
                                                                                                          "require": {
                                                                                                              "php": "^7.3|^8.1",
                                                                                                              "artesaos/seotools": "^0.20.2",
                                                                                                              "barryvdh/laravel-dompdf": "^1.0.0",
                                                                                                              "cviebrock/eloquent-sluggable": "^9.0.0",
                                                                                                              "dompdf/dompdf": "1.0.0",
                                                                                                              "fruitcake/laravel-cors": "^2.0.4",
                                                                                                              "guzzlehttp/guzzle": "^7.4.0",
                                                                                                              "intervention/image": "^2.7",
                                                                                                              "jenssegers/agent": "^2.6",
                                                                                                              "laravel/framework": "^v9.0",
                                                                                                              "laravel/jetstream": "^2.4.4",
                                                                                                              "laravel/sanctum": "^2.12.1",
                                                                                                              "laravel/telescope": "^4.6.6",
                                                                                                              "laravel/tinker": "^2.6.2",
                                                                                                              "livewire/livewire": "^2.7.2",
                                                                                                              "maatwebsite/excel": "^3.1.33",
                                                                                                              "mews/purifier": "^3.3.6",
                                                                                                              "spatie/laravel-medialibrary": "^9.0.0",
                                                                                                              "spatie/laravel-permission": "^5.3.1",
                                                                                                              "te7a-houdini/laravel-trix": "^2.0.5",
                                                                                                              "wboyz/laravel-enum": "^0.2.1"
                                                                                                          },
                                                                                                          "require-dev": {
                                                                                                              "barryvdh/laravel-debugbar": "^3.6.4",
                                                                                                              "spatie/laravel-ignition": "^1.0",
                                                                                                              "fakerphp/faker": "^1.16",
                                                                                                              "laravel/sail": "^1.12.3",
                                                                                                              "mockery/mockery": "^1.4.4",
                                                                                                              "nunomaduro/collision": "^6.1",
                                                                                                              "phpunit/phpunit": "^9.5.10"
                                                                                                          },
                                                                                                          "autoload": {
                                                                                                              "files": [
                                                                                                                  "app/Library/helper.php"
                                                                                                              ],
                                                                                                              "psr-4": {
                                                                                                                  "App\\": "app/",
                                                                                                                  "Database\\Factories\\": "database/factories/",
                                                                                                                  "Database\\Seeders\\": "database/seeders/"
                                                                                                              }
                                                                                                          },
                                                                                                          "autoload-dev": {
                                                                                                              "psr-4": {
                                                                                                                  "Tests\\": "tests/"
                                                                                                              }
                                                                                                          },
                                                                                                          "scripts": {
                                                                                                              "post-autoload-dump": [
                                                                                                                  "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                                                                                                                  "@php artisan package:discover --ansi",
                                                                                                                  "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
                                                                                                              ],
                                                                                                              "post-update-cmd": [
                                                                                                                  "@php artisan vendor:publish --tag=laravel-assets --ansi"
                                                                                                      
                                                                                                              ],
                                                                                                              "post-root-package-install": [
                                                                                                                  "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                              ],
                                                                                                              "post-create-project-cmd": [
                                                                                                                  "@php artisan key:generate --ansi"
                                                                                                              ]
                                                                                                          },
                                                                                                          "extra": {
                                                                                                              "laravel": {
                                                                                                                  "dont-discover": []
                                                                                                              }
                                                                                                          },
                                                                                                          "config": {
                                                                                                              "optimize-autoloader": true,
                                                                                                              "preferred-install": "dist",
                                                                                                              "sort-packages": true
                                                                                                          },
                                                                                                          "minimum-stability": "dev",
                                                                                                          "prefer-stable": true
                                                                                                      }
                                                                                                      

                                                                                                      and I do not see any illuminate* packages referenced in it...

                                                                                                      How that can be fixed ?

                                                                                                      Thanks!

                                                                                                      ANSWER

                                                                                                      Answered 2022-Feb-15 at 07:54

                                                                                                      Laravel 9 requires PHP 8.

                                                                                                      1. Delete the ^7.3| in composer.json at the line PHPThe correct syntax is: "php": "^8.0"

                                                                                                      2. Delete the v in composer.json at the line laravel/framework, The correct syntax is: "laravel/framework": "^9.0",

                                                                                                      3. And check the package's artesaos/seotools compatibility with the Laravel 9

                                                                                                      Source https://stackoverflow.com/questions/71122732

                                                                                                      QUESTION

                                                                                                      mockery::mock and mockery::stub do not work properly with quasiquotation?
                                                                                                      Asked 2022-Jan-31 at 20:39

                                                                                                      I've written an import function that gets a single file from an aws s3-bucket.

                                                                                                      That function itself is a wrapper around aws.s3::s3read_using() which takes a reading function as its first argument.

                                                                                                      Why do I wrap around aws.s3::s3read_using() ? Because I need to do some special error-handling and want the wrapping function to do some Recall() up to a limit... but that's a different story.

                                                                                                      Now that i've successfully build and tested my wrapping function i want to do another wrapping arround that:

                                                                                                      I want to iterate n times over my wrapper to bind the downloaded files together. I now have the difficulty to hand the 'reading_function' to the FUN argument of aws.s3::s3read_using().

                                                                                                      I could do that by simply using ... - BUT! I want to make clear to the USER of my wrapping wrapper, that he needs to specify that argument.

                                                                                                      So I've decided to use rlangs rlang::enexpr() to capture the argument and to hand it over to my first wrapper via !! - which in return captures that argument again with rlang::enexpr() and hands it over - finally - to aws.s3::s3read_using() via rlang::expr(aws.s3::s3read_using(FUN = !!reading_fn, object = s3_object))

                                                                                                      That works perfectly fine and smooth. My Problem is with testing that function construct using testthat and mockery

                                                                                                      Here is some broadly simplyfied code:

                                                                                                      my_workhorse_function <- function(fn_to_work_with, value_to_work_on) {
                                                                                                        fn <- rlang::enexpr(fn_to_work_with)
                                                                                                        # Some other magic happens here - error handling, condition-checking, etc...
                                                                                                        out <- eval(rlang::expr((!!fn)(value_to_work_on)))
                                                                                                      }
                                                                                                      
                                                                                                      my_iterating_function <- function(fn_to_iter_with, iterate_over) {
                                                                                                        fn <- rlang::enexpr(fn_to_iter_with)
                                                                                                        out <- list()
                                                                                                        for(i in seq_along(iterate_over)) {
                                                                                                          out[[i]] <- my_workhorse_function(!!fn, iterate_over[i])
                                                                                                        }
                                                                                                        return(out)
                                                                                                      }
                                                                                                      
                                                                                                      # Works just fine
                                                                                                      my_iterating_function(sqrt, c(9:16))
                                                                                                      

                                                                                                      Now, to the test:

                                                                                                      # Throws an ERROR: 'Error in `!fn`: invalid argument type'
                                                                                                      test_that("my_iterating_function iterates length(iterate_over) times over my_workhorse_function", {
                                                                                                        mock_1 <- mockery::mock(1, cycle = TRUE)
                                                                                                        stub(my_iterating_function, "my_workhorse_function", mock_1)
                                                                                                        expect_equal(my_iterating_function(sqrt, c(9:16)), list(1,1,1,1,1,1,1,1))
                                                                                                        expect_called(mock_1, 8)
                                                                                                      })
                                                                                                      

                                                                                                      I've used a workarround, but that just doesn't feel right, even though, it works:

                                                                                                      # Test passed
                                                                                                      test_that("my_iterating_function iterates length(iterate_over) times over my_workhorse_function", {
                                                                                                        mock_1 <- mockery::mock(1, cycle = TRUE)
                                                                                                        stub(my_iterating_function, "my_workhorse_function", 
                                                                                                             function(fn_to_work_with, value_to_work_on) {
                                                                                                               fn <- rlang::enexpr(fn_to_work_with)
                                                                                                               out <- mock_1(fn, value_to_work_on)
                                                                                                               out})
                                                                                                        expect_equal(my_iterating_function(sqrt, c(9:16)), list(1,1,1,1,1,1,1,1))
                                                                                                        expect_called(mock_1, 8)
                                                                                                      })
                                                                                                      

                                                                                                      I'm using version of R: 4.1.1 I'm using versions of testthat(3.1.1), mockery(0.4.2), rlang(0.4.12)

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-09 at 20:11

                                                                                                      I think you're complicating things here, although maybe I'm not fully understanding your end goal. You can directly pass functions through arguments without any issue. Your example code above can be easily simplified to (keeping the loop just to match your test_that() call):

                                                                                                      library(testthat)
                                                                                                      library(mockery)
                                                                                                      
                                                                                                      my_workhorse_function <- function(fn_to_work_with, value_to_work_on) {
                                                                                                        fn_to_work_with(value_to_work_on)
                                                                                                      }
                                                                                                      
                                                                                                      my_iterating_function <- function(fn_to_iter_with, iterate_over) {
                                                                                                        out <- list()
                                                                                                        for(i in seq_along(iterate_over)) {
                                                                                                          out[[i]] <- my_workhorse_function(fn_to_iter_with, iterate_over[i])
                                                                                                        }
                                                                                                        return(out)
                                                                                                      }
                                                                                                      
                                                                                                      # Works just fine
                                                                                                      my_iterating_function(sqrt, c(9:16))
                                                                                                      #> [[1]]
                                                                                                      #> [1] 3
                                                                                                      #> 
                                                                                                      #> ...
                                                                                                      
                                                                                                      test_that("my_iterating_function iterates length(iterate_over) times over my_workhorse_function", {
                                                                                                        mock_1 <- mockery::mock(1, cycle = TRUE)
                                                                                                        stub(my_iterating_function, "my_workhorse_function", mock_1)
                                                                                                        expect_equal(my_iterating_function(sqrt, c(9:16)), list(1,1,1,1,1,1,1,1))
                                                                                                        expect_called(mock_1, 8)
                                                                                                      })
                                                                                                      #> Test passed 🥇
                                                                                                      

                                                                                                      You can just pass FUN directly through all of your nested functions. The functions you're wrapping with enexpr() were never going to be evaluated in the first place until you explicitly call them. You usually use enexpr when users are supplying expressions, not just functions.

                                                                                                      Source https://stackoverflow.com/questions/70291177

                                                                                                      QUESTION

                                                                                                      Laravel model can't be named 'Match'
                                                                                                      Asked 2022-Jan-16 at 12:28

                                                                                                      I want to create a model in Laravel named 'Match'. When I try to do this, I get an error: syntax error, unexpected token "match", expecting identifier. When I add a character (for example: 'Matcha'), the error goes away.

                                                                                                      I am using this code in composer.json:

                                                                                                      "require": {
                                                                                                              "php": "^7.3|^8.0",
                                                                                                              "beyondcode/laravel-websockets": "^1.12",
                                                                                                              "fruitcake/laravel-cors": "^2.0",
                                                                                                              "guzzlehttp/guzzle": "^7.0.1",
                                                                                                              "laravel/framework": "^8.75",
                                                                                                              "laravel/sanctum": "^2.11",
                                                                                                              "laravel/tinker": "^2.5",
                                                                                                              "laravel/ui": "^3.4"
                                                                                                          },
                                                                                                          "require-dev": {
                                                                                                              "facade/ignition": "^2.5",
                                                                                                              "fakerphp/faker": "^1.9.1",
                                                                                                              "laravel/sail": "^1.0.1",
                                                                                                              "mockery/mockery": "^1.4.4",
                                                                                                              "nunomaduro/collision": "^5.10",
                                                                                                              "phpunit/phpunit": "^9.5.10"
                                                                                                          },
                                                                                                      

                                                                                                      I have tried to solve the problem, but I couldn't find any solutions on the internet.

                                                                                                      Is there a way I can solve this error?

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-16 at 12:28

                                                                                                      You are using PHP 8 and match is a reserved keyword in PHP 8.

                                                                                                      Refer reserved keywords.

                                                                                                      Source https://stackoverflow.com/questions/70729813

                                                                                                      QUESTION

                                                                                                      Is the code actually executed when using a Mockery spy?
                                                                                                      Asked 2022-Jan-10 at 19:35

                                                                                                      I am trying to write some tests with a Mockery Spy. However, it doesn't seem like the "spied upon" code is executed when I'm using a spy.

                                                                                                      Is the code actually executed when using a Mockery spy?

                                                                                                      Here is what I tested:

                                                                                                      // In my test:
                                                                                                      $spy = $this->spy(FeedManager::class);
                                                                                                      
                                                                                                      // Controller
                                                                                                      resolve(FeedManager::class)->createResponse();
                                                                                                      
                                                                                                      // FeedManger::createResponse()
                                                                                                      public static function createResponse(Builder $builder)
                                                                                                      {
                                                                                                        dd("here i am"); // this never gets called unless I remove the spy
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2022-Jan-10 at 19:35

                                                                                                      Apparently, the "spy code" is not supposed to run. Found this quote from the docs.

                                                                                                      The \Mockery::spy() method call is actually a shorthand for calling \Mockery::mock()->shouldIgnoreMissing(). The shouldIgnoreMissing method is a “behaviour modifier”.

                                                                                                      Source https://stackoverflow.com/questions/70656434

                                                                                                      QUESTION

                                                                                                      Heroku deploy failure, requested package composer-plugin-api could not be found in any version
                                                                                                      Asked 2021-Dec-30 at 08:58
                                                                                                      -----> Building on the Heroku-20 stack
                                                                                                      -----> Using buildpack: heroku/php
                                                                                                      -----> PHP app detected
                                                                                                      -----> Bootstrapping...
                                                                                                      -----> Installing platform packages...
                                                                                                       !     ERROR: Failed to install system packages!
                                                                                                       !     
                                                                                                       !     Your platform requirements (for runtimes and extensions) could
                                                                                                       !     not be resolved to an installable set of dependencies, or a
                                                                                                       !     platform package repository was unreachable.
                                                                                                       !     
                                                                                                       !     This usually means that you (or packages you are using) depend
                                                                                                       !     on a combination of PHP versions and/or extensions that are
                                                                                                       !     currently not available on Heroku.
                                                                                                       !     
                                                                                                       !     The following is the full output from the installation attempt:
                                                                                                       !     
                                                                                                       !     > You are using Composer 1 which is deprecated. You should upgrade to Composer 2, see https://blog.packagist.com/deprecating-composer-1-support/
                                                                                                       !     > Loading repositories with available runtimes and extensions
                                                                                                       !     > Updating dependencies
                                                                                                       !     > Your requirements could not be resolved to an installable set of packages.
                                                                                                       !     > 
                                                                                                       !     >   Problem 1
                                                                                                       !     >     - The requested package composer-plugin-api could not be found in any version, there may be a typo in the package name.
                                                                                                       !     > 
                                                                                                       !     
                                                                                                       !     For reference, the following runtimes are currently available:
                                                                                                       !     
                                                                                                       !     PHP:  8.1.1, 8.1.0, 8.0.14, 8.0.13, 8.0.12, 8.0.11, 8.0.10, 
                                                                                                       !     8.0.9, 8.0.8, 8.0.7, 8.0.6, 8.0.3, 8.0.2, 8.0.1, 8.0.0, 
                                                                                                       !     8.0.0RC4, 7.4.27, 7.4.26, 7.4.25, 7.4.24, 7.4.23, 7.4.22, 
                                                                                                       !     7.4.21, 7.4.20, 7.4.19, 7.4.16, 7.4.15, 7.4.14, 7.4.13, 
                                                                                                       !     7.4.12, 7.3.33, 7.3.32, 7.3.31, 7.3.30, 7.3.29, 7.3.28, 
                                                                                                       !     7.3.27, 7.3.26, 7.3.25, 7.3.24
                                                                                                       !     
                                                                                                       !     Please verify that all requirements for runtime versions in
                                                                                                       !     'composer.lock' are compatible with the list above, and ensure
                                                                                                       !     all required extensions are available for the desired runtimes.
                                                                                                       !     
                                                                                                       !     When choosing a PHP runtimes and extensions, please also ensure
                                                                                                       !     they are available on your app's stack (heroku-20), and select
                                                                                                       !     a different stack if needed after consulting the article below.
                                                                                                       !     
                                                                                                       !     For a list of supported runtimes & extensions on Heroku, please
                                                                                                       !     refer to: https://devcenter.heroku.com/articles/php-support
                                                                                                       !     Push rejected, failed to compile PHP app.
                                                                                                       !     Push failed
                                                                                                      

                                                                                                      Coeds above are the error I am getting when I deploy the app, the app runs perfectly fine locally, I am not sure what happened during the deployment.

                                                                                                      composer.json

                                                                                                      {
                                                                                                          "name": "laravel/laravel",
                                                                                                          "type": "project",
                                                                                                          "description": "The Laravel Framework.",
                                                                                                          "keywords": ["framework", "laravel"],
                                                                                                          "license": "MIT",
                                                                                                          "require": {
                                                                                                              "php": "^8.1.1",
                                                                                                              "composer-plugin-api": "^2.2",
                                                                                                              "dcat/laravel-admin": "^1.7",
                                                                                                              "fruitcake/laravel-cors": "^2.0",
                                                                                                              "guzzlehttp/guzzle": "^7.0.1",
                                                                                                              "laravel/framework": "^8.75",
                                                                                                              "laravel/sanctum": "^2.11",
                                                                                                              "laravel/tinker": "^2.5"
                                                                                                          },
                                                                                                          "require-dev": {
                                                                                                              "facade/ignition": "^2.5",
                                                                                                              "fakerphp/faker": "^1.9.1",
                                                                                                              "laravel/sail": "^1.0.1",
                                                                                                              "mockery/mockery": "^1.4.4",
                                                                                                              "nunomaduro/collision": "^5.10",
                                                                                                              "phpunit/phpunit": "^9.5.10",
                                                                                                              "composer/composer": "^2.0"
                                                                                                          },
                                                                                                          "autoload": {
                                                                                                              "psr-4": {
                                                                                                                  "App\\": "app/",
                                                                                                                  "Database\\Factories\\": "database/factories/",
                                                                                                                  "Database\\Seeders\\": "database/seeders/"
                                                                                                              }
                                                                                                          },
                                                                                                          "autoload-dev": {
                                                                                                              "psr-4": {
                                                                                                                  "Tests\\": "tests/"
                                                                                                              }
                                                                                                          },
                                                                                                          "scripts": {
                                                                                                              "post-autoload-dump": [
                                                                                                                  "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                                                                                                                  "@php artisan package:discover --ansi"
                                                                                                              ],
                                                                                                              "post-update-cmd": [
                                                                                                                  "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
                                                                                                              ],
                                                                                                              "post-root-package-install": [
                                                                                                                  "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                                                                                                              ],
                                                                                                              "post-create-project-cmd": [
                                                                                                                  "@php artisan key:generate --ansi"
                                                                                                              ]
                                                                                                          },
                                                                                                          "extra": {
                                                                                                              "laravel": {
                                                                                                                  "dont-discover": []
                                                                                                              }
                                                                                                          },
                                                                                                          "config": {
                                                                                                              "optimize-autoloader": true,
                                                                                                              "preferred-install": "dist",
                                                                                                              "sort-packages": true
                                                                                                          },
                                                                                                          "minimum-stability": "dev",
                                                                                                          "prefer-stable": true
                                                                                                      }
                                                                                                      

                                                                                                      Error 1

                                                                                                      The requested package composer-plugin-api could not be found in any version, there may be a typo in the package name.

                                                                                                      Error 2

                                                                                                      I am using Composer version 2.2.1, why it shows that i am using composer 1 during the deployment?

                                                                                                      Error 3

                                                                                                      In the composer.json file, I have required PHP 8.1.1, why does it still say that I am not using the correct version?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-30 at 08:58

                                                                                                      It looks like the Heroku server your are using for deploying your application does not support the composer version used locally. As you are using heroku-20, make sure you use Composer 1.10.* or 2.1.*

                                                                                                      My assumption is that you updated Composer to 2.2.x which may not be supported at the moment. You should temporarily downgrade to Composer 2.1.14 then run composer update again.

                                                                                                      composer self-update --rollback
                                                                                                      composer -v # Make sure the version is 2.1.*
                                                                                                      composer update
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/70495907

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install mockery

                                                                                                      To install Mockery, run the command below and you will get the latest version.

                                                                                                      Support

                                                                                                      In older versions, this README file was the documentation for Mockery. Over time we have improved this, and have created an extensive documentation for you. Please use this README file as a starting point for Mockery, but do read the documentation to learn how to use Mockery. The current version can be seen at [docs.mockery.io](http://docs.mockery.io).
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit
                                                                                                      CLONE
                                                                                                    • HTTPS

                                                                                                      https://github.com/mockery/mockery.git

                                                                                                    • CLI

                                                                                                      gh repo clone mockery/mockery

                                                                                                    • sshUrl

                                                                                                      git@github.com:mockery/mockery.git

                                                                                                    • Share this Page

                                                                                                      share link

                                                                                                      Explore Related Topics

                                                                                                      Consider Popular Mock Libraries

                                                                                                      faker.js

                                                                                                      by Marak

                                                                                                      Faker

                                                                                                      by fzaninotto

                                                                                                      Mock

                                                                                                      by nuysoft

                                                                                                      faker

                                                                                                      by joke2k

                                                                                                      nock

                                                                                                      by nock

                                                                                                      Compare Mock Libraries with Highest Support

                                                                                                      faker

                                                                                                      by joke2k

                                                                                                      Faker

                                                                                                      by fzaninotto

                                                                                                      wiremock

                                                                                                      by tomakehurst

                                                                                                      faker

                                                                                                      by faker-ruby

                                                                                                      powermock

                                                                                                      by powermock

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit