From c1a2177a8baca55fa3607fecdd8eb8391121599e Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Sun, 3 Dec 2017 00:39:31 -0200 Subject: [PATCH] Refactoring tests --- test/Faker/DefaultGeneratorTest.php | 4 +-- test/Faker/GeneratorTest.php | 2 +- test/Faker/Provider/BaseTest.php | 32 ++++++++++++------------ test/Faker/Provider/DateTimeTest.php | 4 +-- test/Faker/Provider/PaymentTest.php | 2 +- test/Faker/Provider/kk_KZ/PersonTest.php | 2 +- test/Faker/Provider/nl_BE/PersonTest.php | 4 +-- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/test/Faker/DefaultGeneratorTest.php b/test/Faker/DefaultGeneratorTest.php index 5bb7bbebf6..fa9eb8529f 100644 --- a/test/Faker/DefaultGeneratorTest.php +++ b/test/Faker/DefaultGeneratorTest.php @@ -10,14 +10,14 @@ class DefaultGeneratorTest extends TestCase public function testGeneratorReturnsNullByDefault() { $generator = new DefaultGenerator; - $this->assertSame(null, $generator->value); + $this->assertNull($generator->value); } public function testGeneratorReturnsDefaultValueForAnyPropertyGet() { $generator = new DefaultGenerator(123); $this->assertSame(123, $generator->foo); - $this->assertNotSame(null, $generator->bar); + $this->assertNotNull($generator->bar); } public function testGeneratorReturnsDefaultValueForAnyMethodCall() diff --git a/test/Faker/GeneratorTest.php b/test/Faker/GeneratorTest.php index 8771ab88ee..f15df441fd 100644 --- a/test/Faker/GeneratorTest.php +++ b/test/Faker/GeneratorTest.php @@ -20,7 +20,7 @@ public function testGetFormatterReturnsCallable() $generator = new Generator; $provider = new FooProvider(); $generator->addProvider($provider); - $this->assertTrue(is_callable($generator->getFormatter('fooFormatter'))); + $this->assertInternalType('callable', $generator->getFormatter('fooFormatter')); } public function testGetFormatterReturnsCorrectFormatter() diff --git a/test/Faker/Provider/BaseTest.php b/test/Faker/Provider/BaseTest.php index ad2e21592b..37d7a982eb 100644 --- a/test/Faker/Provider/BaseTest.php +++ b/test/Faker/Provider/BaseTest.php @@ -9,28 +9,28 @@ class BaseTest extends TestCase { public function testRandomDigitReturnsInteger() { - $this->assertTrue(is_integer(BaseProvider::randomDigit())); + $this->assertInternalType('integer', BaseProvider::randomDigit()); } public function testRandomDigitReturnsDigit() { - $this->assertTrue(BaseProvider::randomDigit() >= 0); - $this->assertTrue(BaseProvider::randomDigit() < 10); + $this->assertGreaterThanOrEqual(0, BaseProvider::randomDigit()); + $this->assertLessThan(10, BaseProvider::randomDigit()); } public function testRandomDigitNotNullReturnsNotNullDigit() { - $this->assertTrue(BaseProvider::randomDigitNotNull() > 0); - $this->assertTrue(BaseProvider::randomDigitNotNull() < 10); + $this->assertGreaterThan(0, BaseProvider::randomDigitNotNull()); + $this->assertLessThan(10, BaseProvider::randomDigitNotNull()); } public function testRandomDigitNotReturnsValidDigit() { for ($i = 0; $i <= 9; $i++) { - $this->assertTrue(BaseProvider::randomDigitNot($i) >= 0); - $this->assertTrue(BaseProvider::randomDigitNot($i) < 10); - $this->assertTrue(BaseProvider::randomDigitNot($i) !== $i); + $this->assertGreaterThanOrEqual(0, BaseProvider::randomDigitNot($i)); + $this->assertLessThan(10, BaseProvider::randomDigitNot($i)); + $this->assertNotSame(BaseProvider::randomDigitNot($i), $i); } } @@ -52,14 +52,14 @@ public function testRandomNumberThrowsExceptionWhenCalledWithATooHighNumberOfDig public function testRandomNumberReturnsInteger() { - $this->assertTrue(is_integer(BaseProvider::randomNumber())); - $this->assertTrue(is_integer(BaseProvider::randomNumber(5, false))); + $this->assertInternalType('integer', BaseProvider::randomNumber()); + $this->assertInternalType('integer', BaseProvider::randomNumber(5, false)); } public function testRandomNumberReturnsDigit() { - $this->assertTrue(BaseProvider::randomNumber(3) >= 0); - $this->assertTrue(BaseProvider::randomNumber(3) < 1000); + $this->assertGreaterThanOrEqual(0, BaseProvider::randomNumber(3)); + $this->assertLessThan(1000, BaseProvider::randomNumber(3)); } public function testRandomNumberAcceptsStrictParamToEnforceNumberSize() @@ -99,7 +99,7 @@ public function testRandomFloat() public function testRandomLetterReturnsString() { - $this->assertTrue(is_string(BaseProvider::randomLetter())); + $this->assertInternalType('string', BaseProvider::randomLetter()); } public function testRandomLetterReturnsSingleLetter() @@ -110,12 +110,12 @@ public function testRandomLetterReturnsSingleLetter() public function testRandomLetterReturnsLowercaseLetter() { $lowercaseLetters = 'abcdefghijklmnopqrstuvwxyz'; - $this->assertTrue(strpos($lowercaseLetters, BaseProvider::randomLetter()) !== false); + $this->assertNotFalse(strpos($lowercaseLetters, BaseProvider::randomLetter())); } public function testRandomAsciiReturnsString() { - $this->assertTrue(is_string(BaseProvider::randomAscii())); + $this->assertInternalType('string', BaseProvider::randomAscii()); } public function testRandomAsciiReturnsSingleCharacter() @@ -126,7 +126,7 @@ public function testRandomAsciiReturnsSingleCharacter() public function testRandomAsciiReturnsAsciiCharacter() { $lowercaseLetters = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'; - $this->assertTrue(strpos($lowercaseLetters, BaseProvider::randomAscii()) !== false); + $this->assertNotFalse(strpos($lowercaseLetters, BaseProvider::randomAscii())); } public function testRandomElementReturnsNullWhenArrayEmpty() diff --git a/test/Faker/Provider/DateTimeTest.php b/test/Faker/Provider/DateTimeTest.php index d967bd51ab..ce5c4fc56b 100644 --- a/test/Faker/Provider/DateTimeTest.php +++ b/test/Faker/Provider/DateTimeTest.php @@ -72,8 +72,8 @@ public function testUnixTime() { $timestamp = DateTimeProvider::unixTime(); $this->assertInternalType('int', $timestamp); - $this->assertTrue($timestamp >= 0); - $this->assertTrue($timestamp <= time()); + $this->assertGreaterThanOrEqual(0, $timestamp); + $this->assertLessThanOrEqual(time(), $timestamp); } public function testDateTime() diff --git a/test/Faker/Provider/PaymentTest.php b/test/Faker/Provider/PaymentTest.php index ab5e64fe77..d2a4524118 100644 --- a/test/Faker/Provider/PaymentTest.php +++ b/test/Faker/Provider/PaymentTest.php @@ -48,7 +48,7 @@ public function loadLocalProviders($locale) public function testCreditCardTypeReturnsValidVendorName() { - $this->assertTrue(in_array($this->faker->creditCardType, array('Visa', 'MasterCard', 'American Express', 'Discover Card'))); + $this->assertContains($this->faker->creditCardType, array('Visa', 'MasterCard', 'American Express', 'Discover Card')); } public function creditCardNumberProvider() diff --git a/test/Faker/Provider/kk_KZ/PersonTest.php b/test/Faker/Provider/kk_KZ/PersonTest.php index a641bf5aa7..c565735250 100644 --- a/test/Faker/Provider/kk_KZ/PersonTest.php +++ b/test/Faker/Provider/kk_KZ/PersonTest.php @@ -25,6 +25,6 @@ public function testIndividualIdentificationNumberIsValid() $individualIdentificationNumber = $this->faker->individualIdentificationNumber($birthDate); $controlDigit = Person::checkSum($individualIdentificationNumber); - $this->assertTrue($controlDigit === (int)substr($individualIdentificationNumber, 11, 1)); + $this->assertSame($controlDigit, (int)substr($individualIdentificationNumber, 11, 1)); } } diff --git a/test/Faker/Provider/nl_BE/PersonTest.php b/test/Faker/Provider/nl_BE/PersonTest.php index fb3f97a01e..4885cc3dad 100644 --- a/test/Faker/Provider/nl_BE/PersonTest.php +++ b/test/Faker/Provider/nl_BE/PersonTest.php @@ -27,13 +27,13 @@ public function setUp() public function testRrnIsValid() { $rrn = $this->faker->rrn(); - + $this->assertEquals(11, strlen($rrn)); $ctrlNumber = substr($rrn, 9, 2); $calcCtrl = 97 - (substr($rrn, 0, 9) % 97); $altcalcCtrl = 97 - ((2 . substr($rrn, 0, 9)) % 97); - $this->assertTrue(in_array($ctrlNumber, array($calcCtrl, $altcalcCtrl))); + $this->assertContains($ctrlNumber, array($calcCtrl, $altcalcCtrl)); $middle = substr($rrn, 6, 3); $this->assertGreaterThan(1, $middle);