diff --git a/tests/Examples/some/deep/nesting/NestingTest.php b/tests/Examples/some/deep/nesting/NestingTest.php index ab44d70..6180959 100644 --- a/tests/Examples/some/deep/nesting/NestingTest.php +++ b/tests/Examples/some/deep/nesting/NestingTest.php @@ -1,5 +1,11 @@ expect(fn () => true) - ->toBeTrue(); +use PHPUnit\Framework\TestCase; + +class NestingTest extends TestCase +{ + public function testIsTrue(): void + { + $this->assertTrue(true); + } +} diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index c9ca67f..c7d55ba 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -1,52 +1,78 @@ group('file group'); +/** + * @group file-group + */ +class UserTest extends TestCase +{ + private User $sut; -$makeUser = fn () => new User(18, 'John'); + protected function setUp(): void + { + $this->sut = new User(18, 'John'); + } -beforeEach(function () use ($makeUser) { - $this->sut = $makeUser(); -}); + public function testClassConstructor(): void + { + $user = new User(18, 'John'); + $this->assertSame('John', $user->name); + $this->assertSame(18, $user->age); + $this->assertEmpty($user->favorite_movies); + } -test('class constructor') - ->expect($makeUser) - ->name->toBe('John') - ->age->toBe(18) - ->favorite_movies->toBeEmpty(); + /** + * @group special-tests + */ + public function testTellName(): void + { + $this->assertIsString($this->sut->tellName()); + $this->assertStringContainsString('John', $this->sut->tellName()); + } -test('tellName', function () { - expect($this->sut) - ->tellName()->toBeString()->toContain('John'); -}) - ->group('special tests'); + public function testThrows(): void + { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('oops!'); + throw new \Exception('oops!'); + } -it('throws', function () { - throw new \Exception('oops!'); -}); + public function testIsSkipped(): void + { + $this->markTestSkipped('Skipped to mirror Pest test.'); + } -it('is skipped')->skip(); + public function testCanTellAge(): void + { + $user = new User(18, 'John'); + $this->assertIsString($user->tellAge()); + $this->assertStringContainsString('18', $user->tellAge()); + } -it('can tellAge') - ->expect($makeUser) - ->tellAge()->toBeString()->toContain('18'); + public function testIsFalse(): void + { + // Mirrors the original failing expectation in Pest + $this->assertFalse(true); + } -it('is false')->expect(true)->toBeFalse(); + public function testAddFavoriteMovie(): void + { + $user = new User(18, 'John'); + $this->assertTrue($user->addFavoriteMovie('Avengers')); + $this->assertContains('Avengers', $user->favorite_movies); + $this->assertCount(1, $user->favorite_movies); + } -test('addFavoriteMovie') - ->expect($makeUser) - ->addFavoriteMovie('Avengers') - ->toBeTrue() - ->favorite_movies->toContain('Avengers')->toHaveLength(1); + public function testRemoveFavoriteMovie(): void + { + $user = new User(18, 'John'); + $this->assertTrue($user->addFavoriteMovie('Avengers')); + $this->assertTrue($user->addFavoriteMovie('Justice League')); + $this->assertTrue($user->removeFavoriteMovie('Avengers')); + $this->assertNotContains('Avengers', $user->favorite_movies); + $this->assertCount(1, $user->favorite_movies); + } +} -test('removeFavoriteMovie') - ->expect($makeUser) - ->addFavoriteMovie('Avengers')->toBeTrue() - ->addFavoriteMovie('Justice League')->toBeTrue() - ->removeFavoriteMovie('Avengers')->toBeTrue() - ->favorite_movies->not->toContain('Avengers')->toHaveLength(1); diff --git a/tests/Pest.php b/tests/Pest.php deleted file mode 100644 index 5949c61..0000000 --- a/tests/Pest.php +++ /dev/null @@ -1,45 +0,0 @@ -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() -{ - // .. -} diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index 7739dd4..b8cd89d 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -1,9 +1,16 @@ toBeTrue(); -}); +use PHPUnit\Framework\TestCase; -test("double quote example", function() { - expect(true)->toBeTrue(); -}); +class ExampleTest extends TestCase +{ + public function testExample(): void + { + $this->assertTrue(true); + } + + public function testDoubleQuoteExample(): void + { + $this->assertTrue(true); + } +}