Skip to content

Commit

Permalink
Merge branch '11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 25, 2024
2 parents 7ca3aec + 1d5704f commit 3744ac9
Show file tree
Hide file tree
Showing 56 changed files with 287 additions and 677 deletions.
5 changes: 2 additions & 3 deletions tests/_files/3194.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

trait T3194
Expand All @@ -29,9 +30,7 @@ public function doSomething(): bool
}
}

/**
* @covers \PHPUnit\TestFixture\C3194
*/
#[CoversClass(C3194::class)]
final class Test3194 extends TestCase
{
public function testOne(): void
Expand Down
65 changes: 18 additions & 47 deletions tests/_files/BankAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

#[CoversFunction(BankAccount::class)]
class BankAccountTest extends TestCase
{
protected $ba;

protected function setUp(): void
{
$this->ba = new BankAccount;
}

/**
* @covers BankAccount::getBalance
*
* @group balanceIsInitiallyZero
* @group specification
* @group 1234
*/
#[Group('balanceIsInitiallyZero')]
#[Group('specification')]
#[Group('1234')]
public function testBalanceIsInitiallyZero(): void
{
/* @Given a fresh bank account */
Expand All @@ -39,58 +31,37 @@ public function testBalanceIsInitiallyZero(): void
$this->assertEquals(0, $balance);
}

/**
* @covers BankAccount::withdrawMoney
*
* @group balanceCannotBecomeNegative
* @group specification
*/
#[Group('balanceCannotBecomeNegative')]
#[Group('specification')]
public function testBalanceCannotBecomeNegative(): void
{
$ba = new BankAccount;

try {
$this->ba->withdrawMoney(1);
$ba->withdrawMoney(1);
} catch (BankAccountException) {
$this->assertEquals(0, $this->ba->getBalance());
$this->assertEquals(0, $ba->getBalance());

return;
}

$this->fail();
}

/**
* @covers BankAccount::depositMoney
*
* @group balanceCannotBecomeNegative
* @group specification
*/
#[Group('balanceCannotBecomeNegative')]
#[Group('specification')]
public function testBalanceCannotBecomeNegative2(): void
{
$ba = new BankAccount;

try {
$this->ba->depositMoney(-1);
$ba->depositMoney(-1);
} catch (BankAccountException) {
$this->assertEquals(0, $this->ba->getBalance());
$this->assertEquals(0, $ba->getBalance());

return;
}

$this->fail();
}

/*
* @covers BankAccount::getBalance
* @covers BankAccount::depositMoney
* @covers BankAccount::withdrawMoney
* @group balanceCannotBecomeNegative
*/
/*
public function testDepositingAndWithdrawingMoneyWorks()
{
$this->assertEquals(0, $this->ba->getBalance());
$this->ba->depositMoney(1);
$this->assertEquals(1, $this->ba->getBalance());
$this->ba->withdrawMoney(1);
$this->assertEquals(0, $this->ba->getBalance());
}
*/
}
9 changes: 4 additions & 5 deletions tests/_files/CoverageClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(CoveredClass::class)]
#[UsesClass(CoveredClass::class)]
class CoverageClassTest extends TestCase
{
/**
* @covers \PHPUnit\TestFixture\CoveredClass
*
* @uses \PHPUnit\TestFixture\CoveredClass
*/
public function testSomething(): void
{
$o = new CoveredClass;
Expand Down
9 changes: 4 additions & 5 deletions tests/_files/CoverageFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\CoversFunction;
use PHPUnit\Framework\Attributes\UsesFunction;
use PHPUnit\Framework\TestCase;

#[CoversFunction('globalFunction')]
#[UsesFunction('globalFunction')]
class CoverageFunctionTest extends TestCase
{
/**
* @covers ::globalFunction
*
* @uses ::globalFunction
*/
public function testSomething(): void
{
globalFunction();
Expand Down
5 changes: 2 additions & 3 deletions tests/_files/CoverageMethodNothingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;

#[CoversNothing]
class CoverageMethodNothingTest extends TestCase
{
/**
* @coversNothing
*/
public function testSomething(): void
{
$o = new CoveredClass;
Expand Down
17 changes: 3 additions & 14 deletions tests/_files/DependencyOnClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\DependsOnClass;
use PHPUnit\Framework\TestCase;

class DependencyOnClassTest extends TestCase
{
/**
* Guard support for using annotations to depend on a whole successful TestSuite.
*
* @depends PHPUnit\TestFixture\DependencySuccessTest::class
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3519
*/
#[DependsOnClass(DependencySuccessTest::class)]
public function testThatDependsOnASuccessfulClass(): void
{
$this->assertTrue(true);
}

/**
* Guard support for using annotations to depend on a whole failing TestSuite.
*
* @depends PHPUnit\TestFixture\DependencyFailureTest::class
*
* @see https://github.com/sebastianbergmann/phpunit/issues/3519
*/
#[DependsOnClass(DependencyFailureTest::class)]
public function testThatDependsOnAFailingClass(): void
{
$this->assertTrue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;

class DoesNotPerformAssertionsButPerformingAssertionsTest extends TestCase
{
/**
* @doesNotPerformAssertions
*/
#[DoesNotPerformAssertions]
public function testFalseAndTrueAreStillFine(): void
{
$this->assertFalse(false);
Expand Down
5 changes: 2 additions & 3 deletions tests/_files/IniTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
namespace PHPUnit\TestFixture;

use function ini_get;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\TestCase;

class IniTest extends TestCase
{
/**
* @preserveGlobalState enabled
*/
#[PreserveGlobalState(true)]
public function testIni(): void
{
$this->assertEquals('application/x-test', ini_get('default_mimetype'));
Expand Down
Loading

0 comments on commit 3744ac9

Please sign in to comment.