dev-master
9999999-devAdditional phpunit traits to complement Laravel testing
The Development Requires
v1.0
1.0.0.0Additional phpunit traits to complement Laravel testing
The Development Requires
Additional phpunit traits to complement Laravel testing
``# PHPUnit Traits, (*1)
1.Install package through composer., (*2)
composer require tyler36/phpunit-helper-traits
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)
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)
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)
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)
Helper for setting authenticated state., (*21)
Ensure current status is guest (logged out)., (*22)
USE:
Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;
, (*23)
EG., (*24)
$this->asGuest();
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();
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)
ASSERT: Mail was NOT sent, (*30)
$this->seeEmailWasNotSent();
ASSERT: Mail was sent, (*31)
$this->seeEmailWasSent();
ASSERT: $count number of emails were sent, (*32)
$this->seeEmailsSent(3)
ASSERT: Recipient, (*33)
$this->seeEmailTo($recipient);
ASSERT: NOT Recipient, (*34)
$this->seeEmailNotTo($recipient);
ASSERT: Sender, (*35)
$this->seeEmailFrom($sender);
ASSERT: NOT Sender, (*36)
$this->seeEmailNotFrom($sender);
ASSERT: Body Matches, (*37)
$this->seeEmailEquals($body);
ASSERT: Body NOT Matches, (*38)
$this->seeEmailNotEquals($body);
ASSERT: Body contains fragment, (*39)
$this->seeEmailContains($excerpt);
ASSERT: Body NOT contains fragment, (*40)
$this->seeEmailNotContains($excerpt);
ASSERT: Subject Matches, (*41)
$this->seeEmailSubjectEquals($subject);
ASSERT: Subject NOT Matches, (*42)
$this->seeEmailSubjectNotEquals($subject);
ASSERT: Subject contains, (*43)
$this->seeEmailSubjectContains($fragment);
ASSERT: Subject NOT contains, (*44)
$this->seeEmailSubjectNotContains($fragment);
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)
Additional phpunit traits to complement Laravel testing
Additional phpunit traits to complement Laravel testing