mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
use Pest\Exceptions\DatasetMissing;
|
|
use Pest\Exceptions\TestAlreadyExist;
|
|
use Pest\TestSuite;
|
|
|
|
it('does not allow to add the same test description twice', function () {
|
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
$test = function () {};
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
|
})->throws(
|
|
TestAlreadyExist::class,
|
|
sprintf('A test with the description `%s` already exist in the filename `%s`.', 'foo', __FILE__),
|
|
);
|
|
|
|
it('alerts users about tests with arguments but no input', function () {
|
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
$test = function (int $arg) {};
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
|
})->throws(
|
|
DatasetMissing::class,
|
|
sprintf("A test with the description '%s' has %d argument(s) ([%s]) and no dataset(s) provided in %s", 'foo', 1, 'int $arg', __FILE__),
|
|
);
|
|
|
|
it('can return an array of all test suite filenames', function () {
|
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
$test = function () {};
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'bar', $test));
|
|
|
|
expect($testSuite->tests->getFilenames())->toEqual([
|
|
__FILE__,
|
|
__FILE__,
|
|
]);
|
|
});
|
|
|
|
it('can filter the test suite filenames to those with the only method', function () {
|
|
$testSuite = new TestSuite(getcwd(), 'tests');
|
|
$test = function () {};
|
|
|
|
$testWithOnly = new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test);
|
|
$testWithOnly->only = true;
|
|
$testSuite->tests->set($testWithOnly);
|
|
|
|
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory('Baz/Bar/Boo.php', 'bar', $test));
|
|
|
|
expect($testSuite->tests->getFilenames())->toEqual([
|
|
__FILE__,
|
|
]);
|
|
});
|