noregression / callable-comparator
使 PHPunit 断言中使用可调用函数成为可能
0.1.0
2015-12-17 20:53 UTC
Requires
- php: >=5.5.9
- sebastian/comparator: ~1.1
- sebastian/exporter: ~1.2
Requires (Dev)
- codeclimate/php-test-reporter: 0.1.*
- phpunit/phpunit: ~4.6
This package is not auto-updated.
Last update: 2024-09-14 18:58:24 UTC
README
使 PHPunit 断言中使用可调用函数成为可能
安装
composer require noregression/callable-comparator
用法
<?php require_once ('vendor/autoload.php'); use NoRegression\PHPUnit\CallableComparatorTrait; use NoRegression\PHPUnit\Comparator\Callables\CallableProxy; use NoRegression\PHPUnit\Comparator\Callables\IsDateTime; use NoRegression\PHPUnit\Comparator\Callables\IsUuid; use NoRegression\PHPUnit\Comparator\Callables\IsPasswordHashFor; class ExampleTest extends \PHPUnit_Framework_TestCase { use CallableComparatorTrait; public function setUp() { parent::setUp(); $this->setupCallableComparator(); } public function tearDown() { parent::tearDown(); $this->tearDownCallableComparator(); } public function testCallableComparator() { $data = [ 'id' => 'f4a2b7b0-e944-11e4-b571-0800200c9a66', 'modified' => '2015-03-22 01:12', 'bcrypt_password' => password_hash('password', PASSWORD_BCRYPT), 'default_password' => password_hash('password', PASSWORD_DEFAULT), 'emptystring' => '', 'contains' => 'This string contains "lazy fox".' ]; $expected = [ 'id' => new IsUuid(), 'modified' => new IsDateTime(), 'bcrypt_password' => new IsPasswordHashFor('password'), 'default_password' => new IsPasswordHashFor('password'), 'emptystring' => new CallableProxy([$this, 'assertEmpty']), 'contains' => new CallableProxy([$this, 'assertContains'], ['lazy fox']) ]; $this->assertEquals($expected, $data); } }