Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Latest commit

 

History

History
172 lines (128 loc) · 3.43 KB

rector_rules_overview.md

File metadata and controls

172 lines (128 loc) · 3.43 KB

8 Rules Overview

AfterBeforeClassToAfterAllBeforeAllRector

Change @afterClass/@beforeClass to afterAll()/beforeAll() in Pest

 use PHPUnit\Framework\TestCase;

+afterAll(function () {
+    echo 'afterAll';
+});
+
 class AfterClassTest extends TestCase
 {
-    /**
-     * @afterClass
-     */
-    public function after()
-    {
-        echo 'afterAll';
-    }
 }

CustomTestCaseToUsesRector

Change parent test case class to uses() in Pest

-use Tests\AbstractCustomTestCase;
+uses(Tests\AbstractCustomTestCase::class);

-class CustomTestCaseTest extends AbstractCustomTestCase
+class CustomTestCaseTest
 {
     public function testCustomTestCase()
     {
     }
 }

PHPUnitTestToPestTestFunctionsRector

Convert PHPUnit test to Pest test functions

-use PHPUnit\Framework\TestCase;
-
-final class SomeTest extends TestCase
-{
-    public function test()
-    {
-        $result = 100 + 50;
-        $this->assertSame(150, $result);
-    }
-}
+test('test', function () {
+    $result = 100 + 50;
+    expect($result)->toBe(150);
+});

PestItNamingRector

Renames tests starting with it to use the it() function

-test('it starts with it')->skip();
+it('starts with it')->skip();

PhpDocGroupOnClassToFileScopeGroupRector

Changes @group phpdoc to uses()->group() in Pest

 use PHPUnit\Framework\TestCase;

-/**
- * @group testGroup
- */
+uses()->group('testGroup');
+
 class SomeClassTest extends TestCase
 {
 }

SetUpTearDownToBeforeEachAfterEachRector

Change setUp() class method to beforeEach() func call

-use PHPUnit\Framework\TestCase;
-
-class SetUpTest extends TestCase
-{
-    protected function setUp(): void
-    {
-        $value = 100;
-    }
-}
+beforeEach(function () {
+    $value = 100;
+});

TestClassMethodToPestTestFuncCallRector

Change PHPUnit test method to Pest test function

-use PHPUnit\Framework\TestCase;
-
-class ExampleTest extends TestCase
-{
-    public function testSimple()
-    {
-        $this->assertTrue(true);
-    }
-}
+test('testSimple', function () {
+    $this->assertTrue(true);
+});

TraitUsesToUsesRector

Move class trait uses to Pest uses() function

 use PHPUnit\Framework\TestCase;
+uses(SomeTrait::class);

 class SomeClass extends TestCase
 {
     use SomeTrait;
 }