Skip to content

Commit

Permalink
Use assertions statically (since they are declared as static methods …
Browse files Browse the repository at this point in the history
…too)
  • Loading branch information
Ocramius committed Apr 23, 2021
1 parent 8e0630f commit 8df0b26
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 114 deletions.
6 changes: 3 additions & 3 deletions tests/Calculator/BcMathCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public function itSubtractsAValueFromAnotherWithScaleSet(int $value1, int $value
*/
public function itComparesNumbersCloseToZero(): void
{
$this->assertEquals(1, $this->getCalculator()::compare('1', '0.0005'));
$this->assertEquals(1, $this->getCalculator()::compare('1', '0.000000000000000000000000005'));
self::assertEquals(1, $this->getCalculator()::compare('1', '0.0005'));
self::assertEquals(1, $this->getCalculator()::compare('1', '0.000000000000000000000000005'));
}

/**
* @test
*/
public function itUsesScaleForAdd(): void
{
$this->assertEquals('0.00130154000000', $this->getCalculator()::add('0.00125148', '0.00005006'));
self::assertEquals('0.00130154000000', $this->getCalculator()::add('0.00125148', '0.00005006'));
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Calculator/CalculatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function itDividesAValueByAnotherExact(int $value1, int|float $value2, st
*/
public function itCeilsAValue(float $value, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::ceil((string) $value));
self::assertEquals($expected, $this->getCalculator()::ceil((string) $value));
}

/**
Expand All @@ -119,7 +119,7 @@ public function itCeilsAValue(float $value, string $expected): void
*/
public function itFloorsAValue(float $value, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::floor((string) $value));
self::assertEquals($expected, $this->getCalculator()::floor((string) $value));
}

/**
Expand All @@ -131,7 +131,7 @@ public function itFloorsAValue(float $value, string $expected): void
*/
public function itCalculatesTheAbsoluteValue(int $value, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::absolute((string) $value));
self::assertEquals($expected, $this->getCalculator()::absolute((string) $value));
}

/**
Expand All @@ -145,7 +145,7 @@ public function itCalculatesTheAbsoluteValue(int $value, string $expected): void
*/
public function itSharesAValue(int $value, int $ratio, int $total, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::share((string) $value, (string) $ratio, (string) $total));
self::assertEquals($expected, $this->getCalculator()::share((string) $value, (string) $ratio, (string) $total));
}

/**
Expand All @@ -158,7 +158,7 @@ public function itSharesAValue(int $value, int $ratio, int $total, string $expec
*/
public function itRoundsAValue(float|int|string $value, int $mode, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::round((string) $value, $mode));
self::assertEquals($expected, $this->getCalculator()::round((string) $value, $mode));
}

/**
Expand All @@ -172,8 +172,8 @@ public function itComparesValuesLess(int|string $left, int|string $right): void
{
// Compare with both orders. One must return a value less than zero,
// the other must return a value greater than zero.
$this->assertLessThan(0, $this->getCalculator()::compare((string) $left, (string) $right));
$this->assertGreaterThan(0, $this->getCalculator()::compare((string) $right, (string) $left));
self::assertLessThan(0, $this->getCalculator()::compare((string) $left, (string) $right));
self::assertGreaterThan(0, $this->getCalculator()::compare((string) $right, (string) $left));
}

/**
Expand All @@ -186,8 +186,8 @@ public function itComparesValuesLess(int|string $left, int|string $right): void
public function itComparesValues(int|string $left, int|string $right): void
{
// Compare with both orders, both must return zero.
$this->assertEquals(0, $this->getCalculator()::compare((string) $left, (string) $right));
$this->assertEquals(0, $this->getCalculator()::compare((string) $left, (string) $right));
self::assertEquals(0, $this->getCalculator()::compare((string) $left, (string) $right));
self::assertEquals(0, $this->getCalculator()::compare((string) $left, (string) $right));
}

/**
Expand All @@ -200,7 +200,7 @@ public function itComparesValues(int|string $left, int|string $right): void
*/
public function itCalculatesTheModulusOfAValue(int $left, int $right, string $expected): void
{
$this->assertEquals($expected, $this->getCalculator()::mod((string) $left, (string) $right));
self::assertEquals($expected, $this->getCalculator()::mod((string) $left, (string) $right));
}

/** @test */
Expand Down
8 changes: 4 additions & 4 deletions tests/Calculator/GmpCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ protected function getCalculator(): string
*/
public function itMultipliesZero(): void
{
$this->assertSame('0', $this->getCalculator()::multiply('0', '0.8'));
self::assertSame('0', $this->getCalculator()::multiply('0', '0.8'));
}

/**
* @test
*/
public function itFloorsZero(): void
{
$this->assertSame('0', $this->getCalculator()::floor('0'));
self::assertSame('0', $this->getCalculator()::floor('0'));
}

/**
* @test
*/
public function itComparesZeroWithFraction(): void
{
$this->assertSame(1, $this->getCalculator()::compare('0.5', '0'));
self::assertSame(1, $this->getCalculator()::compare('0.5', '0'));
}

/**
* @test
*/
public function it_divides_bug538(): void
{
$this->assertSame('-4.54545454545455', $this->getCalculator()::divide('-500', '110'));
self::assertSame('-4.54545454545455', $this->getCalculator()::divide('-500', '110'));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function itAcceptsOnlyMoney(): void
$money_a = Money::EUR(1);
$money_b = Money::EUR(2);

$this->assertFalse($this->comparator->accepts($money_a, false));
$this->assertFalse($this->comparator->accepts(false, $money_a));
$this->assertTrue($this->comparator->accepts($money_a, $money_b));
self::assertFalse($this->comparator->accepts($money_a, false));
self::assertFalse($this->comparator->accepts(false, $money_a));
self::assertTrue($this->comparator->accepts($money_a, $money_b));
}

/**
Expand All @@ -43,8 +43,8 @@ public function itComparesUnequalValues(): void
try {
$this->comparator->assertEquals($money_a, $money_b);
} catch (ComparisonFailure $e) {
$this->assertSame('Failed asserting that two Money objects are equal.', $e->getMessage());
$this->assertStringContainsString(
self::assertSame('Failed asserting that two Money objects are equal.', $e->getMessage());
self::assertStringContainsString(
'--- Expected
+++ Actual
@@ @@
Expand All @@ -56,7 +56,7 @@ public function itComparesUnequalValues(): void
return;
}

$this->fail('ComparisonFailure should have been thrown.');
self::fail('ComparisonFailure should have been thrown.');
}

/**
Expand All @@ -69,7 +69,7 @@ public function itComparesEqualValues(): void

$this->comparator->assertEquals($money_a, $money_b);

$this->assertEquals(
self::assertEquals(
$money_a,
$money_b,
'This is only here to increment the assertion counter, since we are testing an assertion'
Expand Down
4 changes: 2 additions & 2 deletions tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function itConvertsToADifferentCurrency(
$counterCurrency
);

$this->assertEquals($expectedAmount, $money->getAmount());
$this->assertEquals($counterCurrencyCode, $money->getCurrency()->getCode());
self::assertEquals($expectedAmount, $money->getAmount());
self::assertEquals($counterCurrencyCode, $money->getCurrency()->getCode());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Currencies/CurrencyListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function itHasCurrencies(string $currency): void
{
$currencies = new CurrencyList(self::CORRECT_CURRENCIES);

$this->assertTrue($currencies->contains(new Currency($currency)));
self::assertTrue($currencies->contains(new Currency($currency)));
}

/**
Expand All @@ -44,7 +44,7 @@ public function itProvidesSubunit(string $currency): void
{
$currencies = new CurrencyList(self::CORRECT_CURRENCIES);

$this->assertIsInt($currencies->subunitFor(new Currency($currency)));
self::assertIsInt($currencies->subunitFor(new Currency($currency)));
}

/**
Expand All @@ -68,7 +68,7 @@ public function itIsIterable(): void

$iterator = $currencies->getIterator();

$this->assertContainsOnlyInstancesOf(Currency::class, $iterator);
self::assertContainsOnlyInstancesOf(Currency::class, $iterator);
}

/** @psalm-return non-empty-list<array{non-empty-string}> */
Expand Down
8 changes: 4 additions & 4 deletions tests/Currencies/ISOCurrenciesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function itHasIsoCurrencies(string $currency): void
{
$currencies = new ISOCurrencies();

$this->assertTrue($currencies->contains(new Currency($currency)));
self::assertTrue($currencies->contains(new Currency($currency)));
}

/**
Expand All @@ -38,7 +38,7 @@ public function itProvidesSubunit(string $currency): void
{
$currencies = new ISOCurrencies();

$this->assertIsInt($currencies->subunitFor(new Currency($currency)));
self::assertIsInt($currencies->subunitFor(new Currency($currency)));
}

/**
Expand All @@ -63,7 +63,7 @@ public function itProvidesNumericCode(string $currency): void
{
$currencies = new ISOCurrencies();

$this->assertIsInt($currencies->numericCodeFor(new Currency($currency)));
self::assertIsInt($currencies->numericCodeFor(new Currency($currency)));
}

/**
Expand All @@ -87,7 +87,7 @@ public function itIsIterable(): void

$iterator = $currencies->getIterator();

$this->assertContainsOnlyInstancesOf(Currency::class, $iterator);
self::assertContainsOnlyInstancesOf(Currency::class, $iterator);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/CurrencyPairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public function itConvertsToJson(): void
$expectedJson = '{"baseCurrency":"EUR","counterCurrency":"USD","ratio":"1.25"}';
$actualJson = json_encode(new CurrencyPair(new Currency('EUR'), new Currency('USD'), '1.25'));

$this->assertEquals($expectedJson, $actualJson);
self::assertEquals($expectedJson, $actualJson);
}

/** @test */
public function it_parses_an_iso_string(): void
{
$this->assertEquals(
self::assertEquals(
new CurrencyPair(new Currency('EUR'), new Currency('USD'), '1.250000'),
CurrencyPair::createFromIso('EUR/USD 1.250000')
);
Expand All @@ -42,25 +42,25 @@ public function it_equals_to_another_currency_pair(): void
'1.250000'
);

$this->assertFalse($pair->equals(new CurrencyPair(
self::assertFalse($pair->equals(new CurrencyPair(
new Currency('GBP'),
new Currency('USD'),
'1.250000'
)));

$this->assertFalse($pair->equals(new CurrencyPair(
self::assertFalse($pair->equals(new CurrencyPair(
new Currency('EUR'),
new Currency('GBP'),
'1.250000'
)));

$this->assertFalse($pair->equals(new CurrencyPair(
self::assertFalse($pair->equals(new CurrencyPair(
new Currency('EUR'),
new Currency('USD'),
'1.5000'
)));

$this->assertTrue($pair->equals(new CurrencyPair(
self::assertTrue($pair->equals(new CurrencyPair(
new Currency('EUR'),
new Currency('USD'),
'1.250000'
Expand Down
2 changes: 1 addition & 1 deletion tests/CurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ final class CurrencyTest extends TestCase
*/
public function itConvertsToJson(): void
{
$this->assertEquals('"USD"', json_encode(new Currency('USD')));
self::assertEquals('"USD"', json_encode(new Currency('USD')));
}
}
12 changes: 6 additions & 6 deletions tests/Exchange/IndirectExchangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function itCalculatesAMinimalChain(): void
$pair = $exchange->quote(new Currency('USD'), new Currency('AOA'));

// USD => EUR => AOA
$this->assertEquals('USD', $pair->getBaseCurrency()->getCode());
$this->assertEquals('AOA', $pair->getCounterCurrency()->getCode());
$this->assertEquals(12, $pair->getConversionRatio());
self::assertEquals('USD', $pair->getBaseCurrency()->getCode());
self::assertEquals('AOA', $pair->getCounterCurrency()->getCode());
self::assertEquals(12, $pair->getConversionRatio());
}

private function createExchange(): IndirectExchange
Expand Down Expand Up @@ -60,9 +60,9 @@ public function itCalculatesAdjacentNodes(): void

$pair = $exchange->quote(new Currency('USD'), new Currency('EUR'));

$this->assertEquals('USD', $pair->getBaseCurrency()->getCode());
$this->assertEquals('EUR', $pair->getCounterCurrency()->getCode());
$this->assertEquals(4, $pair->getConversionRatio());
self::assertEquals('USD', $pair->getBaseCurrency()->getCode());
self::assertEquals('EUR', $pair->getCounterCurrency()->getCode());
self::assertEquals(4, $pair->getConversionRatio());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/BitcoinMoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function itFormatsMoney(int $value, string $formatted, int $fractionDigit
->with(self::equalTo($currency))
->willReturn(8);

$this->assertSame(
self::assertSame(
$formatted,
(new BitcoinMoneyFormatter($fractionDigits, $currencies))
->format(new Money($value, $currency))
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/DecimalMoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function itFormatsMoney(int $amount, string $currency, int $subunit, stri
->willReturn($subunit);

$moneyFormatter = new DecimalMoneyFormatter($currencies);
$this->assertSame($result, $moneyFormatter->format($money));
self::assertSame($result, $moneyFormatter->format($money));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/IntlLocalizedDecimalFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function itFormatsMoney(int $amount, string $currency, int $subunit, stri
->willReturn($subunit);

$moneyFormatter = new IntlLocalizedDecimalFormatter($numberFormatter, $currencies);
$this->assertSame($result, $moneyFormatter->format($money));
self::assertSame($result, $moneyFormatter->format($money));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Formatter/IntlMoneyFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function itFormatsMoney(int $amount, string $currency, int $subunit, stri
->willReturn($subunit);

$moneyFormatter = new IntlMoneyFormatter($numberFormatter, $currencies);
$this->assertSame($result, $moneyFormatter->format($money));
self::assertSame($result, $moneyFormatter->format($money));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/MoneyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function itCreatesMoneyUsingFactories(Currency $currency): void
$code = $currency->getCode();
$money = Money::{$code}(20);

$this->assertInstanceOf(Money::class, $money);
$this->assertEquals(new Money(20, $currency), $money);
self::assertInstanceOf(Money::class, $money);
self::assertEquals(new Money(20, $currency), $money);
}

/** @psalm-return list<array{Currency}> */
Expand Down
Loading

0 comments on commit 8df0b26

Please sign in to comment.