mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +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);
|
||||
});
|
||||
Reference in New Issue
Block a user