Download the PHP package thatsus/laravel-better-bind without Composer

On this page you can find all versions of the php package thatsus/laravel-better-bind. 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-better-bind

laravel-better-bind

A better bind feature for automated tests in Laravel/Lumen 5+.

Why Better Bind is better

  1. It's less verbose than Laravel's built-in option.
  2. It protects you against missing constructor parameters.
  3. You can choose to check the constructor parameters for correctness.

Automated testing in Laravel using mocks means injecting objects using the Application's bind method.

This can have some drawbacks.

Better Bind provides a syntactically friendly mechanism to verify that constructor parameters match your target class.

Missing required parameters cause an assertion failure.

Extra parameters cause an assertion failure.

Wrong-type parameters cause an assertion failure.

It can be a one-liner.

Better Bind also provides a way to capture the constructor parameters so you can run your own assertions on them.

Installation

Example Test

In this example we expect the Dog::bark method to create a Sound object with itself as the value for the constructor's $animal parameter.

First, we use the betterInstance method from Better Bind to provide the mock to the code. Then we capture the $params argument and check at the end that it has the parameter values we expect.

Passing Code

Gallant wrote this code correctly with the right parameters for the constructor.

Failing Code 1

Goofus forgot to include the name of the parameter for the constructor.

Failing Code 2

Now Goofus included an extra parameter for the constructor by accident.

Failing Code 3

Goofus accidentally passed in a string. That's the wrong type for the $animal parameter.

Methods

betterInstance($signature, $object, [&$params = []])

If $signature is a string that does not refer to an existing class, no assertions will run against the parameters.

betterBind($signature, $closure, [&$params = []])

If $signature is a string that does not refer to an existing class, no assertions will run against the parameters.

betterBind(...)->ignoreParameters($param1, $param2, ...)

Allow Laravel to supply the parameters named. Do not check that the given parameter names are given by the call to makeWith.

I'm not convinced. Can't I do this without Better Bind?

You can do some of the same stuff without this library.

Compare the following versions of the test.

The obvious drawback to the version that doesn't use Better Bind is that there are extra lines, and one of them is very verbose. The secret extra drawback here is that nothing tests to ensure that the requirements to the real Sound class's constructor are met.

What will happen if you write the code from "Failing Code 1"?

Laravel will detect that Sound's constructor typehints an Animal object. But no 'animal' element is in the params, so Laravel will new up an Animal object to do the job. There will be no test failure.

Using Better Bind, the missing value will be detected and the test will fail.

If you want Laravel to fill in a new Animal object itself, you can add ->ignoreParameters('animal').

Compatibility

We believe this code is compatible with all versions of Laravel 5+ and Lumen 5+, but testing it is a chore because make changed to makeWith in 5.4 just to confuse everybody. Drop us a line and let us know how great it is and what version of Laravel you're working with.

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT


All versions of laravel-better-bind with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
illuminate/support Version ^5.0,<5.6
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 thatsus/laravel-better-bind contains the following files

Loading the files please wait ....