PHPackages                             tyler36/phpunit-helper-traits - 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. tyler36/phpunit-helper-traits

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

tyler36/phpunit-helper-traits
=============================

Additional phpunit traits to complement Laravel testing

v1.0(9y ago)028PHP

Since Jul 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tyler36/phpunit-helper-traits)[ Packagist](https://packagist.org/packages/tyler36/phpunit-helper-traits)[ RSS](/packages/tyler36-phpunit-helper-traits/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

``# PHPUnit Traits

Installation
------------

[](#installation)

1.Install package through composer.

```
   composer require tyler36/phpunit-helper-traits

```

---

Intro
-----

[](#intro)

These traits were designed and tested with Laravel 5.2, with Laravel-elixir 5. Using laravel-elixir's 'visit' command will test a page is available and generate a crawler object used for some of the tests. Check the tests directory for further examples and uses.

### CheckAssetExistsTrait

[](#checkassetexiststrait)

Check if item/s are available, and also appears on the page. If the string starts with 'http', this trait will make a HTTP request to the web and check if the asset is available. Usefully for checking CDNs. Other paths will begin looking in the projects 'public' directory ("app()-&gt;publicPath()"). If the tests has a *crawler* object, this trait will also check if the string is displayed on the page.

\*Returns TEST case to allow chaining.

USE: Include trait within class - `use tyler36\phpunitTraits\CheckAssetExistsTrait;`

Call trait with filename or array - `$this->checkAssetExists($filename);`

EG.

`$this->checkAssetExists("https://code.jquery.com/jquery-3.1.0.min.js");`

`$this->checkAssetExists("/robots.txt");`

`$this->checkAssetExists(["js/jquery.js", "css/main.css"]);`

`$this->visit('/home')->checkAssetExists("/images/logo.jpg")`

### CountElementsTrait

[](#countelementstrait)

Check page and counts occurrence of specified CSS selector.

USE: Include trait within class - `use tyler36\phpunitTraits\CountElementsTrait;`

Call trait with CSS selector and expected count - `$this->countElements($selector, $count);`

EG. `$this->countElements('.card', 3);`

### DisableExceptionHandlerTrait

[](#disableexceptionhandlertrait)

This trait overwrites the default exception handler, allowing you to check error messages with assertions.

USE: Include trait within class - `use tyler36\phpunitTraits\DisableExceptionHandlerTrait;`

Call trait with CSS selector to disable exception handling - `$this->disableExceptionHandling()`

Use TRY / CATCH in test.

### ImpersonateTrait

[](#impersonatetrait)

Helper for setting authenticated state.

#### asGuest

[](#asguest)

Ensure current status is guest (logged out).

USE: Include trait within class - `use tyler36\phpunitTraits\CountElementsTrait;`

EG.

```
$this->asGuest();

```

#### asMember

[](#asmember)

Ensure current status is member (logged out). If a user object is passed, this trait will login as that user. If no user object is passed, this trait will use a 'App\\User' factory to create a random User object and log in.

USE: Include trait within class - `use tyler36\phpunitTraits\CountElementsTrait;`

EG.

```
$this->asMember();

```

### MailTrackingTrait

[](#mailtrackingtrait)

Inspired by [phpunit-testing-in-laravel](https://laracasts.com/series/phpunit-testing-in-laravel/episodes/12)Check mail options by intercepting sent mails. You may want to prevent laravel from sending mail by using the log driver; in a test or setUp() function

```
config()->set('mail.driver', 'log');

```

USE: Include trait within class - `use tyler36\phpunitTraits\MailTrackerTrait;`

#### seeEmailWasNotSent

[](#seeemailwasnotsent)

ASSERT: Mail was NOT sent

```
$this->seeEmailWasNotSent();

```

#### seeEmailWasSent

[](#seeemailwassent)

ASSERT: Mail was sent

```
$this->seeEmailWasSent();

```

#### seeEmailsSent($count)

[](#seeemailssentcount)

ASSERT: $count number of emails were sent

```
$this->seeEmailsSent(3)

```

#### seeEmailTo($recipient)

[](#seeemailtorecipient)

ASSERT: Recipient

```
$this->seeEmailTo($recipient);

```

#### seeEmailNotTo($recipient)

[](#seeemailnottorecipient)

ASSERT: NOT Recipient

```
$this->seeEmailNotTo($recipient);

```

#### seeEmailFrom($sender)

[](#seeemailfromsender)

ASSERT: Sender

```
$this->seeEmailFrom($sender);

```

#### seeEmailNotFrom($sender)

[](#seeemailnotfromsender)

ASSERT: NOT Sender

```
$this->seeEmailNotFrom($sender);

```

#### seeEmailEquals($body)

[](#seeemailequalsbody)

ASSERT: Body Matches

```
$this->seeEmailEquals($body);

```

#### seeEmailNotEquals($body)

[](#seeemailnotequalsbody)

ASSERT: Body NOT Matches

```
$this->seeEmailNotEquals($body);

```

#### seeEmailContains($excerpt)

[](#seeemailcontainsexcerpt)

ASSERT: Body contains fragment

```
$this->seeEmailContains($excerpt);

```

#### seeEmailNotContains($excerpt)

[](#seeemailnotcontainsexcerpt)

ASSERT: Body NOT contains fragment

```
$this->seeEmailNotContains($excerpt);

```

#### seeEmailSubjectEquals($subject)

[](#seeemailsubjectequalssubject)

ASSERT: Subject Matches

```
$this->seeEmailSubjectEquals($subject);

```

#### seeEmailSubjectNotEquals($subject)

[](#seeemailsubjectnotequalssubject)

ASSERT: Subject NOT Matches

```
$this->seeEmailSubjectNotEquals($subject);

```

#### seeEmailSubjectContains($excerpt)

[](#seeemailsubjectcontainsexcerpt)

ASSERT: Subject contains

```
$this->seeEmailSubjectContains($fragment);

```

#### seeEmailSubjectNotContains($excerpt)

[](#seeemailsubjectnotcontainsexcerpt)

ASSERT: Subject NOT contains

```
$this->seeEmailSubjectNotContains($fragment);

```

### PrepareFileUploadTrait

[](#preparefileuploadtrait)

Simulate a file upload

Include trait within class - `use tyler36\phpunitTraits\PrepareFileUploadTrait;`

Call trait with filename or array - `$this->prepareUpload($file)`

EG. `$this->prepareUpload('./avatar.jpg');`

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3589d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c68f48588d57835c170cde02444307a450b98cfab07c9674094b881545c13b76?d=identicon)[tyler36](/maintainers/tyler36)

---

Top Contributors

[![s-hendrix-iqnet](https://avatars.githubusercontent.com/u/180614482?v=4)](https://github.com/s-hendrix-iqnet "s-hendrix-iqnet (2 commits)")

---

Tags

laravelphpunittesting

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/tyler36-phpunit-helper-traits/health.svg)

```
[![Health](https://phpackages.com/badges/tyler36-phpunit-helper-traits/health.svg)](https://phpackages.com/packages/tyler36-phpunit-helper-traits)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M677](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[brianium/paratest

Parallel testing for PHP

2.5k118.8M753](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)

PHPackages © 2026

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