PHPackages                             watson/testing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. watson/testing

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

watson/testing
==============

Laravel controller and model testing helpers.

2.0.0(11y ago)234.2k7[2 issues](https://github.com/dwightwatson/testing/issues)MITPHPPHP &gt;=5.4.0

Since Jun 29Pushed 10y ago1 watchersCompare

[ Source](https://github.com/dwightwatson/testing)[ Packagist](https://packagist.org/packages/watson/testing)[ RSS](/packages/watson-testing/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (10)Used By (0)

Testing, PHPUnit helpers for Laravel
====================================

[](#testing-phpunit-helpers-for-laravel)

This package is no longer maintained, in favour of better testing support now shipping with Laravel.
----------------------------------------------------------------------------------------------------

[](#this-package-is-no-longer-maintained-in-favour-of-better-testing-support-now-shipping-with-laravel)

Testing contains traits with helpers for testing models and controllers in Laravel. It helps you assert the validity of your models (assuming the use of [watson/validating](https://github.com/dwightwatson/validating)) as well as the relationships of your models. It also allows you to test the responses of your controllers.

Installation
============

[](#installation)

Simply run the following Composer command in your application.

```
composer require watson/testing
```

The `~1.0` stream is for Laravel 4, and the `~2.0` stream is for Laravel 5.

Overview
--------

[](#overview)

To use the test helpers in your tests, simply bring the trait in to your test file.

```
class UsersControllerTest extends TestCase {
	use Watson\Testing\ControllerHelpers;
}
```

```
class UserTest extends TestCase {
	use Watson\Testing\ModelHelpers;
}
```

If you'd prefer to use the test helpers globally, just use this trait in your `TestCase.php`.

```
class TestCase extends Illuminate\Foundation\Testing\TestCase {
	use Watson\Testing\TestingTrait;
}
```

Controller testing
------------------

[](#controller-testing)

### assertViewIs($expectedView, $message = null);

[](#assertviewisexpectedview-message--null)

```
// Controller
return View::make('users.index');

// Test
$this->assertViewIs('users.index');
```

Ensure that the view used in the response is the one you expected.

Model testing
-------------

[](#model-testing)

### Model validations

[](#model-validations)

If you're using [watson/validating](https://github.com/dwightwatson/validating) on your models it is really easy to test your validations. We will use the following `User` model for these examples.

```
$user = new User;
```

#### assertValid(Model $model, $message = null)

[](#assertvalidmodel-model-message--null)

```
$user->email = 'example@example.com';

$this->assertValid($user);
```

#### assertInvalid(Model $model, $message = null)

[](#assertinvalidmodel-model-message--null)

```
$user->email = 'foo';

$this->assertInvalid($user);
```

If you want to easily check if a model is valid or invalid with or without a certain attribute, there a number of helpers for quickly asserting that this is the case.

#### assertValidWith(Model $model, $attribute, $value = null, $message = null)

[](#assertvalidwithmodel-model-attribute-value--null-message--null)

```
$this->assertValidWith($user, 'email', 'example@example.com');
```

#### assertValidWithout(Model $model, $attribute, $message = null)

[](#assertvalidwithoutmodel-model-attribute-message--null)

```
$this->assertValidWithout($user, 'last_name')
```

#### assertInvalidWith(Model $model, $attribute, $value = null, $message = null)

[](#assertinvalidwithmodel-model-attribute-value--null-message--null)

```
$this->assertInvalidWith($user, 'email', 'foo');
```

#### assertInvalidWithout(Model $model, $attribute, $message = null)

[](#assertinvalidwithoutmodel-model-attribute-message--null)

```
$this->assertInvalidWithout($user, 'email');
```

### Specific model validations

[](#specific-model-validations)

If you'd prefer an easier (and more readable) way of asserting the validations on your model you might like to try specific model validations. They work with [watson/validating](https://github.com/dwightwatson/validating) or any other validation trait that complies with `Watson\Validating\ValidatingInterface` (that is, has a `getDefaultRules` method).

#### assertValidatesWith(Model $mode, $attribute, $rule, $message = null)

[](#assertvalidateswithmodel-mode-attribute-rule-message--null)

```
// Assert that the email attribute is required.
$this->assertValidatesWith($user, 'email', 'required');
$this->assertValidatesRequired($user, 'email');
```

Here is the list of included Laravel default validation assertions:

- assertValidatesAccepted(Model $model, $attribute, $message = null)
- assertValidatesActiveUrl(Model $model, $attribute)
- assertValidatesAfter(Model $model, $attribute, $date)
- assertValidatesAlpha(Model $model, $attribute)
- assertValidatesAlphaDash(Model $model, $attribute)
- assertValidatesAlphaNum(Model $model, $attribute)
- assertValidatesArray(Model $model, $attribute)
- assertValidatesBefore(Model $model, $attribute, $date)
- assertValidatesBetween(Model $model, $attribute, $min, $max)
- assertValidatesConfirmed(Model $model, $attribute)
- assertValidatesDate(Model $model, $attribute)
- assertValidatesDate(Model $model, $attribute)
- assertValidatesDifferent(Model $model, $attribute, $field)
- assertValidatesDigits(Model $model, $attribute, $value)
- assertValidatesDigitsBetween(Model $model, $attribute, $min, $max)
- assertValidatesBoolean(Model $model, $attribute)
- assertValidatesEmail(Model $model, $attribute)
- assertValidatesExists(Model $model, $attribute, $parameters)
- assertValidatesImage(Model $model, $attribute)
- assertValidatesIn(Model $model, $attribute, $values)
- assertValidatesInteger(Model $model, $attribute)
- assertValidatesIp(Model $model, $attribute)
- assertValidatesMax(Model $model, $attribute, $value)
- assertValidatesMimes(Model $model, $attribute, $values)
- assertValidatesMin(Model $model, $attribute, $value)
- assertValidatesNotIn(Model $model, $attribute, $values)
- assertValidatesNumeric(Model $model, $attribute)
- assertValidatesRegex(Model $model, $attribute, $pattern)
- assertValidatesRequired(Model $model, $attribute)
- assertValidatesRequiredIf(Model $model, $attribute, $field, $value)
- assertValidatesRequiredWith(Model $model, $attribute, $values)
- assertValidatesRequiredWithAll(Model $model, $attribute, $values)
- assertValidatesRequiredWithout(Model $model, $attribute, $values)
- assertValidatesRequiredWithoutAll(Model $model, $attribute, $values)
- assertValidatesSame(Model $model, $attribute, $field)
- assertValidatesSize(Model $model, $attribute, $value)
- assertValidatesTimezone(Model $model, $attribute)
- assertValidatesUnique(Model $model, $attribute, $parameters)

### Model relationships

[](#model-relationships)

You can assert the different relationships exist on your model.

#### assertBelongsTo($class, $relation)

[](#assertbelongstoclass-relation)

Ensure that a post belongs to a user.

```
$this->assertBelongsTo($post, 'user');
```

#### assertBelongsToMany($class, $relation)

[](#assertbelongstomanyclass-relation)

Ensure that a tag belongs to many posts.

```
$this->assertBelongsToMany($tag, 'posts');
```

#### assertHasOne($class, $relation)

[](#asserthasoneclass-relation)

Ensure that a user has one profile.

```
$this->assertHasOne($user, 'profile');
```

#### assertHasMany($class, $relation)

[](#asserthasmanyclass-relation)

Ensure that a user has many posts.

```
$this->assertHasMany($user, 'posts');
```

Credits
-------

[](#credits)

This package builds upon the work of the now unmaintained [way/laravel-test-helpers](https://github.com/JeffreyWay/Laravel-Test-Helpers) and includes code from the unmerged pull requests of [SammyK](https://github.com/JeffreyWay/Laravel-Test-Helpers/pull/52/files), [effi](https://github.com/JeffreyWay/Laravel-Test-Helpers/pull/41), [mrevd](https://github.com/JeffreyWay/Laravel-Test-Helpers/pull/42) and [sorora](https://github.com/JeffreyWay/Laravel-Test-Helpers/pull/8/files).

I decided to continue the development of these helpers because I prefer testing with the tool that ships with the framework, and I really like PHPUnit.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~61 days

Total

9

Last Release

4079d ago

Major Versions

1.1.x-dev → 2.0.02015-03-19

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1100408?v=4)[Dwight Watson](/maintainers/dwightwatson)[@dwightwatson](https://github.com/dwightwatson)

---

Top Contributors

[![dwightwatson](https://avatars.githubusercontent.com/u/1100408?v=4)](https://github.com/dwightwatson "dwightwatson (16 commits)")

---

Tags

testingphpunitlaravel

### Embed Badge

![Health badge](/badges/watson-testing/health.svg)

```
[![Health](https://phpackages.com/badges/watson-testing/health.svg)](https://phpackages.com/packages/watson-testing)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[illuminated/testing-tools

Laravel-specific Testing Helpers and Assertions.

5420.4k17](/packages/illuminated-testing-tools)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.3k13](/packages/lastzero-test-tools)[srlabs/laravel-testing-utilities

Helper utilities for testing Laravel Applications

1011.9k](/packages/srlabs-laravel-testing-utilities)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
