feat(expect): add more methods

This commit is contained in:
ceceppa
2020-07-13 17:27:55 +01:00
parent 679082e805
commit 9f62f2d483
12 changed files with 388 additions and 8 deletions

View File

@ -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

View 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);

View 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);

View 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);

View 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);

View 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
View 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
View 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);

View 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);

View 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);

View 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);