PHPUnit Polyfills
=====================================================
[![Version](https://poser.pugx.org/yoast/phpunit-polyfills/version)](//packagist.org/packages/yoast/phpunit-polyfills)
[![CS Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml)
[![Lint Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml)
[![Test Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml)
[![Minimum PHP Version](https://img.shields.io/packagist/php-v/yoast/phpunit-polyfills.svg?maxAge=3600)](https://packagist.org/packages/yoast/phpunit-polyfills)
[![License: BSD3](https://poser.pugx.org/yoast/phpunit-polyfills/license)](https://github.com/Yoast/PHPUnit-Polyfills/blob/master/LICENSE)
Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests.
* [Requirements](#requirements)
* [Installation](#installation)
* [Why use the PHPUnit Polyfills?](#why-use-the-phpunit-polyfills)
* [Using this library](#using-this-library)
* [Features](#features)
- [Polyfill traits](#polyfill-traits)
- [Helper traits](#helper-traits)
- [TestCases](#testcases)
- [TestListener](#testlistener)
* [Frequently Asked Questions](#frequently-asked-questions)
* [Contributing](#contributing)
* [License](#license)
Requirements
------------
* PHP 5.4 or higher.
* [PHPUnit] 4.8 - 9.x (automatically required via Composer).
[PHPUnit]: https://packagist.org/packages/phpunit/phpunit
Installation
------------
To install this package, run:
```bash
composer require --dev yoast/phpunit-polyfills
```
To update this package, run:
```bash
composer update --dev yoast/phpunit-polyfills --with-dependencies
```
Make sure to either use the Composer `vendor/autoload.php` file _as_ your test bootstrap file; òr require the `vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php` file _in_ your test bootstrap.
Why use the PHPUnit Polyfills?
------------------------------
This library is set up to allow for creating PHPUnit cross-version compatible tests by offering a number of polyfills for functionality which was introduced, split up or renamed in PHPUnit.
### Write your tests for PHPUnit 9.x and run them on PHPUnit 4.8 - 9.x
The polyfills have been setup to allow tests to be _forward_-compatible. What that means is, that your tests can use the assertions supported by the _latest_ PHPUnit version, even when running on older PHPUnit versions.
This puts the burden of upgrading to use the syntax of newer PHPUnit versions at the point when you want to _start_ running your tests on a newer version.
By doing so, dropping support for an older PHPUnit version becomes as straight-forward as removing it from the version constraint in your `composer.json` file.
Using this library
------------------
Each of the polyfills and helpers has been setup as a trait and can be imported and `use`d in any test file which extends the PHPUnit native `TestCase` class.
If the polyfill is not needed for the particular PHPUnit version on which the tests are being run, the autoloader
will automatically load an empty trait with that same name, so you can safely use these traits in tests which
need to be PHPUnit cross-version compatible.
```php
<?php
namespace Vendor\YourPackage\Tests;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
class FooTest extends TestCase
{
use AssertIsType;
public function testSomething()
{
$this->assertIsBool( $maybeBool );
self::assertIsNotIterable( $maybeIterable );
}
}
```
Alternatively, you can use one of the [`TestCase` classes](#testcases) provided by this library instead of using the PHPUnit native `TestCase` class.
In that case, all polyfills and helpers will be available whenever needed.
```php
<?php
namespace Vendor\YourPackage\Tests;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
class FooTest extends TestCase
{
public function testSomething()
{
$this->assertIsBool( $maybeBool );
self::assertMatchesRegularExpression( $pattern, $string, $message );
}
}
```
### Supported ways of calling the assertions
By default, PHPUnit supports [four ways of calling assertions]:
1. **As a method in the `TestCase` class - `$this->assertSomething()`.**
2. **Statically as a method in the `TestCase` class - `self/static/parent::assertSomething()`.**
3. Statically as a method of the `Assert` class - `Assert::assertSomething()`.
4. As a global function - `assertSomething()`.
The polyfills in this library support the first two ways of calling the assertions as those are the most commonly used type of assertion calls.
For the polyfills to work, a test class is **required** to be a (grand-)child of the PHPUnit native `TestCase` class.
[four ways of calling assertions]: https://phpunit.readthedocs.io/en/stable/assertions.html#static-vs-non-static-usage-of-assertion-methods
### Use with PHPUnit < 5.7.0
If your library still needs to support PHP < 5.6 and therefore needs PHPUnit 4 for testing, there are a few caveats when using the traits stand-alone as we then enter "double-polyfill" territory.
To prevent _"conflicting method names"_ errors when a trait is `use`d multiple times in a class, the traits offered here do not attempt to solve this.
You will need to make sure to `use` any additional traits needed for the polyfills to work.
| PHPUnit | When `use`-ing this trait | You also need to `use` this trait |
|-----------|---------------------------------|-----------------------------------|
| 4.8 < 5.2 | `ExpectExceptionObject` | `ExpectException` |
| 4.8 < 5.2 | `ExpectPHPException` | `ExpectException` |
| 4.8 < 5.2 | `ExpectExceptionMessageMatches` | `ExpectException` |
| 4.8 < 5.6 | `AssertionRenames` | `AssertFileDirectory` |
_**Note: this only applies to the stand-alone use of the traits. The [`TestCase` classes](#testcases) provided by this library already take care of this automatically.**_
Code example testing for a PHP native warning in a test which needs to be able to run on PHPUnit 4.8:
```php
<?php
namespace Vendor\YourPackage\Tests;
use PHPUnit\Framework\TestCase;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
class FooTest extends TestCase
{
use ExpectException;
use ExpectPHPException;
public function testSomething()
{
$this->expectWarningMessage( 'A non-numeric value encountered' );
}
}
```
Features
--------
### Polyfill traits
#### PHPUnit < 5.0.0: `Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType`
Polyfills the following methods:
| | | |
|----------------------------|------------------------------|-------------------------|
| [`Assert::assertFinite()`] | [`Assert::assertInfinite()`] | [`Assert::assertNan()`] |
These methods were introduced in PHPUnit 5.0.0.
[`Assert::assertFinite()`]: https://phpunit.readthedocs.io/en/stable/assertions.html#assertinfinite
[`Assert::assertInfinite()`]: https://phpunit.readthedocs.io/en/stable/assertions.html#assertinfinite
[`Assert::assertNan()`]: https://phpunit.readthedocs.io/en/stable/assertions.html#assertnan
#### PHPUnit < 5.2.0: `Yoast\PHPUnitPolyfills\Polyfills\ExpectException`
Polyfills the following methods:
| | |
|-------------------------------------|----------------------------------------------|
| [`TestCase::expectException()`] | [`TestCase::expectExceptionMessage()`]
没有合适的资源?快使用搜索试试~ 我知道了~
PHP给pdf添加多行水印+PHP,pdf+PHP添加水印
共4249个文件
php:2309个
inc:425个
dat:278个
需积分: 4 1 下载量 116 浏览量
2022-12-01
16:14:32
上传
评论
收藏 47.51MB RAR 举报
温馨提示
PHP给pdf添加多行水印
资源推荐
资源详情
资源评论
收起资源包目录
PHP给pdf添加多行水印+PHP,pdf+PHP添加水印 (4249个子文件)
random_compat.phar.pubkey.asc 488B
phpcbf.bat 423B
phpcs.bat 410B
phpcbf.bat 130B
phpcs.bat 129B
phpunit.bat 117B
install.cmd 385B
bootstrap.min.css 118KB
nv.d3.min.css 9KB
lang2fonts.css 9KB
bar.css 6KB
bluescreen.css 5KB
mpdf.css 2KB
style.css 2KB
ClassDefinitionOpeningBraceSpaceUnitTest.css 2KB
ClassDefinitionNameSpacingUnitTest.css 1KB
ShorthandSizeUnitTest.css 1KB
IndentationUnitTest.1.css 1KB
ClassDefinitionClosingBraceSpaceUnitTest.css 1KB
DuplicateClassDefinitionUnitTest.css 1KB
SemicolonSpacingUnitTest.css 1KB
ColonSpacingUnitTest.css 1003B
DisallowMultipleStyleDefinitionsUnitTest.css 854B
OpacityUnitTest.css 817B
dumper.css 810B
GitMergeConflictUnitTest.2.css 779B
GitMergeConflictUnitTest.1.css 771B
DuplicateStyleDefinitionUnitTest.css 677B
CommentedOutCodeUnitTest.css 489B
ForbiddenStylesUnitTest.css 480B
SuperfluousWhitespaceUnitTest.1.css 479B
toggle.css 444B
ColourDefinitionUnitTest.css 433B
LowercaseStyleDefinitionUnitTest.css 409B
MissingColonUnitTest.css 381B
style.css 361B
NamedColoursUnitTest.css 337B
BrowserSpecificStylesUnitTest.css 281B
EmptyClassDefinitionUnitTest.css 256B
EmptyStyleDefinitionUnitTest.css 232B
CSSLintUnitTest.css 149B
IndentationUnitTest.2.css 103B
DisallowTabIndentUnitTest.css 62B
DisallowSpaceIndentUnitTest.css 61B
SuperfluousWhitespaceUnitTest.3.css 51B
SuperfluousWhitespaceUnitTest.2.css 50B
LineEndingsUnitTest.css 49B
EndFileNoNewlineUnitTest.1.css 22B
EndFileNewlineUnitTest.1.css 22B
EndFileNoNewlineUnitTest.2.css 21B
EndFileNewlineUnitTest.2.css 21B
EndFileNoNewlineUnitTest.3.css 20B
EndFileNewlineUnitTest.3.css 20B
linebrdictK.dat 1MB
linebrdictT.dat 295KB
dejavuserifcondensed.cw.dat 128KB
dejavuserifcondensedB.cw.dat 128KB
linebrdictL.dat 124KB
qrv40_2.dat 87KB
qrv40_3.dat 87KB
qrv40_0.dat 87KB
qrv40_1.dat 87KB
qrv39_2.dat 83KB
qrv39_3.dat 83KB
qrv39_0.dat 83KB
qrv39_1.dat 83KB
qrv38_2.dat 79KB
qrv38_3.dat 79KB
qrv38_0.dat 79KB
qrv38_1.dat 79KB
qrv37_2.dat 75KB
qrv37_3.dat 75KB
qrv37_0.dat 75KB
qrv37_1.dat 75KB
qrv36_2.dat 71KB
qrv36_3.dat 71KB
qrv36_0.dat 71KB
qrv36_1.dat 71KB
qrv35_2.dat 67KB
qrv35_3.dat 67KB
qrv35_0.dat 67KB
qrv35_1.dat 67KB
qrv34_2.dat 65KB
qrv34_3.dat 65KB
qrv34_0.dat 65KB
qrv34_1.dat 65KB
qrv33_2.dat 61KB
qrv33_3.dat 61KB
qrv33_0.dat 61KB
qrv33_1.dat 61KB
qrv32_2.dat 58KB
qrv32_3.dat 58KB
qrv32_0.dat 58KB
qrv32_1.dat 58KB
qrv31_2.dat 55KB
qrv31_3.dat 55KB
qrv31_0.dat 55KB
qrv31_1.dat 55KB
qrv30_2.dat 51KB
qrv30_3.dat 51KB
共 4249 条
- 1
- 2
- 3
- 4
- 5
- 6
- 43
资源评论
sunsijia21983
- 粉丝: 86
- 资源: 70
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 信息办公个人求职管理系统-jobgljsp.rar
- 信息办公一流网络JSP网络管理系统 v1.0-yljsp10.rar
- chirpstack学习
- 管家婆辉煌、财贸、工贸、服装,食品,千方模拟狗
- 基于python开发的工业环境老鼠检测+源码+文档(毕业设计&课程设计&项目开发)
- USB转以太网的芯片SR9900全套设计资料包括(参考设计原理图PCB+ Linux -Windows驱动程序+量产工具)
- 信息办公XML考试系统-xmlks.rar
- 基于python开发的无人机图像目标检测+实验数据+开发文档+操作流程+源码(毕业设计&课程设计&项目开发)
- 全球智能商品管理与优化系统
- IDM下载器(电脑小工具)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功