HypervelHypervel
Hypervel
Documentation
GitHub
Hypervel
Documentation
GitHub
  • Documentation

    • Prologue

      • Contributing Guide
    • Getting Started

      • Introduction
      • Installation
      • Configuration
      • Directory Structure
      • Deployment
    • Architecture Concepts

      • Request Lifecycle
      • Service Container
      • Service Providers
      • Facades
    • The Basics

      • Routing
      • Middleware
      • CSRF Protection
      • Controllers
      • Requests
      • Responses
      • Views
      • Blade Templates
      • URL Generation
      • Session
      • Validation
      • Error Handling
      • Logging
    • Digging Deeper

      • Artisan Console
      • Broadcasting
      • Cache
      • Collections
      • Context
      • Coroutine
      • Contracts
      • Events
      • File Storage
      • Helpers
      • HTTP Client
      • Localization
      • Mail
      • Notifications
      • Package Development
      • Package Porting
      • Processes
      • Queues
      • Rate Limiting
      • Strings
      • Task Scheduling
    • Security

      • Authentication
      • Authorization
      • Encryption
      • Hashing
    • Database

      • Getting Started
      • Query Builder
      • Pagination
      • Migrations
      • Seeding
      • Redis
    • Eloquent ORM

      • Getting Started
      • Relationships
      • Collections
      • Mutators / Casts
      • API Resources
      • Serialization
      • Factories
    • Testing

      • Getting Started
      • HTTP Tests
      • Console Tests
      • Database
      • Mocking
      • Packages Toolkit

Packages Toolkit: Testbench

  • Introduction
  • Installation
  • Configuration
  • Basic Usages
    • Hypervel Skeleton
    • Service Providers
    • Exclude Packages
    • Environment Variables
  • Getting Started
    • PHPUnit Configuration

Introduction

Packages Toolkit for Hypervel is a collection of packages that have been designed to write, test, and preview your Hypervel packages.

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

Installation

To start using Packages Toolkit for Hypervel you can first install the components:

composer require --dev hypervel/testbench

Configuration

The Packages Toolkit for Hypervel uses testbench.yaml as a configuration file where you can define the following schemas to be used within Workbench environment:

NameTypeDescription
hypervelstringSet the path to Hypervel skeleton.
providersarrayList of Service Provider classes to be loaded.
dont-discoverarrayList of packages to be ignored.
envarraySet environment variables to be loaded.
purgearrayConfigurable files and directories to be pruned after executing test cases.
workbenchObjectSee Workbench configuration for details.

Basic Usages

For the testbench command to understand any required service providers, bootstrappers, environment variables or other options to be used when executing the "artisan" command you need to add the following testbench.yaml file on the project root directory.

providers:
  - Hypervel\Package\PackageServiceProvider

dont-discover:
  - hypervel/sanctum

Hypervel Skeleton

You can use hypervel configuration key to set a custom location instead of using the default vendor/hypervel/testbench/workbench:

hypervel: ./workbench

To publish the skeleton folder, you can run the following command:

vendor/bin/testbench-sync workbench

Service Providers

You can use providers configuration key to set an array of service providers to be loaded additionally:

providers:
  - Hypervel\Sanctum\SanctumServiceProvider
  - Workbench\App\Providers\WorkbenchServiceProvider

Exclude Packages

To exclude specific packages, you can also use dont-discover to exclude specific packages from being loaded:

dont-discover:
  - hypervel/html

Environment Variables

You can use env configuration key to set an array of environment variables to be loaded:

env:
  - SEND_QUERIES_TO_RAY=(false)

Warning

The env environment variables are only applied when using the CLI and will not be used when running tests.

Workbench Discovery Configuration

The discovers configuration allows Workbench to discover routes and commands.

NameTypeDescription
webboolEnabling the options allows Workbench to register routes from workbench/routes/web.php
apiboolEnabling the options allows Workbench to register routes from workbench/routes/api.php
commandsboolEnabling the options allows Workbench to register console commands from workbench/routes/console.php

Example

workbench:
  discovers:
    web: true
    api: false
    commands: false

Getting Started

To use Testbench Component, all you need to do is extend Hypervel\Testbench\TestCase instead of PHPUnit\Framework\TestCase. The fixture app booted by Hypervel\Testbench\TestCase is predefined to follow the base application skeleton of Hypervel.

class TestCase extends \Hypervel\Testbench\TestCase
{
    //
}

PHPUnit Configuration

You can separate your tests in your phpunit.xml file by providing different test suites, allowing you to run your Feature tests on demand.

For example:

<testsuites>
    <testsuite name="Feature">
        <directory suffix="Test.php">./tests/Feature</directory>
    </testsuite>
    <testsuite name="Unit">
        <directory suffix="Test.php">./tests/Unit</directory>
    </testsuite>
</testsuites>

Run only your feature tests by running PHPUnit with the --testsuite=Feature option.

vendor/bin/phpunit --testsuite=Feature
Edit this page
Last Updated:
Contributors: Albert Chen
Prev
Mocking