mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat(expect): add more methods
This commit is contained in:
@ -5,6 +5,96 @@
|
||||
PASS Tests\Expect\ToBe
|
||||
✓ strict comparisons
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\thatDirectoryExists
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\thatDirectoryIsReadable
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeEmpty
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeFalse
|
||||
✓ strict comparisons
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeGreatherThan
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeGreatherThanOrEqual
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeLessThan
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toBeLessThanOrEqual
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toContain
|
||||
✓ passes
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toContainOnly
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toContainOnlyInstancesOf
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toContainString
|
||||
✓ is case sensitive
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toContainStringIgnoringCase
|
||||
✓ ignore difference in casing
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toCount
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqual
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualCanonicalizing
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualIgnoringCase
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Expect\toEqualWithDelta
|
||||
✓ pass
|
||||
✓ failures
|
||||
✓ not failures
|
||||
|
||||
PASS Tests\Features\AfterAll
|
||||
@ -172,5 +262,5 @@
|
||||
WARN Tests\Visual\Success
|
||||
- visual snapshot of test suite on success
|
||||
|
||||
Tests: 6 skipped, 99 passed
|
||||
Time: 3.62s
|
||||
Tests: 6 skipped, 153 passed
|
||||
Time: 4.35s
|
||||
|
||||
17
tests/Expect/thatDirectoryExists.php
Normal file
17
tests/Expect/thatDirectoryExists.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
$temp = sys_get_temp_dir();
|
||||
|
||||
expect($temp)->toBeExistingDirectory();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('/random/path/whatever')->toBeExistingDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect('.')->not->toBeExistingDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
15
tests/Expect/thatDirectoryIsReadable.php
Normal file
15
tests/Expect/thatDirectoryIsReadable.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(sys_get_temp_dir())->toBeWritableDirectory();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('/random/path/whatever')->toBeWritableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect(sys_get_temp_dir())->not->toBeWritableDirectory();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
18
tests/Expect/toBeEmpty.php
Normal file
18
tests/Expect/toBeEmpty.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([])->toBeEmpty();
|
||||
expect(null)->toBeEmpty();
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2])->toBeEmpty();
|
||||
expect(' ')->toBeEmpty();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect([])->not->toBeEmpty();
|
||||
expect(null)->not->toBeEmpty();
|
||||
})->throws(ExpectationFailedException::class);
|
||||
17
tests/Expect/toContainOnly.php
Normal file
17
tests/Expect/toContainOnly.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toContainOnly('int');
|
||||
expect(['hello', 'world'])->toContainOnly('string');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2, '3'])->toContainOnly('string');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect([1, 2, 3])->not->toContainOnly('int');
|
||||
expect(['hello', 'world'])->not->toContainOnly('string');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
23
tests/Expect/toContainOnlyInstancesOf.php
Normal file
23
tests/Expect/toContainOnlyInstancesOf.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Pest\Actions\AddsTests;
|
||||
use Pest\Expectation;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
$expected = [new Expectation('whatever')];
|
||||
|
||||
expect($expected)->toContainOnlyInstancesOf(Expectation::class);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
$expected = [new Expectation('whatever')];
|
||||
|
||||
expect($expected)->toContainOnlyInstancesOf(AddsTests::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
$expected = [new Expectation('whatever')];
|
||||
|
||||
expect($expected)->not->toContainOnlyInstancesOf(Expectation::class);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
15
tests/Expect/toCount.php
Normal file
15
tests/Expect/toCount.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect([1, 2, 3])->toCount(3);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect([1, 2, 3])->toCount(4);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect([1, 2, 3])->not->toCount(3);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
15
tests/Expect/toEqual.php
Normal file
15
tests/Expect/toEqual.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('00123')->toEqual(123);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(['a', 'b', 'c'])->toEqual(['a', 'b']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect('042')->not->toEqual(42);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
16
tests/Expect/toEqualCanonicalizing.php
Normal file
16
tests/Expect/toEqualCanonicalizing.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('00123')->toEqualCanonicalizing(123);
|
||||
expect(['a', 'b', 'c'])->toEqualCanonicalizing(['c', 'a', 'b']);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(['a', 'b', 'c'])->toEqualCanonicalizing(['a', 'b']);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect('042')->not->toEqualCanonicalizing(42);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
15
tests/Expect/toEqualIgnoringCase.php
Normal file
15
tests/Expect/toEqualIgnoringCase.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect('hello')->toEqualIgnoringCase('HELLO');
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect('hello')->toEqualIgnoringCase('BAR');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect('HELLO')->not->toEqualIgnoringCase('HelLo');
|
||||
})->throws(ExpectationFailedException::class);
|
||||
15
tests/Expect/toEqualWithDelta.php
Normal file
15
tests/Expect/toEqualWithDelta.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
test('pass', function () {
|
||||
expect(1.0)->toEqualWithDelta(1.3, .4);
|
||||
});
|
||||
|
||||
test('failures', function () {
|
||||
expect(1.0)->toEqualWithDelta(1.5, .1);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
|
||||
test('not failures', function () {
|
||||
expect(1.0)->not->toEqualWithDelta(1.6, .7);
|
||||
})->throws(ExpectationFailedException::class);
|
||||
Reference in New Issue
Block a user