feat: improve init files

This commit is contained in:
Nuno Maduro
2020-12-27 15:24:21 +01:00
parent 26b2e3561a
commit 424e24d530
6 changed files with 44 additions and 56 deletions

View File

@ -36,14 +36,10 @@ final class PestInstallCommand extends Command
{ {
/* @phpstan-ignore-next-line */ /* @phpstan-ignore-next-line */
$pest = base_path('tests/Pest.php'); $pest = base_path('tests/Pest.php');
/* @phpstan-ignore-next-line */ $stubs = 'stubs/Laravel';
$helpers = base_path('tests/Helpers.php');
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
foreach ([$pest, $helpers] as $file) { if (File::exists($pest)) {
if (File::exists($file)) { throw new InvalidConsoleArgument(sprintf('%s already exist', $pest));
throw new InvalidConsoleArgument(sprintf('%s already exist', $file));
}
} }
File::copy(implode(DIRECTORY_SEPARATOR, [ File::copy(implode(DIRECTORY_SEPARATOR, [
@ -52,14 +48,7 @@ final class PestInstallCommand extends Command
'Pest.php', 'Pest.php',
]), $pest); ]), $pest);
File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
$stubs,
'Helpers.php',
]), $helpers);
$this->output->success('`tests/Pest.php` created successfully.'); $this->output->success('`tests/Pest.php` created successfully.');
$this->output->success('`tests/Helpers.php` created successfully.');
if (!(bool) $this->option('no-interaction')) { if (!(bool) $this->option('no-interaction')) {
(new Thanks($this->output))(); (new Thanks($this->output))();

View File

@ -1,11 +0,0 @@
<?php
namespace Tests;
/**
* A basic assert example.
*/
function assertExample(): void
{
test()->assertTrue(true);
}

View File

@ -1,3 +1,44 @@
<?php <?php
/*
|--------------------------------------------------------------------------
| Underlying Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/
uses(Tests\TestCase::class)->in('Feature'); uses(Tests\TestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something() {
// ..
});

View File

@ -1,11 +0,0 @@
<?php
namespace Tests;
/**
* A basic assert example.
*/
function assertExample(): void
{
test()->assertTrue(true);
}

View File

@ -1,3 +0,0 @@
<?php
uses(TestCase::class)->in(__DIR__);

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
</phpunit>