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';
- }
}
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()
{
}
}
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);
+});
Renames tests starting with it
to use the it()
function
-test('it starts with it')->skip();
+it('starts with it')->skip();
Changes @group
phpdoc to uses()->group()
in Pest
use PHPUnit\Framework\TestCase;
-/**
- * @group testGroup
- */
+uses()->group('testGroup');
+
class SomeClassTest extends TestCase
{
}
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;
+});
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);
+});
Move class trait uses to Pest uses()
function
use PHPUnit\Framework\TestCase;
+uses(SomeTrait::class);
class SomeClass extends TestCase
{
use SomeTrait;
}