mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-16 03:54:55 +02:00
78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use TestProject\User;
|
|
|
|
/**
|
|
* @group file-group
|
|
*/
|
|
class UserTest extends TestCase
|
|
{
|
|
private User $sut;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->sut = new User(18, 'John');
|
|
}
|
|
|
|
public function testClassConstructor(): void
|
|
{
|
|
$user = new User(18, 'John');
|
|
$this->assertSame('John', $user->name);
|
|
$this->assertSame(18, $user->age);
|
|
$this->assertEmpty($user->favorite_movies);
|
|
}
|
|
|
|
/**
|
|
* @group special-tests
|
|
*/
|
|
public function testTellName(): void
|
|
{
|
|
$this->assertIsString($this->sut->tellName());
|
|
$this->assertStringContainsString('John', $this->sut->tellName());
|
|
}
|
|
|
|
public function testThrows(): void
|
|
{
|
|
$this->expectException(\Exception::class);
|
|
$this->expectExceptionMessage('oops!');
|
|
throw new \Exception('oops!');
|
|
}
|
|
|
|
public function testIsSkipped(): void
|
|
{
|
|
$this->markTestSkipped('Skipped to mirror Pest test.');
|
|
}
|
|
|
|
public function testCanTellAge(): void
|
|
{
|
|
$user = new User(18, 'John');
|
|
$this->assertIsString($user->tellAge());
|
|
$this->assertStringContainsString('18', $user->tellAge());
|
|
}
|
|
|
|
public function testIsFalse(): void
|
|
{
|
|
// Mirrors the original failing expectation in Pest
|
|
$this->assertFalse(true);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|