diff --git a/tests/AbstractUsernamePasswordAuthenticationStrategyTest.php b/tests/AbstractUsernamePasswordAuthenticationStrategyTest.php index e97631a9..b919da98 100644 --- a/tests/AbstractUsernamePasswordAuthenticationStrategyTest.php +++ b/tests/AbstractUsernamePasswordAuthenticationStrategyTest.php @@ -10,18 +10,17 @@ use Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy; use Joomla\Authentication\Authentication; use Joomla\Authentication\Password\HandlerInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ +#[CoversClass(AbstractUsernamePasswordAuthenticationStrategy::class)] class AbstractUsernamePasswordAuthenticationStrategyTest extends TestCase { - /** - * @testdox A user can be successfully authenticated - * - * @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy - */ + #[TestDox('A user can be successfully authenticated')] public function testAuthenticateSuccess() { $handler = $this->createMock(HandlerInterface::class); @@ -45,11 +44,7 @@ protected function getHashedPassword($username) $this->assertSame(Authentication::SUCCESS, $strategy->getResult(), 'The correct result status is set'); } - /** - * @testdox A user cannot be authenticated when a password cannot be found for the username - * - * @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy - */ + #[TestDox('A user cannot be authenticated when a password cannot be found for the username')] public function testAuthenticateNoUser() { $handler = $this->createMock(HandlerInterface::class); @@ -72,11 +67,7 @@ protected function getHashedPassword($username) $this->assertSame(Authentication::NO_SUCH_USER, $strategy->getResult(), 'The correct result status is set'); } - /** - * @testdox A user cannot be authenticated when the password cannot be validated - * - * @covers Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy - */ + #[TestDox('A user cannot be authenticated when the password cannot be validated')] public function testAuthenticateInvalidPassword() { $handler = $this->createMock(HandlerInterface::class); diff --git a/tests/AuthenticationTest.php b/tests/AuthenticationTest.php index 3a7e5102..75ac9885 100644 --- a/tests/AuthenticationTest.php +++ b/tests/AuthenticationTest.php @@ -9,11 +9,13 @@ use Joomla\Authentication\Authentication; use Joomla\Authentication\AuthenticationStrategyInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\Authentication */ +#[CoversClass(Authentication::class)] class AuthenticationTest extends TestCase { /** @@ -35,8 +37,6 @@ protected function setUp(): void /** * Tests the authenticate method, specifying the strategy by name. - * - * @covers Joomla\Authentication\Authentication */ public function testSingleStrategy() { @@ -53,8 +53,6 @@ public function testSingleStrategy() /** * Tests the authenticate method, using all strategies - * - * @covers Joomla\Authentication\Authentication */ public function testSingleStrategyEmptyArray() { @@ -71,8 +69,6 @@ public function testSingleStrategyEmptyArray() /** * Tests the authenticate method, using some strategies. - * - * @covers Joomla\Authentication\Authentication */ public function testSomeStrategies() { @@ -101,8 +97,6 @@ public function testSomeStrategies() /** * Tests the authenticate method, using a non registered strategy - * - * @covers Joomla\Authentication\Authentication */ public function testStrategiesException() { @@ -113,8 +107,6 @@ public function testStrategiesException() /** * Tests getting the result back. - * - * @covers Joomla\Authentication\Authentication */ public function testGetResults() { diff --git a/tests/Password/Argon2iHandlerTest.php b/tests/Password/Argon2iHandlerTest.php index 7ccbc6d1..ee843a1c 100644 --- a/tests/Password/Argon2iHandlerTest.php +++ b/tests/Password/Argon2iHandlerTest.php @@ -8,11 +8,14 @@ namespace Joomla\Authentication\Tests\Password; use Joomla\Authentication\Password\Argon2iHandler; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\Password\Argon2iHandler */ +#[CoversClass(Argon2iHandler::class)] class Argon2iHandlerTest extends TestCase { /** @@ -27,11 +30,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); } - /** - * @testdox A password is hashed and validated - * - * @covers Joomla\Authentication\Password\Argon2iHandler - */ + #[TestDox('A password is hashed and validated')] public function testAPasswordIsHashedAndValidated() { $handler = new Argon2iHandler(); diff --git a/tests/Password/Argon2idHandlerTest.php b/tests/Password/Argon2idHandlerTest.php index c9b31018..9afbbf15 100644 --- a/tests/Password/Argon2idHandlerTest.php +++ b/tests/Password/Argon2idHandlerTest.php @@ -8,11 +8,14 @@ namespace Joomla\Authentication\Tests\Password; use Joomla\Authentication\Password\Argon2idHandler; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\Password\Argon2idHandler */ +#[CoversClass(Argon2idHandler::class)] class Argon2idHandlerTest extends TestCase { /** @@ -27,11 +30,7 @@ public static function setUpBeforeClass(): void parent::setUpBeforeClass(); } - /** - * @testdox A password is hashed and validated - * - * @covers Joomla\Authentication\Password\Argon2idHandler - */ + #[TestDox('A password is hashed and validated')] public function testAPasswordIsHashedAndValidated() { $handler = new Argon2idHandler(); diff --git a/tests/Password/BCryptHandlerTest.php b/tests/Password/BCryptHandlerTest.php index 9e4048d4..6911052b 100644 --- a/tests/Password/BCryptHandlerTest.php +++ b/tests/Password/BCryptHandlerTest.php @@ -8,18 +8,17 @@ namespace Joomla\Authentication\Tests\Password; use Joomla\Authentication\Password\BCryptHandler; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\Password\BCryptHandler */ +#[CoversClass(BCryptHandler::class)] class BCryptHandlerTest extends TestCase { - /** - * @testdox A password is hashed and validated - * - * @covers Joomla\Authentication\Password\BCryptHandler - */ + #[TestDox('A password is hashed and validated')] public function testAPasswordIsHashedAndValidated() { $handler = new BCryptHandler(); diff --git a/tests/Strategies/DatabaseStrategyTest.php b/tests/Strategies/DatabaseStrategyTest.php index 5a6f5512..d8ff0a81 100644 --- a/tests/Strategies/DatabaseStrategyTest.php +++ b/tests/Strategies/DatabaseStrategyTest.php @@ -7,6 +7,7 @@ namespace Joomla\Authentication\Tests\Strategies; +use Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy; use Joomla\Authentication\Authentication; use Joomla\Authentication\Password\HandlerInterface; use Joomla\Authentication\Strategies\DatabaseStrategy; @@ -14,12 +15,16 @@ use Joomla\Database\DatabaseInterface; use Joomla\Database\QueryInterface; use Joomla\Input\Input; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * Test class for \Joomla\Authentication\Strategies\DatabaseStrategy */ +#[CoversClass(DatabaseStrategy::class)] +#[UsesClass(AbstractUsernamePasswordAuthenticationStrategy::class)] class DatabaseStrategyTest extends TestCase { /** @@ -51,30 +56,27 @@ protected function setUp(): void /** * Tests the authenticate method with valid credentials. - * - * @covers Joomla\Authentication\Strategies\DatabaseStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testValidPassword() { $query = $this->createMock(QueryInterface::class); - $query->expects($this->any()) + $query->expects($this->once()) ->method('select') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('from') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('where') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('bind') ->willReturnSelf(); - $this->db->expects($this->any()) + $this->db->expects($this->once()) ->method('createQuery') ->willReturn($query); @@ -87,11 +89,11 @@ public function testValidPassword() ->method('loadResult') ->willReturn('$2y$10$.vpEGa99w.WUetDFJXjMn.RiKRhZ/ImzxtOjtoJ0VFDV8S7ua0uJG'); - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0); - $this->passwordHandler->expects($this->any()) + $this->passwordHandler->expects($this->once()) ->method('validatePassword') ->willReturn(true); @@ -103,30 +105,27 @@ public function testValidPassword() /** * Tests the authenticate method with invalid credentials. - * - * @covers Joomla\Authentication\Strategies\DatabaseStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testInvalidPassword() { $query = $this->createMock(QueryInterface::class); - $query->expects($this->any()) + $query->expects($this->once()) ->method('select') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('from') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('where') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('bind') ->willReturnSelf(); - $this->db->expects($this->any()) + $this->db->expects($this->once()) ->method('createQuery') ->willReturn($query); @@ -139,11 +138,11 @@ public function testInvalidPassword() ->method('loadResult') ->willReturn('$2y$10$.vpEGa99w.WUetDFJXjMn.RiKRhZ/ImzxtOjtoJ0VFDV8S7ua0uJH'); - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0); - $this->passwordHandler->expects($this->any()) + $this->passwordHandler->expects($this->once()) ->method('validatePassword') ->willReturn(false); @@ -155,16 +154,13 @@ public function testInvalidPassword() /** * Tests the authenticate method with no credentials provided. - * - * @covers Joomla\Authentication\Strategies\DatabaseStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testNoPassword() { $this->db->expects($this->never()) ->method('setQuery'); - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturn(false); @@ -179,30 +175,27 @@ public function testNoPassword() /** * Tests the authenticate method with credentials for an unknown user. - * - * @covers Joomla\Authentication\Strategies\DatabaseStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testUserNotExist() { $query = $this->createMock(QueryInterface::class); - $query->expects($this->any()) + $query->expects($this->once()) ->method('select') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('from') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('where') ->willReturnSelf(); - $query->expects($this->any()) + $query->expects($this->once()) ->method('bind') ->willReturnSelf(); - $this->db->expects($this->any()) + $this->db->expects($this->once()) ->method('createQuery') ->willReturn($query); @@ -215,7 +208,7 @@ public function testUserNotExist() ->method('loadResult') ->willReturn(null); - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0); diff --git a/tests/Strategies/LocalStrategyTest.php b/tests/Strategies/LocalStrategyTest.php index 3d27a626..db2d0a6f 100644 --- a/tests/Strategies/LocalStrategyTest.php +++ b/tests/Strategies/LocalStrategyTest.php @@ -7,16 +7,21 @@ namespace Joomla\Authentication\Tests\Strategies; +use Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy; use Joomla\Authentication\Authentication; use Joomla\Authentication\Password\HandlerInterface; use Joomla\Authentication\Strategies\LocalStrategy; use Joomla\Input\Input; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * Test class for Joomla\Authentication\Strategies\LocalStrategy */ +#[CoversClass(LocalStrategy::class)] +#[UsesClass(AbstractUsernamePasswordAuthenticationStrategy::class)] class LocalStrategyTest extends TestCase { /** @@ -42,17 +47,14 @@ protected function setUp(): void /** * Tests the authenticate method with valid credentials. - * - * @covers Joomla\Authentication\Strategies\LocalStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testValidPassword() { - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0); - $this->passwordHandler->expects($this->any()) + $this->passwordHandler->expects($this->once()) ->method('validatePassword') ->willReturn(true); @@ -69,17 +71,14 @@ public function testValidPassword() /** * Tests the authenticate method with invalid credentials. - * - * @covers Joomla\Authentication\Strategies\LocalStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testInvalidPassword() { - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0); - $this->passwordHandler->expects($this->any()) + $this->passwordHandler->expects($this->once()) ->method('validatePassword') ->willReturn(false); @@ -96,13 +95,10 @@ public function testInvalidPassword() /** * Tests the authenticate method with no credentials provided. - * - * @covers Joomla\Authentication\Strategies\LocalStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testNoPassword() { - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturn(false); @@ -122,13 +118,10 @@ public function testNoPassword() /** * Tests the authenticate method with credentials for an unknown user. - * - * @covers Joomla\Authentication\Strategies\LocalStrategy - * @uses Joomla\Authentication\AbstractUsernamePasswordAuthenticationStrategy */ public function testUserNotExist() { - $this->input->expects($this->any()) + $this->input->expects($this->exactly(2)) ->method('get') ->willReturnArgument(0);