Skip to content

Commit

Permalink
Migrate to PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed May 2, 2024
1 parent b638587 commit 0437dca
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor
/composer.lock
/.phpunit.result.cache
/.phpunit.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"require-dev": {
"ext-pdo": "*",
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^10.1",
"vimeo/psalm": "5.24.0"
},
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="ORM tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</source>
</phpunit>
68 changes: 12 additions & 56 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'));
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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'],
Expand Down
Loading

0 comments on commit 0437dca

Please sign in to comment.