mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
first
This commit is contained in:
32
tests/Unit/Actions/AddsCoverage.php
Normal file
32
tests/Unit/Actions/AddsCoverage.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Pest\Actions\AddsCoverage;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('adds coverage if --coverage exist', function () {
|
||||
$testSuite = new TestSuite(getcwd());
|
||||
assertFalse($testSuite->coverage);
|
||||
|
||||
$arguments = AddsCoverage::from($testSuite, []);
|
||||
assertEquals([], $arguments);
|
||||
assertFalse($testSuite->coverage);
|
||||
|
||||
$arguments = AddsCoverage::from($testSuite, ['--coverage']);
|
||||
assertEquals(['--coverage-php', \Pest\Console\Coverage::getPath()], $arguments);
|
||||
assertTrue($testSuite->coverage);
|
||||
});
|
||||
|
||||
it('adds coverage if --min exist', function () {
|
||||
$testSuite = new TestSuite(getcwd());
|
||||
assertEquals($testSuite->coverageMin, 0.0);
|
||||
|
||||
assertFalse($testSuite->coverage);
|
||||
AddsCoverage::from($testSuite, []);
|
||||
assertEquals($testSuite->coverageMin, 0.0);
|
||||
|
||||
AddsCoverage::from($testSuite, ['--min=2']);
|
||||
assertEquals($testSuite->coverageMin, 2.0);
|
||||
|
||||
AddsCoverage::from($testSuite, ['--min=2.4']);
|
||||
assertEquals($testSuite->coverageMin, 2.4);
|
||||
});
|
||||
20
tests/Unit/Actions/AddsDefaults.php
Normal file
20
tests/Unit/Actions/AddsDefaults.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use NunoMaduro\Collision\Adapters\Phpunit\Printer;
|
||||
use Pest\Actions\AddsDefaults;
|
||||
use PHPUnit\TextUI\DefaultResultPrinter;
|
||||
|
||||
it('sets defaults', function () {
|
||||
$arguments = AddsDefaults::to(['bar' => 'foo']);
|
||||
|
||||
assertInstanceOf(Printer::class, $arguments['printer']);
|
||||
assertEquals($arguments['bar'], 'foo');
|
||||
});
|
||||
|
||||
it('does not override options', function () {
|
||||
$defaultResultPrinter = new DefaultResultPrinter();
|
||||
|
||||
assertEquals(AddsDefaults::to(['printer' => $defaultResultPrinter]), [
|
||||
'printer' => $defaultResultPrinter,
|
||||
]);
|
||||
});
|
||||
32
tests/Unit/Actions/AddsTests.php
Normal file
32
tests/Unit/Actions/AddsTests.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Pest\Actions\AddsTests;
|
||||
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
|
||||
use PHPUnit\Framework\TestSuite;
|
||||
use PHPUnit\Framework\WarningTestCase;
|
||||
|
||||
$closure = function () {
|
||||
};
|
||||
$pestTestCase = new class() extends \PHPUnit\Framework\TestCase {
|
||||
};
|
||||
|
||||
test('default php unit tests', function () {
|
||||
$testSuite = new TestSuite();
|
||||
|
||||
$phpUnitTestCase = new class() extends PhpUnitTestCase {
|
||||
};
|
||||
$testSuite->addTest($phpUnitTestCase);
|
||||
assertCount(1, $testSuite->tests());
|
||||
|
||||
AddsTests::to($testSuite, new \Pest\TestSuite(getcwd()));
|
||||
assertCount(1, $testSuite->tests());
|
||||
});
|
||||
|
||||
it('removes warnings', function () use ($pestTestCase) {
|
||||
$testSuite = new TestSuite();
|
||||
$warningTestCase = new WarningTestCase('No tests found in class "Pest\TestCase".');
|
||||
$testSuite->addTest($warningTestCase);
|
||||
|
||||
AddsTests::to($testSuite, new \Pest\TestSuite(getcwd()));
|
||||
assertCount(0, $testSuite->tests());
|
||||
});
|
||||
42
tests/Unit/Actions/ValidatesConfiguration.php
Normal file
42
tests/Unit/Actions/ValidatesConfiguration.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Pest\Actions\ValidatesConfiguration;
|
||||
use Pest\Exceptions\AttributeNotSupportedYet;
|
||||
use Pest\Exceptions\FileOrFolderNotFound;
|
||||
|
||||
it('throws exception when configuration not found', function () {
|
||||
$this->expectException(FileOrFolderNotFound::class);
|
||||
|
||||
ValidatesConfiguration::in([
|
||||
'configuration' => 'foo',
|
||||
]);
|
||||
});
|
||||
|
||||
it('throws exception when `process isolation` is true', function () {
|
||||
$this->expectException(AttributeNotSupportedYet::class);
|
||||
$this->expectExceptionMessage('The PHPUnit attribute `processIsolation` with value `true` is not supported yet.');
|
||||
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'Fixtures',
|
||||
'phpunit-in-isolation.xml',
|
||||
]);
|
||||
|
||||
ValidatesConfiguration::in([
|
||||
'configuration' => $filename,
|
||||
]);
|
||||
});
|
||||
|
||||
it('do not throws exception when `process isolation` is false', function () {
|
||||
$filename = implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'Fixtures',
|
||||
'phpunit-not-in-isolation.xml',
|
||||
]);
|
||||
|
||||
ValidatesConfiguration::in([
|
||||
'configuration' => $filename,
|
||||
]);
|
||||
|
||||
assertTrue(true);
|
||||
});
|
||||
24
tests/Unit/Console/Coverage.php
Normal file
24
tests/Unit/Console/Coverage.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Pest\Console\Coverage;
|
||||
|
||||
it('generates coverage based on file input', function () {
|
||||
assertEquals([
|
||||
'4..6', '102',
|
||||
], Coverage::getMissingCoverage(new class() {
|
||||
public function getCoverageData(): array
|
||||
{
|
||||
return [
|
||||
1 => ['foo'],
|
||||
2 => ['bar'],
|
||||
4 => [],
|
||||
5 => [],
|
||||
6 => [],
|
||||
7 => null,
|
||||
100 => null,
|
||||
101 => ['foo'],
|
||||
102 => [],
|
||||
];
|
||||
}
|
||||
}));
|
||||
});
|
||||
11
tests/Unit/Support/Backtrace.php
Normal file
11
tests/Unit/Support/Backtrace.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
use Pest\Support\Backtrace;
|
||||
|
||||
it('gets file name from called file', function () {
|
||||
$a = function () {
|
||||
return Backtrace::file();
|
||||
};
|
||||
|
||||
assertEquals(__FILE__, $a());
|
||||
});
|
||||
19
tests/Unit/Support/Reflection.php
Normal file
19
tests/Unit/Support/Reflection.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Pest\Support\Reflection;
|
||||
|
||||
it('gets file name from closure', function () {
|
||||
$fileName = Reflection::getFileNameFromClosure(function () {});
|
||||
|
||||
assertEquals(__FILE__, $fileName);
|
||||
});
|
||||
|
||||
it('gets property values', function () {
|
||||
$class = new class() {
|
||||
private $foo = 'bar';
|
||||
};
|
||||
|
||||
$value = Reflection::getPropertyValue($class, 'foo');
|
||||
|
||||
assertEquals('bar', $value);
|
||||
});
|
||||
13
tests/Unit/TestSuite.php
Normal file
13
tests/Unit/TestSuite.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Pest\Exceptions\TestAlreadyExist;
|
||||
use Pest\TestSuite;
|
||||
|
||||
it('does not allow to add the same test description twice', function () {
|
||||
$testSuite = new TestSuite(getcwd());
|
||||
$test = function () {};
|
||||
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
||||
$this->expectException(TestAlreadyExist::class);
|
||||
$this->expectExceptionMessage(sprintf('A test with the description `%s` already exist in the filename `%s`.', 'foo', __FILE__));
|
||||
$testSuite->tests->set(new \Pest\Factories\TestCaseFactory(__FILE__, 'foo', $test));
|
||||
});
|
||||
Reference in New Issue
Block a user