2017 © Pedro Peláez
 

library phpunit-helper-traits

Additional phpunit traits to complement Laravel testing

image

tyler36/phpunit-helper-traits

Additional phpunit traits to complement Laravel testing

  • Monday, July 11, 2016
  • by tyler36
  • Repository
  • 1 Watchers
  • 0 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

``# PHPUnit Traits, (*1)

Installation

1.Install package through composer., (*2)

   composer require tyler36/phpunit-helper-traits

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., (*3)

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()->publicPath()"). If the tests has a crawler object, this trait will also check if the string is displayed on the page., (*4)

*Returns TEST case to allow chaining., (*5)

USE: Include trait within class - use tyler36\phpunitTraits\CheckAssetExistsTrait;, (*6)

Call trait with filename or array - $this->checkAssetExists($filename);, (*7)

EG., (*8)

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

$this->checkAssetExists("/robots.txt");, (*10)

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

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

CountElementsTrait

Check page and counts occurrence of specified CSS selector., (*13)

USE: Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;, (*14)

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

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

DisableExceptionHandlerTrait

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

USE: Include trait within class - use tyler36\phpunitTraits\DisableExceptionHandlerTrait;, (*18)

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

Use TRY / CATCH in test., (*20)

ImpersonateTrait

Helper for setting authenticated state., (*21)

asGuest

Ensure current status is guest (logged out)., (*22)

USE: Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;, (*23)

EG., (*24)

$this->asGuest();

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., (*25)

USE: Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;, (*26)

EG., (*27)

$this->asMember();

MailTrackingTrait

Inspired by phpunit-testing-in-laravel 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, (*28)

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

USE: Include trait within class - use tyler36\phpunitTraits\MailTrackerTrait;, (*29)

seeEmailWasNotSent

ASSERT: Mail was NOT sent, (*30)

$this->seeEmailWasNotSent();

seeEmailWasSent

ASSERT: Mail was sent, (*31)

$this->seeEmailWasSent();

seeEmailsSent($count)

ASSERT: $count number of emails were sent, (*32)

$this->seeEmailsSent(3)

seeEmailTo($recipient)

ASSERT: Recipient, (*33)

$this->seeEmailTo($recipient);

seeEmailNotTo($recipient)

ASSERT: NOT Recipient, (*34)

$this->seeEmailNotTo($recipient);

seeEmailFrom($sender)

ASSERT: Sender, (*35)

$this->seeEmailFrom($sender);

seeEmailNotFrom($sender)

ASSERT: NOT Sender, (*36)

$this->seeEmailNotFrom($sender);

seeEmailEquals($body)

ASSERT: Body Matches, (*37)

$this->seeEmailEquals($body);

seeEmailNotEquals($body)

ASSERT: Body NOT Matches, (*38)

$this->seeEmailNotEquals($body);

seeEmailContains($excerpt)

ASSERT: Body contains fragment, (*39)

$this->seeEmailContains($excerpt);

seeEmailNotContains($excerpt)

ASSERT: Body NOT contains fragment, (*40)

$this->seeEmailNotContains($excerpt);

seeEmailSubjectEquals($subject)

ASSERT: Subject Matches, (*41)

$this->seeEmailSubjectEquals($subject);

seeEmailSubjectNotEquals($subject)

ASSERT: Subject NOT Matches, (*42)

$this->seeEmailSubjectNotEquals($subject);

seeEmailSubjectContains($excerpt)

ASSERT: Subject contains, (*43)

$this->seeEmailSubjectContains($fragment);

seeEmailSubjectNotContains($excerpt)

ASSERT: Subject NOT contains, (*44)

$this->seeEmailSubjectNotContains($fragment);

PrepareFileUploadTrait

Simulate a file upload, (*45)

Include trait within class - use tyler36\phpunitTraits\PrepareFileUploadTrait;, (*46)

Call trait with filename or array - $this->prepareUpload($file), (*47)

EG. $this->prepareUpload('./avatar.jpg');, (*48)

The Versions

11/07 2016

dev-master

9999999-dev

Additional phpunit traits to complement Laravel testing

  Sources   Download

The Development Requires

11/07 2016

v1.0

1.0.0.0

Additional phpunit traits to complement Laravel testing

  Sources   Download

The Development Requires