Download the PHP package instaclick/base-test-bundle without Composer

On this page you can find all versions of the php package instaclick/base-test-bundle. 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 base-test-bundle

InstaClick Base Test Bundle

IMPORTANT NOTICE: This bundle is still under development. Any changes will be done without prior notice to consumers of this package. Of course this code will become stable at a certain point, but for now, use at your own risk.

Introduction

This bundle provides lower level support for unit and functional tests on Symfony2. Through the concept of helpers and loaders, this bundle supports individual support for test types, such as Command, Controller, Service, Validator, etc.

This bundle requires that you are using, at least, Symfony 2.1.

Installation

Installing this bundle can be done through these simple steps:

  1. Add this bundle to your project as a composer dependency:

  2. Add this bundle in your application kernel:

  3. Double check if your session name is configured correctly:

Unit Testing

By default, Symfony2 does not provide a native customized support for unit test creation. To mitigate this problem, this bundle contains a wide set of basic unit test abstraction to help you with this job.

Protected/Private

There may be times where you want to directly test a protected/private method or access a non-public property (and the class lacks a getter or setter). For example, the call chain from the closest public method is sufficiently long to make testing an arduous task.

To overcome this obstacle, TestCase provides some methods to assist you.

Let's say this is your subject under test:

Here is an example:

Bundle testing

Most people do not even think about testing a bundle initialization. This is a bad concept, because every line of code deserves to be tested, even though you may not have manually created a class.

Bundle classes are known to be the place to register your CompilerPass instances. No matter if you have a CompilerPass or not, it is a good practice to create a default test for your Bundle class. Here is an example on how to achieve it:

Dependency Injection

Configuration testing

Just like Bundle classes, Configuration classes are very easy to overlook when testing. Testing this specific test is a good approach because it validates your line of thought with Bundle configuration normalization of parameters or even configuration default values. ICBaseTestBundle already provides a small class that can help you with this task.

Extension testing

Testing the DependencyInjection Extension helps you to validate your service definitions and container configuration. Helpful methods available to you:

Validator testing

Validators are a key part of the system, because it helps you verify your business rules are being respected. Testing them becomes even more crucial. Constraints can generate violations at different locations. In order to help you verify it assigns it at the correct place, ValidatorTestCase provides you a set of methods:

Creating your first functional test

Just like a Symfony2 test, implementing a functional test is easy:

Functional tests that requires Database to be initialized

When building your functional tests, it is recurrent that you want your test Database to be created and populated with initial information. This bundle comes with native support for Doctrine Data Fixtures, which allows you to load your database information before your test is actually executed.

To enable your schema to be initialized and also load the initial Database information, just implement the protected static method getFixtureList:

If you don't need any fixtures to be loaded before your test, but still want your empty Database schema to be loaded, you can tell the TestCase to still force the schema to be loaded by changing the configuration property flag:

Overriding the default client instance

Some applications require more granular control than what Symfony2 Client can do. This bundle allows you to change the default client initialization, just like you normally do with your Symfony2 WebTestCase, by overriding the static method createClient.

Changing Client environment

This bundle allows you to easily change the environment the Client gets initialized. To change the default environment (default: "test"), just redefine the constant ENVIRONMENT:

Changing default Object Manager name

When using Databases, you may want to change the default ObjectManager your test should run against. Just like Client's environment, changing the default ObjectManager only requires you to redefine the constant MANAGER_NAME:

Server authentication

Whenever your application uses HTTP authentication, your test should still have an ability to test secured pages. With simplicity in mind, Client can be initialized in an authenticated state for HTTP. The only required step is implement the protected static method getServerParameters:

Note: this assumes you have enabled http_basic in your security configuration using this setting in the config_test.yml file:

See How to simulate HTTP Authentication in a Functional Test for details

Changing Client initialization

Oftentimes, overriding createClient is enough. Whenever you need more refined support, you can still override the default Client initialization by overriding the protected static method initializeClient (sample is actually the default implementation of the method):

Useful hints

Creating a class MockBuilder

Instead of using the native API of PHPUnit, WebTestCase provides a useful method right at your hands:

Retrieving the Service Container

Symfony Client holds an instance of Service Container. You can retrieve the container instance directly from the client:

Retrieving Database references

Database dependant applications usually force you to fetch for elements before actually testing/consuming them. WebTestCase takes advantage of Doctrine Data Fixtures package, allowing you to retrieve references without requiring a database fetch.

Database dependant functional tests

In most cases, your application relies on a database to work. To help you on this task, and also speed up the execution of your suite, we strongly suggest that you use SQLite as your test database. The reason why to do that is because this database works around a single file, allowing you to easily create isolated scenarios. Also, this bundle has an ability to cache the generated schema and reuse it for every test. Another piece of functionality: this bundle integrates natively with Doctrine Data Fixtures, allowing your SQLite test database to be cached with common - test agnostic - information even before your actual test gets executed.

Finally, but no less important, if you use SQLite, your test will run faster with all the native support built-in, simply by using this bundle.

To use SQLite as your test database, add this to your app/config_test.yml:

Attention: you need to use Doctrine >= 2.2 to benefit from this feature.

Using Helpers

This bundle comes with built-in helpers to simplify testing individual pieces of software. This section will explain the native ones and also how to inject your own helper.

Retrieving a helper

Access helpers by taking advantage of the Symfony2 Client instance available in WebTestCase. All helpers are registered in the latter, and it allows you to retrieve an instance easily by calling the method:

Available helpers

ICBaseTestBundle comes with a collection of helpers out of the box. Here is the list of available helpers:

Command Helper

This helper is available to you under the name command. It works as a wrapper around the Symfony Console Component. This also allows you to configure your command, build the command input and retrieve the response content by using its available API. As an example, here is a full implementation of a command test:

Controller Helper

This helper is available to you under the name controller. The motivation of this helper is to enable sub-requests to be executed without requiring the master request to be called. It allows you to simulate a request and check for returned content.

IMPORTANT NOTICE: Controller Helper is still under development. It is part of the plan to connect Symfony\Component\DomCrawler\Crawler as a separate method.

Persistence Helper

This helper is available to you under the name persistence. The persistence helper transforms a reference key to a reference object, or a list of reference keys to a list of reference objects.

Route Helper

This helper is available to you under the name route. The Route helper provides a method to retrieve a generated route from a route id. Moreover, if the route is not registered, the test is marked as skipped.

Service Helper

This helper is available to you under the name service. Whenever you want to mock a Service and automatically inject it back into Service Container, this helper is for you. Helper contains a method that does that: mock. It returns an instance of MockBuilder.

Session Helper

This helper is available to you under the name session. Session helper was written with a simple idea in mind: allow you to simulate login for controller tests. Of course, Session helper also allows you to retrieve the actual Symfony Session to define/check/remove entries normally too.

Validator Helper

This helper is available to you under the name validator. Validator Helper encapsulates more logic than the other native helpers. It allows you to also test success and error states because it requires internal mocking of elements needed for testing.

Unit/Entity Helper

This helper is available to you under the name Unit/Entity. The Unit/Entity helper helps to create Entity stubs where there is no setId() method.

Unit/Function Helper

This helper is available to you under the name Unit/Function. The Unit/Function helper helps to mock built-in PHP functions. Note: the subject under test must be a namespaced class.

Creating and registering your own helper

Registering a new helper is required to override the protected static method initializeHelperList:


All versions of base-test-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
symfony/framework-bundle Version >=2.0,<3.0-dev
doctrine/doctrine-fixtures-bundle Version 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 instaclick/base-test-bundle contains the following files

Loading the files please wait ....