Package Data | |
---|---|
Maintainer Username: | tyler36 |
Package Create Date: | 2016-07-11 |
Package Last Update: | 2016-12-06 |
Home Page: | |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2025-02-10 15:02:01 |
Package Statistics | |
---|---|
Total Downloads: | 27 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
``# PHPUnit Traits
1.Install package through composer.
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.
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.
*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")
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);
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.
Helper for setting authenticated state.
Ensure current status is guest (logged out).
USE:
Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;
EG.
$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.
USE:
Include trait within class - use tyler36\phpunitTraits\CountElementsTrait;
EG.
$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
config()->set('mail.driver', 'log');
USE:
Include trait within class - use tyler36\phpunitTraits\MailTrackerTrait;
ASSERT: Mail was NOT sent
$this->seeEmailWasNotSent();
ASSERT: Mail was sent
$this->seeEmailWasSent();
ASSERT: $count number of emails were sent
$this->seeEmailsSent(3)
ASSERT: Recipient
$this->seeEmailTo($recipient);
ASSERT: NOT Recipient
$this->seeEmailNotTo($recipient);
ASSERT: Sender
$this->seeEmailFrom($sender);
ASSERT: NOT Sender
$this->seeEmailNotFrom($sender);
ASSERT: Body Matches
$this->seeEmailEquals($body);
ASSERT: Body NOT Matches
$this->seeEmailNotEquals($body);
ASSERT: Body contains fragment
$this->seeEmailContains($excerpt);
ASSERT: Body NOT contains fragment
$this->seeEmailNotContains($excerpt);
ASSERT: Subject Matches
$this->seeEmailSubjectEquals($subject);
ASSERT: Subject NOT Matches
$this->seeEmailSubjectNotEquals($subject);
ASSERT: Subject contains
$this->seeEmailSubjectContains($fragment);
ASSERT: Subject NOT contains
$this->seeEmailSubjectNotContains($fragment);
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');