Download the PHP package cydrickn/laravel-query-factory without Composer

On this page you can find all versions of the php package cydrickn/laravel-query-factory. 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-query-factory

Laravel Query Factory

PHP from Packagist ci Coverage Status

Laravel Query Factory, is library for you to easily mock your query builder without sending query from real database.

The library is to use for developers who really follow the Automating Testing, The unit test is the most low level where you need tto test your whole system.

Problem that want to solve by this Library

In laravel is one of the problem, where most of the tutorials and even in document of laravel, the testing is mostly focusing in integration, api and acceptance.

Example of this test are:

Fromm our example, this is an Integration test, not a unit test. Why? We will answer that why using the list below:

From this list and from the example, our test was calling a database, if you call find from your model this will immediately call a query using your connection.

Oops!!!, why not use sqlite, since sqlite is just a file base and can be use without other database? The answer is dont use sqlite for test to just satisfy your unit test, Why?

Classes and Traits

Class Description
LaravelQueryFactory\Facades\QueryFactoryFacade A class for facade use by laravel and lumen
LaravelQueryFactory\QueryFactory The main service that will generate query builder
LaravelQueryFactory\QueryFactoryProvider Provider that will register the LaravelQueryFactory\QueryFactory as query-factory
Trait Description
LaravelQueryFactory\Models\Traits\QueryFactoryTrait Trait that can use by the model to replace the default newBaseQueryBuilder
LaravelQueryFactory\Traits\MockQueryFactory A trait use for testing, to mock connection and pdo

How to use

Installing

Register the Provider

The configuration can be found to config/app.php.

To register your provider, add it to the array:

Creating Model

Model will just use the LaravelQueryFactory\Models\Traits\QueryFactoryTrait this will use the facade or you can also set the QueryFactory using by calling setQueryFactory

Adding QueryFactoryTrait to your model, this will replace the current generation of Query Builder using QueryFactoryFacade so that you can mock it.

Creating Repository/Service

Creating repository or service is just you normal service. It's your choice if you will inject LaravelQueryFactory\QueryFactory, but in this example we will not since we use the default QueryFactory from our facades.

Person Repository

Creating Unit Test

For our unit test you need to use LaravelQueryFactory\Traits\MockQueryFactory. This trait will mock the connection class use by laravel so that it will not connect to any type of database.

for function mockConnection it is accepting:

Why we need to specify this drivers? so that you can get the generated query for test, since every driver has different queries on how they convert your query builder. But I suggest that you use the driver use by your system, so that you can really check your expectation sql.

Conclusion

Using this library (Laravel Query Factory) you can now mock your query builders. By mocking the connection will mock the connection so that it will not connect to database.


All versions of laravel-query-factory with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
laravel/framework Version ~5.5|~6.0|~7.0
ext-pdo Version *
ext-mbstring Version *
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 cydrickn/laravel-query-factory contains the following files

Loading the files please wait ....