All Projects â†’ VladaHejda â†’ PhpUnitAssertException

VladaHejda / PhpUnitAssertException

Licence: other
Assert exception/throwable/error PHPUnit trait

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to PhpUnitAssertException

phpunit-randomizer
A PHPUnit extension that allows you to execute your test cases in a random order
Stars: ✭ 52 (+188.89%)
Mutual labels:  phpunit, phpunit-extension
test-util
👓 Provides utilities for tests.
Stars: ✭ 15 (-16.67%)
Mutual labels:  phpunit, phpunit-assertions
phpunit-json-assertions
JSON assertions for PHPUnit (including JSON Schema)
Stars: ✭ 30 (+66.67%)
Mutual labels:  phpunit, phpunit-assertions
Phpunit Arraysubset Asserts
Provides assertArraySubset for use in PHPunit
Stars: ✭ 95 (+427.78%)
Mutual labels:  phpunit
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).
Stars: ✭ 10,048 (+55722.22%)
Mutual labels:  phpunit
Specify
BDD style code blocks for PHPUnit / Codeception
Stars: ✭ 141 (+683.33%)
Mutual labels:  phpunit
Auth Tests
Always-current tests for Laravel's authentication system. Curated by the community.
Stars: ✭ 230 (+1177.78%)
Mutual labels:  phpunit
Mock Webserver
Simple mock web server in PHP for unit testing.
Stars: ✭ 82 (+355.56%)
Mutual labels:  phpunit
Brainmonkey
Mocking utility for PHP functions and WordPress plugin API
Stars: ✭ 191 (+961.11%)
Mutual labels:  phpunit
Pdt
PHP Development Tools project (PDT)
Stars: ✭ 135 (+650%)
Mutual labels:  phpunit
Laravel Dusk Ci
Docker Test suite for Laravel Dusk in gitlab CI
Stars: ✭ 129 (+616.67%)
Mutual labels:  phpunit
Php Mock Phpunit
Mock built-in PHP functions (e.g. time() or rand()) in PHPUnit.
Stars: ✭ 121 (+572.22%)
Mutual labels:  phpunit
Phpunit Pretty Print
✅  Make your PHPUnit output beautiful
Stars: ✭ 149 (+727.78%)
Mutual labels:  phpunit
Paraunit
Run PHPUnit tests in parallel
Stars: ✭ 104 (+477.78%)
Mutual labels:  phpunit
Steward
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust
Stars: ✭ 215 (+1094.44%)
Mutual labels:  phpunit
Phpunit Json Assert
PHPUnit assertions for JSON documents
Stars: ✭ 90 (+400%)
Mutual labels:  phpunit
Phpunit Bridge
Provides utilities for PHPUnit, especially user deprecation notices management.
Stars: ✭ 2,150 (+11844.44%)
Mutual labels:  phpunit
Verify
BDD Assertions for PHPUnit and Codeception
Stars: ✭ 127 (+605.56%)
Mutual labels:  phpunit
Docker Compose Wordpress
An example Docker Compose setup for WordPress plugin or theme development.
Stars: ✭ 127 (+605.56%)
Mutual labels:  phpunit
Phpunit Accelerator
Listeners to speed up PHPUnit tests
Stars: ✭ 139 (+672.22%)
Mutual labels:  phpunit

PhpUnitAssertException

AssertException is a trait, so it can be easily used in your test case.

  • For PHP 7.1 and PHPUnit 6 compatibility require version 1.3.
  • For PHP 7.1 compatibility require version 1.2.
  • For PHP 7 compatibility require version 1.1.
  • For PHP 5 compatibility require version 1.0.

Install

$ composer require vladahejda/phpunit-assert-exception

Usage

<?php

class MyTest extends \PHPUnit\Framework\TestCase
{
	use VladaHejda\AssertException;

	public function testMultipleExceptionsAtOnce()
	{
		$test = function () {
			// here comes some test stuff of your unit (tested class)
			// which you expect that will throw an Exception
			throw new InvalidArgumentException('Some message 12345', 100);
		};

		// just test if function throws an Exception
		$this->assertException($test); // pass

		// test class of an Exception
		$this->assertException($test, InvalidArgumentException::class); // pass

		// test Exception code
		$this->assertException($test, null, 100); // pass

		// test Exception message
		$this->assertException($test, null, null, 'Some message 12345'); // pass
		$this->assertException($test, null, null, 'Some message'); // also pass, because it checks on substring level

		// test all
		$this->assertException($test, InvalidArgumentException::class, 100, 'Some message 12345'); // pass

		// and here some failing tests
		// wrong class
		$this->assertException($test, ErrorException::class); // fail
		// wrong code
		$this->assertException($test, InvalidArgumentException::class, 200); // fail
		// wrong message
		$this->assertException($test, InvalidArgumentException::class, 100, 'Bad message'); // fail
	}
}

Also see an assertError and assertThrowable methods, which tests if PHP internal Error was thrown, or any Throwable respectively.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].