Download the PHP package soyhuce/laravel-embuscade without Composer

On this page you can find all versions of the php package soyhuce/laravel-embuscade. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-embuscade

Test Laravel views in isolation

Inspired by nunomaduro/laravel-mojito

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status GitHub PHPStan Action Status Total Downloads

Test your Laravel views in isolation, interacting directly with the HTML.

Installation

You can install the package via composer:

Usage

Accessing view expectations

The most basic way to access the ViewExpect is to create it with an HTML string :

As this is not the most convenient way, you can create the ViewExpect from various objects:

If you use Livewire, you can also create a ViewExpect from a Livewire test component:

Navigating the view

Once the ViewExpect is created, you can navigate the view using the following methods:

$cssSelector must be any valid CSS selector, like .class, #id, tag, tag.class, tag#id, tag[attr=value], etc.

Note : Some pseudo-classes and pseudo-elements are not supported, like :hover, :before, :after, :has, etc.

Embuscade selectors

You can also use Embuscade selectors to navigate the view as navigating CSS selectors can be cumbersome:

You can also use the @embuscade directive to generate Embuscade selectors in your blade views:

The data-embuscade attribute will be added to the element, only on testing environment or is debug mode is enabled.

Note : Because @embuscade is not really a blade directive, it requires use of single quotes ' to work and won't have access to execution context. @embuscade("login-button") will not work.

will not work either.

You can customize the HTML attribute Embuscade will use for the selectors using selectorHtmlAttribute method:

In production

If you run in production without dev-dependencies installed, you will need an extra setup in order to remove @embuscade directives from your views.

In your AppServiceProvider::boot method, you can add the following code:

There won't be any overhead here as cached views won't contain any @embuscade directive.

Note : if you run in production with your dev-dependencies installed, you should definitively consider removing them.

Expectations

Expectations on entire view

Some expectations will be applied to the entire view:

Expectations on current element

Other expectation will only look at current root:

Some helpers are also available for you:

Negating expectation

You can negate any expectation by calling not before the expectation:

The negation will only apply to the next expectation.

Navigating and expectations on elements

You can navigate and apply expectations on elements in a single chain, in order to not loose focus on the current element: Given the following HTML:

you can test it with the following code:

Every selection method will allow you to pass a closure that will receive a new ViewExpect, focused on the selected element.

Customization

The ViewExpect class is macroable, so you can add your own expectations:

Debugging

You can dump the current state of the ViewExpect using the dump or dd methods:

It will dump the current HTML node.

WTF is Embuscade ?

Embuscade is a French word meaning ambush. It makes reference to the original package name, Laravel Mojito, as "une embuscade" is also a famous local cocktail from Caen.

Each bar has its own recipe, but it could be something like:

Easy to drink but quite strong, be careful not to fall into the ambush!

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-embuscade with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-dom Version *
illuminate/contracts Version ^12.0
illuminate/testing Version ^12.0
spatie/laravel-package-tools Version ^1.16
symfony/css-selector Version ^7.2
symfony/dom-crawler Version ^7.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package soyhuce/laravel-embuscade contains the following files

Loading the files please wait ....