Skip to content

Commit

Permalink
Merge pull request #153 from mlocati/tests-refactoring
Browse files Browse the repository at this point in the history
Tests refactoring
  • Loading branch information
mlocati committed Nov 8, 2018
2 parents 78be81d + 87378d2 commit 4d912fa
Show file tree
Hide file tree
Showing 23 changed files with 442 additions and 325 deletions.
23 changes: 13 additions & 10 deletions .scrutinizer.yml
@@ -1,12 +1,15 @@
filter:
paths:
- src/
excluded_paths:
- src/data/

checks:
php:
code_rating: true
duplication: true
php:
code_rating: true
duplication: true

tools:
external_code_coverage: true
php_code_sniffer: true
php_mess_detector: true
php_cs_fixer:
config: { level: psr2 }
filter:
paths: [src/*]
external_code_coverage: true
php_code_sniffer: true
php_mess_detector: true
3 changes: 3 additions & 0 deletions .travis/before_script.sh
Expand Up @@ -23,6 +23,9 @@ if test $DO_TESTS -ge 1 || test $DO_CODINGSTYLE -ge 1 || test $DO_UPDATEAPI -ge
if test $DO_TESTS -lt 1; then
echo '### REMOVING PHPUNIT FROM COMPOSER DEPENDENCIES'
composer --no-interaction remove --dev --no-update --no-scripts phpunit/phpunit
elif test "$TRAVIS_PHP_VERSION" = 'hhvm'; then
echo '### REQUIRING OLDER VERSION OF PHPUNIT FOR HHVM'
composer --no-interaction require --dev --no-update --no-scripts 'phpunit/phpunit:^4.8 || ^5.7'
fi

if test $DO_TESTS -ge 2; then
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -44,7 +44,7 @@
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "^4",
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.4",
"friendsofphp/php-cs-fixer": "2.2.*"
},
"replace": {
Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml
@@ -1,5 +1,9 @@
<phpunit
bootstrap="./tests/bootstrap.php"
backupGlobals="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuites>
<testsuite name="Data tests">
Expand All @@ -10,7 +14,7 @@
</testsuite>
<testsuite name="Miscellaneous functions tests">
<directory>./tests/Misc/</directory>
<directory phpVersion="5.5" phpVersionOperator=">=">./tests/Misc5.5/</directory>
<directory phpVersion="5.5" phpVersionOperator=">=">./tests/Misc5_5/</directory>
</testsuite>
<testsuite name="Plural functions tests">
<directory>./tests/Plural/</directory>
Expand Down
226 changes: 113 additions & 113 deletions tests/Calendar/CalendarTest.php

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions tests/Calendar/ConvertIsoToPhpFormatTest.php
@@ -1,13 +1,17 @@
<?php

namespace Punic\Test\Calendar;

use Punic\Calendar;
use Punic\Test\TestCase;
use stdClass;

class ConvertIsoToPhpFormatTest extends PHPUnit_Framework_TestCase
class ConvertIsoToPhpFormatTest extends TestCase
{
/**
* @return array
*/
public function providerLiterals()
public function provideLiterals()
{
return array(
array(null, null),
Expand All @@ -21,7 +25,7 @@ public function providerLiterals()
}

/**
* * @dataProvider providerLiterals
* * @dataProvider provideLiterals
*
* @param string|mixed $isoFormat
* @param string|null $phpFormat
Expand All @@ -34,7 +38,7 @@ public function testLiterals($isoFormat, $phpFormat)
/**
* @return array
*/
public function providerLetters()
public function provideLetters()
{
$result = array(
// Era name
Expand Down Expand Up @@ -124,7 +128,7 @@ public function providerLetters()
}

/**
* * @dataProvider providerLetters
* * @dataProvider provideLetters
*
* @param string $letter
* @param array $multiplierResults
Expand All @@ -140,7 +144,7 @@ public function testLetters($letter, $multiplierResults)
/**
* @return array
*/
public function providerLocaleFormats()
public function provideLocaleFormats()
{
return array(
array(
Expand All @@ -165,7 +169,7 @@ public function providerLocaleFormats()
}

/**
* * @dataProvider providerLocaleFormats
* * @dataProvider provideLocaleFormats
*
* @param string $localeID
* @param array $phpFormatsDate
Expand Down
15 changes: 10 additions & 5 deletions tests/Calendar/ConvertPhpToIsoFormatTest.php
@@ -1,8 +1,13 @@
<?php

namespace Punic\Test\Calendar;

use DateTime;
use DateTimeZone;
use Punic\Calendar;
use Punic\Test\TestCase;

class ConvertPhpToIsoFormatTest extends PHPUnit_Framework_TestCase
class ConvertPhpToIsoFormatTest extends TestCase
{
const TEST_TIMEZONE = 'America/Los_Angeles';
private $previousTimezone;
Expand All @@ -24,7 +29,7 @@ protected function tearDown()
/**
* @return array
*/
public function providerConvertPhpToIsoFormat()
public function provideConvertPhpToIsoFormat()
{
$chunks = array(
// Day
Expand Down Expand Up @@ -57,11 +62,11 @@ public function providerConvertPhpToIsoFormat()
}

/**
* @dataProvider providerConvertPhpToIsoFormat
* @dataProvider provideConvertPhpToIsoFormat
*
* @param string $phpFormat
* @param int $timestamp
* @param DateTime $dateTime
* @param \DateTime $dateTime
*/
public function testConvertPhpToIsoFormat($phpFormat, $timestamp, DateTime $dateTime)
{
Expand All @@ -76,7 +81,7 @@ public function testConvertPhpToIsoFormat($phpFormat, $timestamp, DateTime $date
/**
* @param int $timestamp
*
* @return DateTime
* @return \DateTime
*/
private static function timestampToDateTime($timestamp)
{
Expand Down
40 changes: 23 additions & 17 deletions tests/Currency/CurrencyTest.php
@@ -1,12 +1,18 @@
<?php

class CurrencyTest extends PHPUnit_Framework_TestCase
namespace Punic\Test\Currency;

use Punic\Currency;
use Punic\Data;
use Punic\Test\TestCase;

class CurrencyTest extends TestCase
{
public function testAvailability()
{
$allCurrencyCodes = null;
foreach (\Punic\Data::getAvailableLocales(true) as $locale) {
$theseCurrencyCodes = array_keys(\Punic\Currency::getAllCurrencies(true, true, $locale));
foreach (Data::getAvailableLocales(true) as $locale) {
$theseCurrencyCodes = array_keys(Currency::getAllCurrencies(true, true, $locale));
sort($theseCurrencyCodes);
if (null === $allCurrencyCodes) {
$allCurrencyCodes = $theseCurrencyCodes;
Expand All @@ -20,7 +26,7 @@ public function testAvailability()
/**
* @return array
*/
public function providerGetInfo()
public function provideGetInfo()
{
return array(
array('en', 'USD', null, 'US Dollar', '$', '$', '', 840),
Expand All @@ -36,7 +42,7 @@ public function providerGetInfo()
}

/**
* @dataProvider providerGetInfo
* @dataProvider provideGetInfo
*
* @param string $locale
* @param string $currencyCode
Expand All @@ -49,24 +55,24 @@ public function providerGetInfo()
*/
public function testGetInfo($locale, $currencyCode, $quantity, $currencyName, $currencySymbol, $currencySymbolNarrow, $currencySymbolAlternative, $iso4217)
{
$this->assertSame($currencyName, \Punic\Currency::getName($currencyCode, $quantity, $locale), 'Error getting name');
$this->assertSame($currencySymbol, \Punic\Currency::getSymbol($currencyCode, '', $locale), 'Error getting standard symbol');
$this->assertSame($currencySymbolNarrow, \Punic\Currency::getSymbol($currencyCode, 'narrow', $locale), 'Error getting narrow symbol');
$this->assertSame($currencySymbolAlternative, \Punic\Currency::getSymbol($currencyCode, 'alt', $locale), 'Error getting alternative symbol');
$this->assertSame($iso4217, \Punic\Currency::getNumericCode($currencyCode), 'Error getting code');
$this->assertSame($currencyName, Currency::getName($currencyCode, $quantity, $locale), 'Error getting name');
$this->assertSame($currencySymbol, Currency::getSymbol($currencyCode, '', $locale), 'Error getting standard symbol');
$this->assertSame($currencySymbolNarrow, Currency::getSymbol($currencyCode, 'narrow', $locale), 'Error getting narrow symbol');
$this->assertSame($currencySymbolAlternative, Currency::getSymbol($currencyCode, 'alt', $locale), 'Error getting alternative symbol');
$this->assertSame($iso4217, Currency::getNumericCode($currencyCode), 'Error getting code');
}

public function testGetByCode()
{
$this->assertSame('DKK', \Punic\Currency::getByNumericCode(208));
$this->assertSame('DKK', \Punic\Currency::getByNumericCode('208'));
$this->assertSame('', \Punic\Currency::getByNumericCode(666));
$this->assertSame('DKK', Currency::getByNumericCode(208));
$this->assertSame('DKK', Currency::getByNumericCode('208'));
$this->assertSame('', Currency::getByNumericCode(666));
}

/**
* @return array
*/
public function providerGetCurrencyForTerritory()
public function provideGetCurrencyForTerritory()
{
return array(
array('US', 'USD'),
Expand All @@ -77,19 +83,19 @@ public function providerGetCurrencyForTerritory()
}

/**
* @dataProvider providerGetCurrencyForTerritory
* @dataProvider provideGetCurrencyForTerritory
*
* @param string $territoryCode
* @param string $currencyCode
*/
public function testGetCurrencyForTerritory($territoryCode, $currencyCode)
{
$this->assertSame($currencyCode, \Punic\Currency::getCurrencyForTerritory($territoryCode));
$this->assertSame($currencyCode, Currency::getCurrencyForTerritory($territoryCode));
}

public function testGetAllCurrencies()
{
$currencies = \Punic\Currency::getAllCurrencies();
$currencies = Currency::getAllCurrencies();
$this->assertArrayHasKey('USD', $currencies);
$this->assertArrayHasKey('CHF', $currencies);

Expand Down

0 comments on commit 4d912fa

Please sign in to comment.