Skip to content

Commit

Permalink
chore: uses PHPUnit attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jan 8, 2024
1 parent 751a38e commit f2f4972
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 151 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"laravel/tinker": "dev-develop",
"laravel/sail": "^1.26.2",
"laravel/sanctum": "^4.0.0",
"nunomaduro/larastan": "^3.0.0",
"larastan/larastan": "^2.8.0",
"orchestra/testbench-core": "^9.0.0",
"pestphp/pest": "^3.0.0",
"pestphp/pest": "^2.30.0 || ^3.0.0",
"sebastian/environment": "^7.0.0"
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon
parameters:
level: max
paths:
Expand Down
2 changes: 1 addition & 1 deletion tests/LaravelApp/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
|
*/

return Application::configure()
return Application::configure(dirname(__DIR__))
->withProviders()
->withRouting(
web: __DIR__.'/../routes/web.php',
Expand Down
21 changes: 0 additions & 21 deletions tests/LaravelApp/tests/CreatesApplication.php

This file was deleted.

5 changes: 2 additions & 3 deletions tests/LaravelApp/tests/Feature/CoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

/**
* @group coverage
*/
#[Group('coverage')]
class CoverageTest extends TestCase
{
public function testExample()
Expand Down
37 changes: 10 additions & 27 deletions tests/LaravelApp/tests/Feature/EnvironmentCustomVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

/**
* @group environmentCustomVariables
*/
#[Group('environmentCustomVariables')]
class EnvironmentCustomVariablesTest extends TestCase
{
/**
* @group environmentNoCVPhpunit
*/
#[Group('environmentNoCVPhpunit')]
public function testEnvironmentNoCustomVariablesPhpunit()
{
$this->assertEquals(null, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -23,9 +20,7 @@ public function testEnvironmentNoCustomVariablesPhpunit()
$this->assertEquals(null, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentNoCVParallel
*/
#[Group('environmentNoCVParallel')]
public function testEnvironmentNoCustomVariablesParallel()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -35,9 +30,7 @@ public function testEnvironmentNoCustomVariablesParallel()
$this->assertEquals(null, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentNoCVParallelRecreate
*/
#[Group('environmentNoCVParallelRecreate')]
public function testEnvironmentNoCustomVariablesParallelWithRecreate()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -48,9 +41,7 @@ public function testEnvironmentNoCustomVariablesParallelWithRecreate()
$this->assertEquals(null, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentNoCVParallelDrop
*/
#[Group('environmentNoCVParallelDrop')]
public function testEnvironmentNoCustomVariablesParallelWithDrop()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -61,9 +52,7 @@ public function testEnvironmentNoCustomVariablesParallelWithDrop()
$this->assertEquals(null, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentCVPhpunit
*/
#[Group('environmentCVPhpunit')]
public function testEnvironmentCustomVariablesPhpunit()
{
$this->assertEquals(null, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -73,9 +62,7 @@ public function testEnvironmentCustomVariablesPhpunit()
$this->assertEquals(null, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentCVParallel
*/
#[Group('environmentCVParallel')]
public function testEnvironmentCustomVariablesParallel()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -85,9 +72,7 @@ public function testEnvironmentCustomVariablesParallel()
$this->assertEquals(1, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentCVParallelRecreate
*/
#[Group('environmentCVParallelRecreate')]
public function testEnvironmentCustomVariablesParallelWithRecreate()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand All @@ -98,9 +83,7 @@ public function testEnvironmentCustomVariablesParallelWithRecreate()
$this->assertEquals(1, env('CUSTOM_ENV_VARIABLE_FOR_PARALLEL'));
}

/**
* @group environmentCVParallelDrop
*/
#[Group('environmentCVParallelDrop')]
public function testEnvironmentCustomVariablesParallelWithDrop()
{
$this->assertEquals(1, env('LARAVEL_PARALLEL_TESTING'));
Expand Down
12 changes: 6 additions & 6 deletions tests/LaravelApp/tests/Feature/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
* @group environment
*/
#[Group('environment')]
class EnvironmentTest extends TestCase
{
/** @test */
#[Test]
public function variableOnlyInDotEnv()
{
$this->assertEquals('VAL_IN_DOT_ENV', env('VAR_IN_DOT_ENV'));
$this->assertEquals(null, env('VAR_IN_DOT_ENV_TESTING'));
}

/** @test */
#[Test]
public function variableOnlyInPhpunit()
{
$this->assertEquals('VAL_IN_PHPUNIT', env('VAR_IN_PHPUNIT'));
}

/** @test */
#[Test]
public function variableInDotEnvButOverriddenInPhpunit()
{
$this->assertEquals('VAL_OVERRIDDEN_IN_PHPUNIT', env('VAR_OVERRIDDEN_IN_PHPUNIT'));
Expand Down
12 changes: 6 additions & 6 deletions tests/LaravelApp/tests/Feature/EnvironmentTestingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

namespace Tests\Feature;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

/**
* @group environmentTesting
*/
#[Group('environmentTesting')]
class EnvironmentTestingTest extends TestCase
{
/** @test */
#[Test]
public function variableOnlyInDotEnv()
{
$this->assertEquals(null, env('VAR_IN_DOT_ENV'));
$this->assertEquals('VAL_IN_DOT_ENV_TESTING', env('VAR_IN_DOT_ENV_TESTING'));
}

/** @test */
#[Test]
public function variableOnlyInPhpunit()
{
$this->assertEquals('VAL_IN_PHPUNIT', env('VAR_IN_PHPUNIT'));
}

/** @test */
#[Test]
public function variableInDotEnvButOverriddenInPhpunit()
{
$this->assertEquals('VAL_OVERRIDDEN_IN_PHPUNIT', env('VAR_OVERRIDDEN_IN_PHPUNIT'));
Expand Down
5 changes: 2 additions & 3 deletions tests/LaravelApp/tests/Feature/ExampleWithCustomNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tests\Feature;

use NunoMaduro\Collision\Contracts\Adapters\Phpunit\HasPrintableTestCaseName;
use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

class ExampleWithCustomNameTest extends TestCase implements HasPrintableTestCaseName
Expand All @@ -24,9 +25,7 @@ public static function getLatestPrintableTestCaseMethodName(): string
return 'my-custom-test-case-name';
}

/**
* @group custom-name
*/
#[Group('custom-name')]
public function testPassExample()
{
$this->assertTrue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

namespace LaravelApp\tests\Feature;

use PHPUnit\Framework\Attributes\Group;
use Tests\TestCase;

class ExampleWithUnexpectedOutputTest extends TestCase
{
/**
* @group unexpected-output
*/
#[Group('unexpected-output')]
public function testPassExample()
{
echo 'This is an unexpected output';
Expand Down
14 changes: 13 additions & 1 deletion tests/LaravelApp/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

namespace Tests;

use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Create a new application instance.
*/
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';

$app->make(Kernel::class)->bootstrap();

return $app;
}
}
33 changes: 9 additions & 24 deletions tests/LaravelApp/tests/Unit/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@

namespace Tests\Unit;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

error_reporting(E_ALL);

class ExampleTest extends TestCase
{
/**
* @group fail
*/
#[Group('fail')]
public function testFailExample()
{
$this->assertFalse(true);
}

/**
* @group todo
*/
#[Group('todo')]
public function testTodoExample()
{
$this->markTestSkipped('__TODO__');
Expand All @@ -29,59 +26,47 @@ public function testBasicTest()
$this->assertTrue(true);
}

/**
* @group notices
*/
#[Group('notices')]
public function testUserNotice()
{
trigger_error('This is a user notice');

$this->assertTrue(true);
}

/**
* @group notices
*/
#[Group('notices')]
public function testUserNoticeTwo()
{
trigger_error('This is another user notice');

$this->assertTrue(true);
}

/**
* @group warnings
*/
#[Group('warnings')]
public function testWarning()
{
$this->blabla;

$this->assertTrue(true);
}

/**
* @group warnings
*/
#[Group('warnings')]
public function testUserWarning()
{
trigger_error('This is a user warning', E_USER_WARNING);

$this->assertTrue(true);
}

/**
* @group deprecations
*/
#[Group('deprecations')]
public function testDeprecation()
{
str_contains(null, null);

$this->assertTrue(true);
}

/**
* @group deprecations
*/
#[Group('deprecations')]
public function testUserDeprecation()
{
trigger_deprecation('foo', '1.0', 'This is a deprecation description');
Expand Down
2 changes: 1 addition & 1 deletion tests/LaravelApp/vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

require __DIR__ . '/../../../vendor/autoload.php';
// require __DIR__ . '/../../../vendor/autoload.php';
2 changes: 1 addition & 1 deletion tests/Printer/DatasetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Printer;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class DatasetsTest extends TestCase
{
Expand Down
Loading

0 comments on commit f2f4972

Please sign in to comment.