From f0799ed94381d1375802497cd5aa742a578e46cc Mon Sep 17 00:00:00 2001 From: peter279k Date: Mon, 6 Apr 2020 23:20:54 +0800 Subject: [PATCH] Test enhancement --- .gitignore | 1 + .travis.yml | 8 +- build/logs/clover.xml | 737 ------------------- composer.json | 4 +- tests/Geographer/Integration/CityTest.php | 5 +- tests/Geographer/Integration/CountryTest.php | 2 +- tests/Geographer/Integration/EarthTest.php | 15 +- tests/Geographer/Test.php | 10 +- 8 files changed, 24 insertions(+), 758 deletions(-) delete mode 100644 build/logs/clover.xml diff --git a/.gitignore b/.gitignore index 9476786..d8fd715 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.phar composer.lock vendor/ local/ +build/ diff --git a/.travis.yml b/.travis.yml index 1ec1cd8..a1be602 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ language: php php: - - 5.5 -# - 5.6 - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 - nightly install: - - composer install --dev + - composer install - mkdir -p build/logs after_script: diff --git a/build/logs/clover.xml b/build/logs/clover.xml deleted file mode 100644 index 6b757f2..0000000 --- a/build/logs/clover.xml +++ /dev/null @@ -1,737 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/composer.json b/composer.json index 052d28e..bf7f197 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,11 @@ } ], "require": { - "php": ">=5.5.0", + "php": ">=7.0", "menarasolutions/geographer-data": "^0.1.0" }, "require-dev": { - "phpunit/phpunit": "4.*|5.*", + "phpunit/phpunit": "^6|^7", "codeclimate/php-test-reporter": "dev-master", "illuminate/support": "5.*", "menarasolutions/geographer-de": "0.*", diff --git a/tests/Geographer/Integration/CityTest.php b/tests/Geographer/Integration/CityTest.php index 14e4ab8..87e2979 100644 --- a/tests/Geographer/Integration/CityTest.php +++ b/tests/Geographer/Integration/CityTest.php @@ -2,11 +2,12 @@ namespace Tests; +use PHPUnit\Framework\TestCase; use MenaraSolutions\Geographer\Earth; use MenaraSolutions\Geographer\City; use MenaraSolutions\Geographer\State; -class CityTest extends \PHPUnit_Framework_TestCase +class CityTest extends TestCase { /** * Countries that don't have any big cities @@ -51,7 +52,7 @@ public function most_states_of_all_countries_have_cities() if (! in_array($country->getCode(), $this->emptyCountries)) { //if ($citiesCount == 0) echo $country->getCode(); //if ($citiesCount == 0) echo count($country->getStates()); - $this->assertTrue($citiesCount > 0); + $this->assertGreaterThan(0, $citiesCount); } } } diff --git a/tests/Geographer/Integration/CountryTest.php b/tests/Geographer/Integration/CountryTest.php index 678e1e0..9d743ab 100644 --- a/tests/Geographer/Integration/CountryTest.php +++ b/tests/Geographer/Integration/CountryTest.php @@ -23,7 +23,7 @@ public function can_fetch_states_for_all_countries() $this->assertEquals(MemberCollection::class, get_class($states)); $this->assertTrue(is_array($states) || $states instanceof \ArrayObject); $array = $country->toArray(); - $this->assertTrue(is_array($array)); + $this->assertInternalType('array', $array); $this->assertArrayHasKey('code', $array); $this->assertArrayHasKey('code3', $array); $this->assertArrayHasKey('name', $array); diff --git a/tests/Geographer/Integration/EarthTest.php b/tests/Geographer/Integration/EarthTest.php index 192e63c..caa78dd 100644 --- a/tests/Geographer/Integration/EarthTest.php +++ b/tests/Geographer/Integration/EarthTest.php @@ -4,13 +4,12 @@ use MenaraSolutions\Geographer\Collections\MemberCollection; use MenaraSolutions\Geographer\Country; -use MenaraSolutions\Geographer\Exceptions\MisconfigurationException; use MenaraSolutions\Geographer\Earth; class EarthTest extends Test { const TOTAL_COUNTRIES = 249; - + /** * @test */ @@ -18,9 +17,9 @@ public function planet_class_loads_default_countries() { $earth = new Earth(); $countries = $earth->getCountries(); - $this->assertTrue(is_array($countries->toArray())); - $this->assertEquals(self::TOTAL_COUNTRIES, count($countries)); - $this->assertEquals(self::TOTAL_COUNTRIES, count($countries->toArray())); + $this->assertInternalType('array', $countries->toArray()); + $this->assertCount(self::TOTAL_COUNTRIES, $countries); + $this->assertCount(self::TOTAL_COUNTRIES, $countries->toArray()); } /** @@ -58,7 +57,7 @@ public function can_find_a_country_by_code() { $earth = new Earth(); $russia = $earth->findOne(['code' => 'RU']); - $this->assertTrue($russia instanceof Country); + $this->assertInstanceOf(Country::class, $russia); $this->assertEquals('RU', $russia->getCode()); } @@ -75,7 +74,7 @@ public function can_get_country_lists_by_continents() { $continent = $earth->{'get' . $continent}(); $this->assertInstanceOf(MemberCollection::class, $continent); - $this->assertTrue(is_array($continent->toArray())); + $this->assertInternalType('array', $continent->toArray()); } } @@ -94,4 +93,4 @@ public function can_filter_the_countries() $this->assertNotEquals($count, $countries->count()); } -} \ No newline at end of file +} diff --git a/tests/Geographer/Test.php b/tests/Geographer/Test.php index 28cadc9..e4bc544 100644 --- a/tests/Geographer/Test.php +++ b/tests/Geographer/Test.php @@ -2,16 +2,16 @@ namespace Tests; -use MenaraSolutions\Geographer\Earth; +use PHPUnit\Framework\TestCase; -abstract class Test extends \PHPUnit_Framework_TestCase +abstract class Test extends TestCase { use AnalyzesPerformance; /** * @return void */ - public function setUp() + protected function setUp() { $this->performanceHook(); parent::setUp(); @@ -20,9 +20,9 @@ public function setUp() /** * @return void */ - public function tearDown() + protected function tearDown() { $this->performanceCheck(); parent::tearDown(); } -} \ No newline at end of file +}