定制 vladahejda/phpunit-assert-exception 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vladahejda/phpunit-assert-exception

最新稳定版本:v1.3.0

Composer 安装命令:

composer require vladahejda/phpunit-assert-exception

包简介

Assert exception/throwable/error PHPUnit trait.

关键字:

README 文档

README

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.

统计信息

  • 总下载量: 163.29k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 13
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固