diff --git a/.gitignore b/.gitignore index 4901aab..8ae88e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /vendor /composer.lock -/.phpunit.result.cache +/.phpunit.cache diff --git a/composer.json b/composer.json index a9700dd..c0034f7 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ }, "require-dev": { "ext-pdo": "*", - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^10.1", "vimeo/psalm": "5.24.0" }, "autoload": { diff --git a/phpunit.xml b/phpunit.xml index a964605..cd6319b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,13 @@ - + tests - + src - + diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index 41f18c8..3152c88 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -10,6 +10,8 @@ use Brick\ORM\Tests\Resources\Models\GeoAddress; use Brick\ORM\Tests\Resources\Models\User; use Brick\ORM\Tests\Resources\Objects\Geometry; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; class GatewayTest extends AbstractTestCase { @@ -30,9 +32,7 @@ public function testAddCountry() : void $this->assertDebugStatement(0, 'INSERT INTO Country (code, name) VALUES (?, ?)', 'GB', 'United Kingdom'); } - /** - * @depends testAddCountry - */ + #[Depends('testAddCountry')] public function testLoadUnknownCountry() : void { $this->assertNull(self::$countryRepository->load('XX')); @@ -41,11 +41,7 @@ public function testLoadUnknownCountry() : void $this->assertDebugStatement(0, 'SELECT a.code, a.name FROM Country AS a WHERE a.code = ?', 'XX'); } - /** - * @depends testLoadUnknownCountry - * - * @return Country - */ + #[Depends('testLoadUnknownCountry')] public function testLoadCountry() : Country { $country = self::$countryRepository->load('GB'); @@ -59,13 +55,7 @@ public function testLoadCountry() : Country return $country; } - /** - * @depends testLoadCountry - * - * @param Country $country - * - * @return User - */ + #[Depends('testLoadCountry')] public function testAddUser(Country $country) : User { $user = new User('John Smith'); @@ -92,13 +82,7 @@ public function testAddUser(Country $country) : User return $user; } - /** - * @depends testAddUser - * - * @param User $user - * - * @return int - */ + #[Depends('testAddUser')] public function testUpdateUser(User $user) : int { $address = $user->getBillingAddress(); @@ -124,13 +108,7 @@ public function testUpdateUser(User $user) : int return $user->getId(); } - /** - * @depends testUpdateUser - * - * @param int $userId - * - * @return int - */ + #[Depends('testUpdateUser')] public function testLoadPartialUser(int $userId) : int { $user = self::$userRepository->load($userId, 0, 'name'); @@ -156,13 +134,7 @@ public function testLoadPartialUser(int $userId) : int return $userId; } - /** - * @depends testLoadPartialUser - * - * @param int $userId - * - * @return User - */ + #[Depends('testLoadPartialUser')] public function testLoadUser(int $userId) : User { $user = self::$userRepository->load($userId); @@ -194,13 +166,7 @@ public function testLoadUser(int $userId) : User return $user; } - /** - * @depends testLoadUser - * - * @param User $user - * - * @return int - */ + #[Depends('testLoadUser')] public function testRemoveUser(User $user) : int { self::$userRepository->remove($user); @@ -211,13 +177,7 @@ public function testRemoveUser(User $user) : int return $user->getId(); } - /** - * @depends testRemoveUser - * - * @param int $userId - * - * @return void - */ + #[Depends('testRemoveUser')] public function testLoadRemovedUser(int $userId) : void { $user = self::$userRepository->load($userId); @@ -236,13 +196,12 @@ public function testLoadRemovedUser(int $userId) : void } /** - * @dataProvider providerLoadWithLock - * * @param int $options * @param string $sqlSuffix * * @return void */ + #[DataProvider('providerLoadWithLock')] public function testLoadWithLock(int $options, string $sqlSuffix) : void { self::$countryRepository->load('XX', $options); @@ -251,10 +210,7 @@ public function testLoadWithLock(int $options, string $sqlSuffix) : void $this->assertDebugStatement(0, 'SELECT a.code, a.name FROM Country AS a WHERE a.code = ? ' . $sqlSuffix, 'XX'); } - /** - * @return array - */ - public function providerLoadWithLock() : array + public static function providerLoadWithLock() : array { return [ [Options::LOCK_READ, 'FOR SHARE'], diff --git a/tests/InheritanceTest.php b/tests/InheritanceTest.php index 09cc63b..c5128ce 100644 --- a/tests/InheritanceTest.php +++ b/tests/InheritanceTest.php @@ -4,11 +4,13 @@ namespace Brick\ORM\Tests; -use Brick\ORM\Options; +use Brick\ORM\Exception\UnknownPropertyException; use Brick\ORM\Query; use Brick\ORM\Tests\Resources\Models\Country; use Brick\ORM\Tests\Resources\Models\Event; use Brick\ORM\Tests\Resources\Models\User; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; class InheritanceTest extends AbstractTestCase { @@ -60,13 +62,7 @@ public function testAddCreateCountryEvent() : int return $event->getId(); } - /** - * @depends testAddCreateCountryEvent - * - * @param int $eventId - * - * @return void - */ + #[Depends('testAddCreateCountryEvent')] public function testLoadCreateCountryEvent(int $eventId) : void { $event = self::$eventRepository->load($eventId); @@ -83,15 +79,14 @@ public function testLoadCreateCountryEvent(int $eventId) : void } /** - * @depends testAddCreateCountryEvent - * @dataProvider providerLoadCreateCountryEventUsingClass - * * @param string $class The class name to request. * @param string $sql The expected SQL query. * @param int $eventId The ID of the event to load. * * @return void */ + #[Depends('testAddCreateCountryEvent')] + #[DataProvider('providerLoadCreateCountryEventUsingClass')] public function testLoadCreateCountryEventUsingClass(string $class, string $sql, int $eventId) : void { $event = self::$gateway->load($class, ['id' => $eventId]); @@ -107,10 +102,7 @@ public function testLoadCreateCountryEventUsingClass(string $class, string $sql, $this->assertDebugStatement(0, $sql, $eventId); } - /** - * @return array - */ - public function providerLoadCreateCountryEventUsingClass() : array + public static function providerLoadCreateCountryEventUsingClass() : array { return [ [Event::class, self::LOAD_EVENT_SQL], @@ -120,14 +112,13 @@ public function providerLoadCreateCountryEventUsingClass() : array } /** - * @depends testAddCreateCountryEvent - * @dataProvider providerLoadCreateCountryEventUsingWrongClass - * * @param string $class The class name to request. * @param int $eventId The ID of the event to load. * * @return void */ + #[Depends('testAddCreateCountryEvent')] + #[DataProvider('providerLoadCreateCountryEventUsingWrongClass')] public function testLoadCreateCountryEventUsingWrongClass(string $class, int $eventId) : void { $this->expectException(\Exception::class); @@ -136,10 +127,7 @@ public function testLoadCreateCountryEventUsingWrongClass(string $class, int $ev self::$gateway->load($class, ['id' => $eventId]); } - /** - * @return array - */ - public function providerLoadCreateCountryEventUsingWrongClass() : array + public static function providerLoadCreateCountryEventUsingWrongClass() : array { return [ [Event\CountryEvent\EditCountryNameEvent::class], @@ -153,12 +141,11 @@ public function providerLoadCreateCountryEventUsingWrongClass() : array } /** - * @depends testAddCreateCountryEvent - * * @param int $eventId The ID of the event to load. * * @return void */ + #[Depends('testAddCreateCountryEvent')] public function testLoadPartialCreateCountryEvent(int $eventId) : void { $event = self::$eventRepository->load($eventId, 0, 'id', 'time'); @@ -184,26 +171,21 @@ public function testLoadPartialCreateCountryEvent(int $eventId) : void } /** - * @depends testAddCreateCountryEvent - * @expectedException \Brick\ORM\Exception\UnknownPropertyException - * @expectedExceptionMessage Class "Brick\ORM\Tests\Resources\Models\Event" has no persistent property named "country". - * * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddCreateCountryEvent')] public function testLoadPartialEventUsingPropertyFromChildClass(int $eventId) : void { + $this->expectException(UnknownPropertyException::class); + $this->expectExceptionMessage('Class "Brick\ORM\Tests\Resources\Models\Event" has no persistent property named "country".'); + self::$eventRepository->load($eventId, 0, 'time', 'country'); } /** - * @depends testAddCreateCountryEvent - * * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddCreateCountryEvent')] public function testLoadPartialCreateCountryEventUsingClass(int $eventId) : void { $event = self::$gateway->load(Event\CountryEvent::class, ['id' => $eventId], 0, 'id', 'time', 'country'); @@ -220,12 +202,9 @@ public function testLoadPartialCreateCountryEventUsingClass(int $eventId) : void } /** - * @depends testAddCreateCountryEvent - * * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddCreateCountryEvent')] public function testQueryCreateCountryEvent(int $eventId) : void { $query = new Query(Event::class); @@ -251,12 +230,9 @@ public function testQueryCreateCountryEvent(int $eventId) : void } /** - * @depends testAddCreateCountryEvent - * * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddCreateCountryEvent')] public function testQueryCreateCountryEventWithJoin(int $eventId) : void { $query = new Query(Event\CountryEvent::class); @@ -279,11 +255,7 @@ public function testQueryCreateCountryEventWithJoin(int $eventId) : void $this->assertDebugStatement(0, $expectedQuery, $eventId, 'France'); } - /** - * @depends testAddCreateCountryEvent - * - * @return int - */ + #[Depends('testAddCreateCountryEvent')] public function testAddEditCountryNameEvent() : int { $country = self::$countryRepository->load('FR'); @@ -301,13 +273,7 @@ public function testAddEditCountryNameEvent() : int return $event->getId(); } - /** - * @depends testAddEditCountryNameEvent - * - * @param int $eventId - * - * @return void - */ + #[Depends('testAddEditCountryNameEvent')] public function testLoadEditCountryNameEvent(int $eventId) : void { $event = self::$eventRepository->load($eventId); @@ -325,15 +291,12 @@ public function testLoadEditCountryNameEvent(int $eventId) : void } /** - * @depends testAddEditCountryNameEvent - * @dataProvider providerLoadEditCountryNameEventUsingClass - * * @param string $class The class name to request. * @param string $sql The expected SQL query. * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddEditCountryNameEvent')] + #[DataProvider('providerLoadEditCountryNameEventUsingClass')] public function testLoadEditCountryNameEventUsingClass(string $class, string $sql, int $eventId) : void { $event = self::$gateway->load($class, ['id' => $eventId]); @@ -350,10 +313,7 @@ public function testLoadEditCountryNameEventUsingClass(string $class, string $sq $this->assertDebugStatement(0, $sql, $eventId); } - /** - * @return array - */ - public function providerLoadEditCountryNameEventUsingClass() : array + public static function providerLoadEditCountryNameEventUsingClass() : array { return [ [Event::class, self::LOAD_EVENT_SQL], @@ -363,14 +323,11 @@ public function providerLoadEditCountryNameEventUsingClass() : array } /** - * @depends testAddEditCountryNameEvent - * @dataProvider providerLoadEditCountryNameEventUsingWrongClass - * * @param string $class The class name to request. * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddEditCountryNameEvent')] + #[DataProvider('providerLoadEditCountryNameEventUsingWrongClass')] public function testLoadEditCountryNameEventUsingWrongClass(string $class, int $eventId) : void { $this->expectException(\Exception::class); @@ -379,10 +336,7 @@ public function testLoadEditCountryNameEventUsingWrongClass(string $class, int $ self::$gateway->load($class, ['id' => $eventId]); } - /** - * @return array - */ - public function providerLoadEditCountryNameEventUsingWrongClass() : array + public static function providerLoadEditCountryNameEventUsingWrongClass() : array { return [ [Event\CountryEvent\CreateCountryEvent::class], @@ -396,12 +350,9 @@ public function providerLoadEditCountryNameEventUsingWrongClass() : array } /** - * @depends testAddEditCountryNameEvent - * * @param int $eventId The ID of the event to load. - * - * @return void */ + #[Depends('testAddEditCountryNameEvent')] public function testLoadPartialEditCountryNameEventUsingClass(int $eventId) : void { $event = self::$gateway->load(Event\CountryEvent::class, ['id' => $eventId], 0, 'id', 'time', 'country'); @@ -449,12 +400,9 @@ public function testAddCreateUserEvent() : array } /** - * @depends testAddCreateUserEvent - * * @param int[] $ids The user and event IDs. - * - * @return void */ + #[Depends('testAddCreateUserEvent')] public function testLoadCreateUserEvent(array $ids) : void { [$userId, $eventId] = $ids; @@ -473,15 +421,14 @@ public function testLoadCreateUserEvent(array $ids) : void } /** - * @depends testAddCreateUserEvent - * @dataProvider providerLoadCreateUserEventUsingClass - * * @param string $class The class name to request. * @param string $sql The expected SQL query. * @param int[] $ids The User and Event IDs. * * @return void */ + #[Depends('testAddCreateUserEvent')] + #[DataProvider('providerLoadCreateUserEventUsingClass')] public function testLoadCreateUserEventUsingClass(string $class, string $sql, array $ids) : void { [$userId, $eventId] = $ids; @@ -499,10 +446,7 @@ public function testLoadCreateUserEventUsingClass(string $class, string $sql, ar $this->assertDebugStatement(0, $sql, $eventId); } - /** - * @return array - */ - public function providerLoadCreateUserEventUsingClass() : array + public static function providerLoadCreateUserEventUsingClass() : array { return [ [Event::class, self::LOAD_EVENT_SQL], @@ -512,14 +456,13 @@ public function providerLoadCreateUserEventUsingClass() : array } /** - * @depends testAddCreateUserEvent - * @dataProvider providerLoadCreateUserEventUsingWrongClass - * * @param string $class The class name to request. * @param int[] $ids The User and Event IDs. * * @return void */ + #[Depends('testAddCreateUserEvent')] + #[DataProvider('providerLoadCreateUserEventUsingWrongClass')] public function testLoadCreateUserEventUsingWrongClass(string $class, array $ids) : void { [$userId, $eventId] = $ids; @@ -530,10 +473,7 @@ public function testLoadCreateUserEventUsingWrongClass(string $class, array $ids self::$gateway->load($class, ['id' => $eventId]); } - /** - * @return array - */ - public function providerLoadCreateUserEventUsingWrongClass() : array + public static function providerLoadCreateUserEventUsingWrongClass() : array { return [ [Event\CountryEvent::class], @@ -547,12 +487,11 @@ public function providerLoadCreateUserEventUsingWrongClass() : array } /** - * @depends testAddCreateUserEvent - * * @param int[] $ids The User and (unused here) Event IDs. * * @return int[] */ + #[Depends('testAddCreateUserEvent')] public function testAddEditUserNameEvent(array $ids) : array { [$userId] = $ids; @@ -573,12 +512,11 @@ public function testAddEditUserNameEvent(array $ids) : array } /** - * @depends testAddEditUserNameEvent - * * @param int[] $ids The User and Event IDs. * * @return void */ + #[Depends('testAddEditUserNameEvent')] public function testLoadEditUserNameEvent(array $ids) : void { [$userId, $eventId] = $ids; @@ -598,15 +536,14 @@ public function testLoadEditUserNameEvent(array $ids) : void } /** - * @depends testAddEditUserNameEvent - * @dataProvider providerLoadEditUserNameEventUsingClass - * * @param string $class The class name to request. * @param string $sql The expected SQL query. * @param int[] $ids The User and Event IDs. * * @return void */ + #[Depends('testAddEditUserNameEvent')] + #[DataProvider('providerLoadEditUserNameEventUsingClass')] public function testLoadEditUserNameEventUsingClass(string $class, string $sql, array $ids) : void { [$userId, $eventId] = $ids; @@ -625,10 +562,7 @@ public function testLoadEditUserNameEventUsingClass(string $class, string $sql, $this->assertDebugStatement(0, $sql, $eventId); } - /** - * @return array - */ - public function providerLoadEditUserNameEventUsingClass() : array + public static function providerLoadEditUserNameEventUsingClass() : array { return [ [Event::class, self::LOAD_EVENT_SQL], @@ -638,14 +572,13 @@ public function providerLoadEditUserNameEventUsingClass() : array } /** - * @depends testAddEditUserNameEvent - * @dataProvider providerLoadEditUserNameEventUsingWrongClass - * * @param string $class The class name to request. * @param int[] $ids The User and Event IDs. * * @return void */ + #[Depends('testAddEditUserNameEvent')] + #[DataProvider('providerLoadEditUserNameEventUsingWrongClass')] public function testLoadEditUserNameEventUsingWrongClass(string $class, array $ids) : void { [$userId, $eventId] = $ids; @@ -656,10 +589,7 @@ public function testLoadEditUserNameEventUsingWrongClass(string $class, array $i self::$gateway->load($class, ['id' => $eventId]); } - /** - * @return array - */ - public function providerLoadEditUserNameEventUsingWrongClass() : array + public static function providerLoadEditUserNameEventUsingWrongClass() : array { return [ [Event\CountryEvent::class],