Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package

Overview

Laravel Testing Helper for Packages Development

Testbench Component is the de-facto package that has been designed to help you write tests for your Laravel package.

Before going through the rest of this documentation, please take some time to read the Package Development section of Laravel's own documentation, if you haven't done so yet.

tests Latest Stable Version Total Downloads License

Official Documentation

Documentation for Testbench can be found on the packages.tools/testbench.

Contributing

Thank you for considering contributing to Testbench! You can read the contribution guide here.

Code of Conduct

In order to ensure that the community is welcoming to all, please review and abide by the Code of Conduct.

License

Testbench is open-sourced software licensed under the MIT license.

Comments
  • [Proposal] Support for Behat

    [Proposal] Support for Behat

    Hello, I'm starting to use Behat for some functional testing and would love to be able to boot a Laravel app from this package and use it with Behat. This package being the de-facto standard for testing Laravel packages, seems like a good fit for such feature. If you don't plan on having said feature I would then like, with your consent, to take inspiration from your package to implement my own.

    enhancement open for contribution 
    opened by lucadegasperi 26
  • Unable to fully swap base path on Laravel 5

    Unable to fully swap base path on Laravel 5

    Hello, I'm trying to run my tests, that are creating a folder. I use the following to define the wanted path:

    $this->testModulePath = __DIR__ . "/../Modules/{$this->testModuleName}";
    

    When I dump this using dd I get : "/Users/nicolaswidart/Sites/Asguard/IndividualModules/Workshop/Tests/../Modules/TestingTestModule", which is correct.

    Though when calling an artisan command that is suppose to generate it, it makes it under vendor/orchestra/testbench/fixtures/Modules/TestingTestModule

    This is my getEnvironmentSetUp method:

    protected function getEnvironmentSetUp($app)
    {
        $app['path.base'] = __DIR__ . '/..';
    }
    

    Did I miss something ?

    Thanks!

    question 
    opened by nWidart 25
  • Writing a package and getting 'Session not set on request'

    Writing a package and getting 'Session not set on request'

    My package uses views with forms in it. I am using old() to get the old input if I send it back to the form. When I do this and try to run my tests I am getting the message Session not set on request

    I am using v3.1 with Laravel 5.1

    I have tried the following.

        protected function getEnvironmentSetUp($app)
        {
            $app['request']->setSession($app['session']->driver('array'));
        }
    

    No luck!

    What do I need to do?

    bug 
    opened by bretterer 20
  • SQLSTATE[HY000] [2002] Connection refused

    SQLSTATE[HY000] [2002] Connection refused

    • Testbench Version: 7.12.1

    Description

    Hi,

    After I got the updated testbench version, I can not execute some commands successfully. For example, the following command throwing the error SQLSTATE[HY000] [2002] Connection refused.

    vendor/bin/testbench migrate --database=sqlite --path=vendor/orchestra/testbench-core/laravel/migrations --path=../../../../database/migrations

    I have set my own testbench.yaml file with the following database configuration but it seems that testbench-core ignores them.

    DB_CONNECTION="sqlite" DB_DATABASE="database.sqlite"

    How can I set the DB_CONNECTION parameter in testbench-core ? Is it possible to change the default configuration settings of testbench using any commands option?

    opened by KarinaRashchynskaya 18
  • Factories not working correctly, results in call to a member function define on null error.

    Factories not working correctly, results in call to a member function define on null error.

    Using factories does not work as intended in tests. Trying to call a factory results in the following error: Fatal error: Uncaught Error: Call to a member function define() on null

    This is for orchestra v3.8

    These are the TestCase, Test and factory files being used.

    namespace Tests;
    
    use Orchestra\Testbench\Concerns\WithFactories;
    use Orchestra\Testbench\TestCase as BaseTestCase;
    
    class TestCase extends BaseTestCase
    {
        use WithFactories;
    
        protected function setUp(): void
        {
            parent::setUp();
    
            $this->withFactories(__DIR__.'/../src/database/factories');
        }
    
        protected function getPackageProviders($app): array
        {
            return [
                // providers
            ];
        }
    
        protected function getPackageAliases($app)
        {
            return [
                // aliases
            ];
        }
    }
    
    namespace Tests\Feature;
    
    use App\User;
    use Tests\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    
    class UserTest extends TestCase
    {
        use WithFaker;
    
        private $user;
    
        public function setUp(): void
        {
            parent::setUp();
    
            $this->artisan('migrate');
    
            $this->user = factory(User::class)->create();
        }
    }
    
    /** @var \Illuminate\Database\Eloquent\Factory $factory */
    use App\User;
    use Illuminate\Support\Str;
    use Faker\Generator as Faker;
    
    $factory->define(User::class, function (Faker $faker) {
        return [
            'first_name' => $faker->firstName,
            'last_name' => $faker->lastName,
            'email' => $faker->unique()->safeEmail,
            'email_verified_at' => now(),
            'password' => '', // password
            'remember_token' => Str::random(10),
        ];
    });
    

    Can you tell me what could possibly be wrong here? Is this an implementation error or a bug in orchestra itself?

    question 
    opened by maikelmotivo 17
  • Fatal Error: cannot redeclare class... when running parent app with orchestra\testbench in workbench

    Fatal Error: cannot redeclare class... when running parent app with orchestra\testbench in workbench

    I'm writing a package from the workbench. Orchestra\Testbench works great, and I have no trouble running my tests from the command line using phpunit.

    However, if I try to visit the parent app in the browser I get a fatal error:

    Fatal error: Cannot redeclare crypt_random_string() (previously declared in 
    /path/to/myapp/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php:61) in 
    /path/to/myapp/workbench/morphatic/qualtrics/vendor/phpseclib/phpseclib/phpseclib/Crypt/Random.php on line 246
    

    Pretty sure the problem is that the parent app is trying to load Laravel again from the workbench. Is there a setting or workaround to prevent this?

    bug 
    opened by morphatic 17
  • getRoutes() not found in Router mock object

    getRoutes() not found in Router mock object

    One of my tests fails with this message:

    1) ViewTest::testCreateWithLocale
    BadMethodCallException: Method Mockery_0_Illuminate_Routing_Router::getRoutes() does not exist on this mock object
    
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php:45
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:290
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:773
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:656
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:642
    .../aimeos-laravel/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:53
    .../aimeos-laravel/src/Aimeos/Shop/Base/View.php:54
    .../aimeos-laravel/tests/Base/ViewTest.php:33
    

    It worked when the package was part of an application but since using the testbench package it fails. What could be the cause for this?

    The test code is available at https://github.com/aimeos/aimeos-laravel/blob/master/tests/Base/ViewTest.php#L15-L34

    question 
    opened by aimeos 16
  • Moved the environment setup

    Moved the environment setup

    I propose call getEnvironmentSetUp earlier so that people can make config modifications before all the service providers have booted.

    ~~If you want, I could put it here instead?~~ DONE

    $app->make('Illuminate\Foundation\Bootstrap\RegisterProviders')->bootstrap($app);
    $this->getEnvironmentSetUp($app);
    $app->make('Illuminate\Foundation\Bootstrap\BootProviders')->bootstrap($app);
    
    enhancement 
    opened by GrahamCampbell 15
  • Orchestra database version not exists

    Orchestra database version not exists

    Exception: Missing orchestra/database in composer.json

    "require": {
        "php": "^5.6|^7.0",
        "illuminate/database": "~5.2.0|~5.3.0|~5.4.0",
        "illuminate/support": "~5.2.0|~5.3.0|~5.4.0"
    },
    "require-dev": {
        "orchestra/testbench": "~3.0",
        "phpunit/phpunit": "^5.2"
    },
    

    Latest version of test bench require "orchestra/database": "~3.4.0", but latest release is 3.3.5!

    opened by antonkomarev 14
  • Created classes not found

    Created classes not found

    Hi there,

    I currently develop a package that writes some class files in a laravel application to speed up development.

    When trying to test this, the class file will be written to vendor/testbench-core/fixtures/app. So after generation I have a class FooBar in vendor/testbench-core/fixtures/app/FooBar.php with namespace App.

    Checking if file was written works like this

    $this->assertFileExists(base_path('/app/FooBar.php'));
    

    I now want to write the test if the generated class can be used (and other method tests for this generated class) to verify the correctness of the class stub. When I use

    $foobar = new \App\FooBar();
    $this->assertInstanceOf('App/FooBar', $foobar);
    

    I get an error that the class \App\FooBar is not found.

    How can I instantiate the class? Do I need some special composer autoload setup? Or should this be tested with a real and complete Laravel application?

    Appreciate your help :)

    opened by OliverZiegler 13
  • Update Exceptionhandler to match laravel/framework 5.2 Exception Handler

    Update Exceptionhandler to match laravel/framework 5.2 Exception Handler

    Hello,

    Thank you for all the work you have done on this fantastic package - it is really magnificent and super helpful.

    I am in the process of upgrading one of my packages to be compatible with Laravel 5.2 and some of the integration tests look for validation errors to be triggered, Those errors seem to be handled differently in 5.2 than they were in 5.1 and this PR is intended to update the TestBench exception handler to match the new 5.2 framework exception handler.

    Feel free to ignore this if you would prefer a different method - any advice you have would be appreciated.

    Thanks!

    enhancement nice to have 
    opened by rydurham 13
Releases(v7.18.0)
  • v7.18.0(Jan 4, 2023)

    Changes

    Testbench Changes

    Added
    • Added Orchestra\Testbench\laravel_version_compare function as alias to version_compare specifically for Laravel Framework.
    • Added Orchestra\Testbench\phpunit_version_compare function as alias to version_compare specifically for PHPUnit.
    • Added Orchestra\Testbench\Exceptions\PHPUnitErrorException class.
    Changes
    • Mark Orchestra\Testbench\Bootstrap\ConfigureRay class as final.
    • Refactor Orchestra\Testbench\Concerns\HandlesAnnotations trait.
    Source code(tar.gz)
    Source code(zip)
  • v7.17.0(Dec 22, 2022)

  • v7.16.0(Dec 17, 2022)

    Changes

    Testbench Changes

    Added
    • Added resolveApplicationEnvironmentVariables() method.
    • Added Orchestra\Testbench\Bootstrap\HandleExceptions bootstrap to allow catching deprecation errors during tests.
      • Throws Orchestra\Testbench\Exceptions\DeprecatedException exception when deprecation occured.
      • Set logging.deprecations.trace to true.
      • Set deprecations log file to storage/logs/deprecations.log when LOG_DEPRECATIONS_CHANNEL=single.
    Changes
    • Bump minimum laravel/framework to 9.44.0.
    Source code(tar.gz)
    Source code(zip)
  • v7.15.0(Nov 29, 2022)

  • v7.14.1(Nov 29, 2022)

  • v7.14.0(Nov 22, 2022)

    Changes

    Testbench Changes

    Added
    • Added Orchestra\Testbench\Exceptions\ApplicationNotAvailableException exception when trying to access $this->app outside of booted application.
    • Added tests/CreatesApplication.php to skeleton.
    Changes
    • Update skeleton to match v9.3.11.
    Source code(tar.gz)
    Source code(zip)
  • v7.13.0(Nov 14, 2022)

  • v7.12.1(Nov 12, 2022)

    Changes

    Testbench Changes

    Fixes
    • Fixes where the default database connection as sqlite causes an exception when the database file isn't available. The loaded application should revert to testing database connection for the state.
    Source code(tar.gz)
    Source code(zip)
  • v7.12.0(Nov 12, 2022)

    Changes

    Testbench Changes

    Added
    • Added support for about artisan command.
    • Added package:devtool to generate .env, testbench.yaml and database.sqlite file.
    • Added package:create-sqlite-db and package:drop-sqlite-db command.
    • Improves support for serve command.
    Source code(tar.gz)
    Source code(zip)
  • v7.11.0(Oct 19, 2022)

    Changes

    Testbench Changes

    Added
    • Added Orchestra\Testbench\Foundation\Application::createVendorSymlink() method.
      • The feature uses Orchestra\Testbench\Foundation\Bootstrap\CreateVendorSymlink.
    Changes
    • Bump minimum laravel/framework to 9.36.0
      • Forget View Component's cache and factory between tests.
    Source code(tar.gz)
    Source code(zip)
  • v7.10.2(Oct 15, 2022)

  • v7.10.1(Oct 11, 2022)

  • v7.10.0(Oct 11, 2022)

  • v6.25.1(Oct 11, 2022)

  • v7.9.0(Oct 5, 2022)

    Changes

    Testbench Changes

    Added
    • Added draft support for PHP 8.2.
    Changes
    • Bump minimum laravel/framework to 9.34.0.
    • Bump minimum mockery/mockery to 1.5.1.
    • Bump minimum symfony dependencies to 6.0.9.
    Source code(tar.gz)
    Source code(zip)
  • v7.8.1(Oct 4, 2022)

  • v7.8.0(Sep 28, 2022)

  • v7.7.1(Sep 28, 2022)

  • v7.7.0(Aug 24, 2022)

    Changes

    Testbench Changes

    Added
    • Added loadLaravelMigrationsWithoutRollback() and runLaravelMigrationsWithoutRollback() helpers.
    Changes
    • Update skeleton to match v9.3.5.
    Source code(tar.gz)
    Source code(zip)
  • v6.25.0(Aug 24, 2022)

  • v7.6.1(Aug 10, 2022)

  • v7.6.0(Jun 30, 2022)

  • v7.5.0(May 10, 2022)

  • v7.4.0(Apr 13, 2022)

    Changes

    Testbench Changes

    Changes
    • Bump minimum laravel/framework to 9.7.0.
    • Add support for --drop-databases on package:test command.
    • Update skeleton to match v9.1.5.
    Source code(tar.gz)
    Source code(zip)
  • v7.3.0(Apr 2, 2022)

  • v7.2.0(Mar 20, 2022)

  • v7.1.0(Feb 23, 2022)

    Changes

    Testbench Changes

    Changes
    • Bump minimum laravel/framework to 9.2.
    • Remove Laravel 9 beta compatibilities codes.
    Removed
    • Remove sanctum.php configuration from skeleton.
    Source code(tar.gz)
    Source code(zip)
  • v7.0.2(Feb 16, 2022)

  • v7.0.1(Feb 14, 2022)

  • v7.0.0(Feb 8, 2022)

    Changes

    • Update support for Laravel Framework v9.
    • Increase minimum PHP version to 8.0 and above (tested with 8.0 and 8.1).

    Testbench Changes

    Added
    • Allows customizing default RateLimiter configuration via resolveApplicationRateLimiting() method.
    • Added Orchestra\Testbench\Http\Middleware\PreventRequestsDuringMaintenance middleware.
    Changes
    • Update support for Laravel Framework v9.
    • Increase minimum PHP version to 8.0 and above (tested with 8.0 and 8.1).
    • $loadEnvironmentVariables property is now set to true by default.
    • Following internal classes has been marked as final:
      • Orchestra\Testbench\Bootstrap\LoadConfiguration
      • Orchestra\Testbench\Console\Kernel
      • Orchestra\Testbench\Http\Kernel
    • Moved resources/lang skeleton files to lang directory.
    Removed
    • Remove deprecated Illuminate\Foundation\Testing\Concerns\MocksApplicationServices trait.
    Source code(tar.gz)
    Source code(zip)
Owner
Orchestra Platform
Orchestra Platform provide all the boilerplate for your application, so you can create awesomeness.
Orchestra Platform
laravel package help you to implement geographical calculation, with several algorithms that help you deal with coordinates and distances.

Geographical Calculator Geographical Calculator was developed for laravel 5.8+ to help you to implement geographical calculation, with With several al

karam mustafa 342 Dec 31, 2022
You already have your dream house? Sam Building will help you find the perfect home.

SAM BUILDING Setup Fork or clone this repo! git clone github.com/Igorballo/Real-Estate-App.git Installation des dépendances npm install #or yarn insta

null 4 Nov 29, 2022
Electrik is a full-featured, open-source, starter-kit to help you build you your SaaS application.

Electrik Electrik is a full-featured and open-source stater-kit for for your next SaaS application. It's built on top of Laravel, Livewire, neerajsoha

Electrik 129 Dec 31, 2022
Simple Arabic Laravel Dashboard , has basic settings and a nice layout . to make it easy for you to create fast dashboard

Simple Arabic Laravel Dashboard ✅ Auto Seo ✅ Optimized Notifications With Images ✅ Smart Alerts ✅ Auto Js Validations ✅ Front End Alert ✅ Nice Image V

Peter Tharwat 254 Dec 19, 2022
This package provides a trait to run your tests against a MinIO S3 server.

Laravel MinIO Testing Tools This package provides a trait to run your tests against a MinIO S3 server. ?? Blog post: https://protone.media/en/blog/how

Protone Media 7 Oct 12, 2022
Laravel-veneer - A suite of mocked services to use in your Laravel tests.

Laravel Veneer A suite of fixture data and methods to help make mocking 3rd party services easier. Overview Laravel Veneer aims to solve two problems

Oh See Software 4 Jun 23, 2022
Relational Metrics - lararvel package help you to make your metrics easier

Relational Metrics This package will help you to make your metrics easier, You could get metrics about your Models, Models depending on their relation

Syrian Open Source 25 Oct 12, 2022
This package aims to help you standardize all your API responses in a simple and structured way.

Laravel API Response This package aims to help you standardize all your API responses in a simple and structured way. By default, the stucture of the

Kode Pandai 6 Dec 6, 2022
Renamify is a package for Laravel used to rename a file before uploaded to prevent replacing exists file which has the same name to this new uploaded file.

Renamify Laravel package for renaming file before uploaded on server. Renamify is a package for Laravel used to rename a file before uploaded to preve

MB'DUSENGE Callixte 2 Oct 11, 2022
Perform Self-Diagnosis Tests On Your Laravel Application

Perform Self-Diagnosis Tests On Your Laravel Application This package allows you to run self-diagnosis tests on your Laravel application. It comes wit

Beyond Code 1.4k Dec 13, 2022
Chrome extension to generate Laravel integration tests while using your app.

Laravel TestTools Check out the introduction post about the chrome extension. Installation git clone [email protected]:mpociot/laravel-testtools.git # i

Marcel Pociot 473 Nov 1, 2022
A simple validator package to check if the given zipcode has a valid Dutch zipcode format

Laravel Dutch Zipcode Validator A simple validator package to check if the given zipcode has a valid Dutch zipcode format Table of Contents Installati

Tim Wassenburg 0 May 30, 2022
Decorate Your Models and Write Clean/Reusable Code with Presenters.

Laravel Presenter A clean way to present your model attributes without putting them in the wrong file. Installation You can install the package via co

Coderflex 14 Dec 19, 2022
this package can help you to test race condition in Laravel Feature Test

Laravel Async Testing this package can help you to test race condition in Laravel Feature Test Requirements Laravel versions 5.7, 6.x, 7.x and 8.x PHP

Recca Tsai 61 Nov 5, 2022
a Laravel package help you to execute more effective databases queries.

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimizing sql queries, this package will contain all advanced sq

karam mustafa 9 Jul 26, 2022
This package should help you with creating and managing a Laravel DDD Application

This package should help you with creating and managing a Laravel DDD Application. This package is heavily inspired by "Laravel beyond CRUD" from Spatie.

J. Regner 158 Dec 25, 2022
Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries

Laravel Query Helper Laravel Query Helper was developed for laravel 7.2+ to help you optimize sql queries, this package will contain all advanced SQL

Syrian Open Source 15 Nov 20, 2022
If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

hirwa-products-plugin If you are beginner in WordPress plugin development or if you want to develop your own store product plugin you use this plugin

NIYIBIZI HIRWA 1 Aug 23, 2022
Fully customizable and tests supported Laravel admin dashboard for developers.

Laravel Admin dashboard Like Laravel Jetstream but built with Hotwire Turbo + additional perks. Tools used: tailwindcomponents/dashboard Hotwire Turbo

null 12 Nov 1, 2022