Download the PHP package hackpack/hackunit without Composer

On this page you can find all versions of the php package hackpack/hackunit. 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 hackunit

HackUnit

Testing framework written in and for Hack.

Gitter

But Why?!

There are already many testing frameworks available, such as PHPUnit and behat. Why should you use this one?

Because you like Hack specific features!

With HackUnit, you can easily run your tests using cooperative async with the built in async keyword.

With HackUnit, you can easily iterate through your test data in an async way using the yield keyword.

With HackUnit, you indicate test methods using annotations.

The original goal of HackUnit was to write a testing framework using Hack's strict mode. The project will stay consistent with this goal as more features are added.

Install

Install HackUnit using Composer:

Usage

HackUnit can be run from the command line using the included executable script bin/hackunit. By default, this will be symlinked in your vendor/bin directory.

Thus, the most common way to invoke HackUnit is:

where path1, path2, etc... are each base paths/files to scan for test suites. If any specified path is a directory, the directory will be recursively scanned.

Some command line options exist to alter the behavior of HackUnit:

Test Suites

To define a test suite, create a class and annotate the appropriate methods.

You may inspect HackUnit’s test files for concrete examples.

Tests

Individual test methods are defined using the <<Test>> attribute. Execution order of the tests is not guaranteed.

Each test method MUST accept exactly 1 parameter, with the type hint of HackPack\HackUnit\Contract\Assert. If you mark a method as a test and the signature does not match, the test will not be run.

Test methods may be instance methods, or they may be class (static) methods.

Async

Running your tests async is as easy as adding the async keyword to your test method.

All such async tests are run using cooperative multitasking (see the async documentation), allowing your entire test suite to run faster if your tests perform real I/O operations (DB calls, network calls, etc...).

Setup

You may have HackUnit run some methods before each individual test method is run and/or before any test method is run for the suite. To do so, mark the appropriate method with the <<Setup>> attribute. Multiple setup methods may be declared, but the execution order is not guaranteed.

Each setup method (both suite and test) MUST require exactly 0 parameters. If you mark a method as setup and it requires a parameter, it will not be executed and a parse error will be shown in the report.

Suite setup methods are run once, before any of the test methods in the class are run.

Test setup methods are run just before each test method is run (and thus are potentially run multiple times).

Teardown

You may have HackUnit run some methods after each individual test method is run and/or after all test methods are run for the suite. To do so, mark the appropriate method with the <<TearDown>> attribute. Multiple teardown methods may be declared, but the execution order is not guaranteed.

Each teardown method (both suite and test) MUST require exactly 0 parameters. If you mark a method as teardown and it requires a parameter, it will not be executed and a parse error will be shown in the report.

Suite tear down methods are run once, after all of the test methods in the class are run.

Test tear down methods are run just after each test method is run (and thus are potentially run multiple times).

Suite Providers

Your test suite may require parameters to be passed to the constructor. To tell HackUnit how to construct your test suite, you must define at least one Suite Provider. A Suite Provider is marked with the <<SuiteProvider>> attribute.

You may define multiple Suite Providers for a single test suite. To do so, you must label each one by passing in one string parameter to the attribute (i.e., <<SuiteProvider('name of provider')>>). There are no restrictions on the name of a provider except that each provider name must be unique.

To use a particular Suite Provider for a particular test, you must pass the name of the Suite Provider to the Test attribute.

Assertions

All test methods must accept exactly one parameter of type HackPack\HackUnit\Contract\Assert which should be used to make testable assertions. This object is used to build assertions that will be checked and reported by HackUnit.

In all examples below, $assert contains an instance of HackPack\HackUnit\Contract\Assert.

Bool Assertions

To make assertions about bool type variables, call $assert->bool($myBool)->is($expected).

Numeric Assertions

To make assertions about int and float type variables, call $assert->int($myInt) and $assert->float($myFloat) respectively. The resulting object contains the following methods to actually perform the appropriate assertion.

All of the above may be modified with a call to not() before the assertion to negate the meaning of the assertion. For example:

Note: This library only allows assertions to compare identical numeric types. $assert->int(1)->eq(1.0); produces a type error.

String Assertions

To make assertions about string type variables, call $assert->string($myString). The resulting object contains the following methods to actually perform the appropriate assertion.

All of the above assertions may be negated by calling not() before making the assertion. For example:

Collection Assertions

To make assertions about collections and arrays, call $assert->container($context). The resulting object contains the following methods to perform assertions.

All of the contains* assertions above accept an optional second parameter which must be a callable. The callable will be used to compare the elements in the context with the element(s) provided. If the elements passed to the callable should be treated as equivalent, the callable should return true, otherwise it should return false.

Keyed Collections

If the keys of the container are important for the assertions, you should use $assert->keyedContainer($context). The resulting object contains the following methods to perform assertions.

All of the assertions above accept an optional second (or third in the case of contains) parameter which must be a callable. The callable will be used to compare the values of the elements in the context with the element(s) provided. If the values passed to the callable should be treated as equivalent, the callable should return true, otherwise it should return false.

Mixed Assertions

To make generic assertions about a variable of any type, call $assert->mixed($context). The resulting object contains the following methods to actually perform the appropriate assertion.

Skipping Tests

There are two ways to skip execution of a particular test method:

  1. Add the attribute <<Skip>> to the test method or the test suite. If the <<Skip>> attribute is added to the suite, all tests in that class will be skipped.
  2. Invoke the skip() method of the Assert object passed to your test method.

Data Providers

You may mark some methods as providing a list of data that should be iterated and passed to a test method. To do this, mark the data providing method with the <<DataProvider('name')>> attribute. You must name your data provider as shown to allow HackUnit to know which data provider should be used for each test that consumes data.

The example above demonstrates defining both async and non-async data providers. Special note should be taken of the return values.

In the example above, a MalformedSuite error would occur if the csv consumer function had the signature public function testCsvValues(Assert $assert, Traversable<string>): void. Even though an array<string> is a type of Traversable<string>, the HackUnit parser compares the string representation of the types to ensure invalid data is never passed to the test methods.

How HackUnit loads tests

All files inside the base path(s) specified from the command line will be scanned for class definitions using Fred Emmott's Definition Finder library. Those files will then be loaded and reflection is used to determine which classes are test suites, and which methods perform each task in the suite.

Thanks Fred!

Strict mode all the files!

Well... not quite.

Top level code must use // partial mode, so the bin/hackunit file is not in strict mode. The rest of the project is, with one exception. Test suite files must be dynamically loaded after being scanned for test suites. The only way I can see to perform this dynamic inclusion is to use include_once inside of a class method, which is disallowed in strict mode. This one exception is marked with a /* HH_FIXME */ comment, which disables the type checker for that one line.

Running HackUnit's tests

HackUnit is tested with HackUnit. From the project directory run:


All versions of hackunit with dependencies

PHP Build Version
Package Version
Requires hhvm Version ^3.11
facebook/definition-finder Version ^1.0
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 hackpack/hackunit contains the following files

Loading the files please wait ....