{"id":15480034,"url":"https://github.com/tyler36/phpunit-helper-traits","last_synced_at":"2026-05-06T11:35:05.091Z","repository":{"id":57074154,"uuid":"63040697","full_name":"tyler36/phpunit-helper-traits","owner":"tyler36","description":null,"archived":false,"fork":false,"pushed_at":"2016-12-06T04:51:39.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T04:30:21.273Z","etag":null,"topics":["laravel","phpunit","testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tyler36.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-11T05:59:21.000Z","updated_at":"2022-10-20T00:33:56.000Z","dependencies_parsed_at":"2022-08-24T14:54:49.425Z","dependency_job_id":null,"html_url":"https://github.com/tyler36/phpunit-helper-traits","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Fphpunit-helper-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Fphpunit-helper-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Fphpunit-helper-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyler36%2Fphpunit-helper-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyler36","download_url":"https://codeload.github.com/tyler36/phpunit-helper-traits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246045280,"owners_count":20714751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","phpunit","testing"],"created_at":"2024-10-02T04:40:21.906Z","updated_at":"2026-05-06T11:35:00.071Z","avatar_url":"https://github.com/tyler36.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"``# PHPUnit Traits\n\n## Installation\n1.Install package through composer.\n\n```\n   composer require tyler36/phpunit-helper-traits\n```\n\n\n ---\n## Intro\nThese traits were designed and tested with Laravel 5.2, with Laravel-elixir 5.\nUsing laravel-elixir's 'visit' command will test a page is available and generate a crawler object used for some of the tests.\nCheck the tests directory for further examples and uses.\n\n### CheckAssetExistsTrait\nCheck if item/s are available, and also appears on the page.\nIf the string starts with 'http', this trait will make a HTTP request to the web and check if the asset is available.\nUsefully for checking CDNs.\nOther paths will begin looking in the projects 'public' directory (\"app()-\u003epublicPath()\").\nIf the tests has a _crawler_ object, this trait will also check if the string is displayed on the page.\n\n*Returns TEST case to allow chaining.\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\CheckAssetExistsTrait;```\n\nCall trait with filename or array - ```$this-\u003echeckAssetExists($filename);```\n\n\nEG.\n\n```$this-\u003echeckAssetExists(\"https://code.jquery.com/jquery-3.1.0.min.js\");```\n\n```$this-\u003echeckAssetExists(\"/robots.txt\");```\n\n```$this-\u003echeckAssetExists([\"js/jquery.js\", \"css/main.css\"]);```\n\n```$this-\u003evisit('/home')-\u003echeckAssetExists(\"/images/logo.jpg\")```\n\n\n### CountElementsTrait\nCheck page and counts occurrence of specified CSS selector.\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\CountElementsTrait;```\n\nCall trait with CSS selector and expected count - ```$this-\u003ecountElements($selector, $count);```\n\nEG.\n```$this-\u003ecountElements('.card', 3);```\n\n\n### DisableExceptionHandlerTrait\nThis trait overwrites the default exception handler, allowing you to check error messages with assertions.\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\DisableExceptionHandlerTrait;```\n\nCall trait with CSS selector to disable exception handling - ```$this-\u003edisableExceptionHandling()```\n\nUse TRY / CATCH in test.\n\n\n### ImpersonateTrait\nHelper for setting authenticated state.\n\n#### asGuest\nEnsure current status is guest (logged out).\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\CountElementsTrait;```\n\nEG.\n```\n$this-\u003easGuest();\n```\n\n#### asMember\nEnsure current status is member (logged out).\nIf a user object is passed, this trait will login as that user.\nIf no user object is passed, this trait will use a 'App\\User' factory to create a random User object and log in.\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\CountElementsTrait;```\n\nEG.\n```\n$this-\u003easMember();\n```\n\n\n### MailTrackingTrait\nInspired by [phpunit-testing-in-laravel](https://laracasts.com/series/phpunit-testing-in-laravel/episodes/12)\nCheck mail options by intercepting sent mails.\nYou may want to prevent laravel from sending mail by using the log driver; in a test or setUp() function\n```\nconfig()-\u003eset('mail.driver', 'log');\n```\n\nUSE:\nInclude trait within class -  ```use tyler36\\phpunitTraits\\MailTrackerTrait;```\n\n#### seeEmailWasNotSent\nASSERT:      Mail was NOT sent\n```\n$this-\u003eseeEmailWasNotSent();\n```\n#### seeEmailWasSent\nASSERT:      Mail was sent\n```\n$this-\u003eseeEmailWasSent();\n```\n\n#### seeEmailsSent($count)\nASSERT:     $count number of emails were sent\n```\n$this-\u003eseeEmailsSent(3)\n```\n\n#### seeEmailTo($recipient)\nASSERT:      Recipient\n```\n$this-\u003eseeEmailTo($recipient);\n```\n\n#### seeEmailNotTo($recipient)\nASSERT:      NOT Recipient\n```\n$this-\u003eseeEmailNotTo($recipient);\n```\n\n#### seeEmailFrom($sender)\nASSERT:      Sender\n```\n$this-\u003eseeEmailFrom($sender);\n```\n\n#### seeEmailNotFrom($sender)\nASSERT:      NOT Sender\n```\n$this-\u003eseeEmailNotFrom($sender);\n```\n\n#### seeEmailEquals($body)\nASSERT:      Body Matches\n```\n$this-\u003eseeEmailEquals($body);\n```\n\n#### seeEmailNotEquals($body)\nASSERT:      Body NOT Matches\n```\n$this-\u003eseeEmailNotEquals($body);\n```\n\n#### seeEmailContains($excerpt)\nASSERT:      Body contains fragment\n```\n$this-\u003eseeEmailContains($excerpt);\n```\n\n#### seeEmailNotContains($excerpt)\nASSERT:      Body NOT contains fragment\n```\n$this-\u003eseeEmailNotContains($excerpt);\n```\n\n#### seeEmailSubjectEquals($subject)\nASSERT:      Subject Matches\n```\n$this-\u003eseeEmailSubjectEquals($subject);\n```\n\n#### seeEmailSubjectNotEquals($subject)\nASSERT:      Subject NOT Matches\n```\n$this-\u003eseeEmailSubjectNotEquals($subject);\n```\n\n#### seeEmailSubjectContains($excerpt)\nASSERT:      Subject contains\n```\n$this-\u003eseeEmailSubjectContains($fragment);\n```\n\n\n#### seeEmailSubjectNotContains($excerpt)\nASSERT:      Subject NOT contains\n```\n$this-\u003eseeEmailSubjectNotContains($fragment);\n```\n\n\n### PrepareFileUploadTrait\nSimulate a file upload\n\nInclude trait within class -  ```use tyler36\\phpunitTraits\\PrepareFileUploadTrait;```\n\nCall trait with filename or array - ```$this-\u003eprepareUpload($file)```\n\nEG.\n```$this-\u003eprepareUpload('./avatar.jpg');```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler36%2Fphpunit-helper-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyler36%2Fphpunit-helper-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyler36%2Fphpunit-helper-traits/lists"}