From 739ed7dd9001091ef4a5fb941381287f5bb5c220 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Sun, 24 Mar 2019 19:32:33 +0200 Subject: [PATCH] Updated unit tests for PHPUnit 8. --- CHANGELOG.md | 5 ++++- README.md | 8 ++++++++ composer.lock | 24 ++++++++++++------------ tests/Event/EventTest.php | 12 ++++++------ tests/Formatter/BacktraceTest.php | 6 ++++-- tests/Formatter/HookTest.php | 5 +++-- tests/LapsTestCase.php | 4 ++-- tests/Manager/LoadOrderTest.php | 2 +- tests/Record/CoreTest.php | 2 +- tests/Record/IteratorTest.php | 4 ++-- tests/Record/RecordTest.php | 4 ++-- tests/Record/SqlTest.php | 6 +++--- tests/Record/StopwatchTest.php | 4 ++-- 13 files changed, 50 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e00428e..a81bbde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Changed +- unit tests for PHPUnit 8 + ## 3.2 - 2019-01-30 ### Added @@ -17,7 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - tracking of load events when network–activated ### Deprecated -- dedicated classes for extension events. +- dedicated classes for extension events ## 3.1 - 2019-01-22 diff --git a/README.md b/README.md index fa584c7..b92dca8 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,14 @@ API requests need to be authenticated as admin for performance data to be sent. | -------------------------------------------------- | -------- | | `composer require rarst/laps` | [![Download Laps](https://img.shields.io/badge/dynamic/json.svg?label=download&url=https%3A%2F%2Fapi.github.com%2Frepos%2Frarst%2Flaps%2Freleases%2Flatest&query=%24.assets[0].name&style=for-the-badge)](https://www.rarst.net/download/laps) | +## Tests + +Tests require [Brain Monkey](https://github.com/Brain-WP/BrainMonkey) (included in dependencies) and PHPUnit 8 (not included). + +```bash +phpunit +``` + ## License MIT \ No newline at end of file diff --git a/composer.lock b/composer.lock index ce8bd1c..9c2af9f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "185526a596d05cc666426641f175a314", + "content-hash": "a72036af9e80358500e4274847500bcc", "packages": [ { "name": "composer/installers", @@ -434,16 +434,16 @@ }, { "name": "brain/monkey", - "version": "2.2.0", + "version": "2.2.1", "source": { "type": "git", "url": "https://github.com/Brain-WP/BrainMonkey.git", - "reference": "ed9e0698bc1292f33698719da8ca1aa2e18acc51" + "reference": "326a537bf518edd61bc57ab275e8b075ebb8a1a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/ed9e0698bc1292f33698719da8ca1aa2e18acc51", - "reference": "ed9e0698bc1292f33698719da8ca1aa2e18acc51", + "url": "https://api.github.com/repos/Brain-WP/BrainMonkey/zipball/326a537bf518edd61bc57ab275e8b075ebb8a1a9", + "reference": "326a537bf518edd61bc57ab275e8b075ebb8a1a9", "shasum": "" }, "require": { @@ -494,7 +494,7 @@ "test", "testing" ], - "time": "2017-12-01T16:32:09+00:00" + "time": "2019-03-15T13:42:24+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -546,16 +546,16 @@ }, { "name": "mockery/mockery", - "version": "1.2.0", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "100633629bf76d57430b86b7098cd6beb996a35a" + "reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/100633629bf76d57430b86b7098cd6beb996a35a", - "reference": "100633629bf76d57430b86b7098cd6beb996a35a", + "url": "https://api.github.com/repos/mockery/mockery/zipball/0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2", + "reference": "0eb0b48c3f07b3b89f5169ce005b7d05b18cf1d2", "shasum": "" }, "require": { @@ -564,7 +564,7 @@ "php": ">=5.6.0" }, "require-dev": { - "phpunit/phpunit": "~5.7.10|~6.5|~7.0" + "phpunit/phpunit": "~5.7.10|~6.5|~7.0|~8.0" }, "type": "library", "extra": { @@ -607,7 +607,7 @@ "test double", "testing" ], - "time": "2018-10-02T21:52:37+00:00" + "time": "2019-02-13T09:37:52+00:00" }, { "name": "pds/skeleton", diff --git a/tests/Event/EventTest.php b/tests/Event/EventTest.php index 809d476..8934455 100644 --- a/tests/Event/EventTest.php +++ b/tests/Event/EventTest.php @@ -17,7 +17,7 @@ class EventTest extends LapsTestCase { $events = ( new Core_Events() )->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } @@ -29,7 +29,7 @@ class EventTest extends LapsTestCase { Functions\expect( 'genesis' )->zeroOrMoreTimes(); $events = $genesis->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } @@ -46,7 +46,7 @@ class EventTest extends LapsTestCase { $events = $hybrid->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } @@ -59,7 +59,7 @@ class EventTest extends LapsTestCase { $events = $tha->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } @@ -72,7 +72,7 @@ class EventTest extends LapsTestCase { $events = $woocommerce->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } @@ -85,7 +85,7 @@ class EventTest extends LapsTestCase { $events = $yoast->get_events(); - $this->assertInternalType( 'array', $events ); + $this->assertIsArray( $events ); $this->assertNotEmpty( $events ); } } diff --git a/tests/Formatter/BacktraceTest.php b/tests/Formatter/BacktraceTest.php index 99ecfdd..f1a5463 100644 --- a/tests/Formatter/BacktraceTest.php +++ b/tests/Formatter/BacktraceTest.php @@ -51,8 +51,10 @@ class BacktraceTest extends LapsTestCase { $result = $formatter->format( $backtrace ); - $this->assertInternalType( 'array', $result ); - $this->assertArraySubset( [ 'foo', 'path.php' ], array_values( $result ) ); + $this->assertIsArray( $result ); + $result = array_values( $result ); + $this->assertEquals( 'foo', $result[0] ); + $this->assertEquals( 'path.php', $result[1] ); } } diff --git a/tests/Formatter/HookTest.php b/tests/Formatter/HookTest.php index 2798e26..246781b 100644 --- a/tests/Formatter/HookTest.php +++ b/tests/Formatter/HookTest.php @@ -50,8 +50,9 @@ class HookTest extends LapsTestCase { $result = $formatter->format( $hook ); - $this->assertInternalType( 'array', $result ); - $this->assertArraySubset( [ 'function(2)', 'class::method' ], $result ); + $this->assertIsArray( $result ); + $this->assertEquals( 'function(2)', $result[0] ); + $this->assertEquals( 'class::method', $result[1] ); $this->assertStringStartsWith( 'closure from', $result[2] ); $this->assertStringStartsWith( 'anonymous class from', $result[3] ); } diff --git a/tests/LapsTestCase.php b/tests/LapsTestCase.php index d61f578..f382090 100644 --- a/tests/LapsTestCase.php +++ b/tests/LapsTestCase.php @@ -10,12 +10,12 @@ class LapsTestCase extends TestCase { use MockeryPHPUnitIntegration; - protected function setUp() { + protected function setUp():void { parent::setUp(); Monkey\setUp(); } - protected function tearDown() { + protected function tearDown(): void { Monkey\tearDown(); parent::tearDown(); } diff --git a/tests/Manager/LoadOrderTest.php b/tests/Manager/LoadOrderTest.php index c5bfaa5..0b39d0a 100644 --- a/tests/Manager/LoadOrderTest.php +++ b/tests/Manager/LoadOrderTest.php @@ -43,7 +43,7 @@ class LoadOrderTest extends LapsTestCase { $plugins = $manager->pre_update_option_active_plugins( $plugins ); - $this->assertInternalType( 'array', $plugins ); + $this->assertIsArray( $plugins ); $this->assertCount( 3, $plugins ); $this->assertEquals( 'laps/laps.php', $plugins[0] ); } diff --git a/tests/Record/CoreTest.php b/tests/Record/CoreTest.php index 0883bd1..e8af523 100644 --- a/tests/Record/CoreTest.php +++ b/tests/Record/CoreTest.php @@ -17,7 +17,7 @@ class CoreTest extends LapsTestCase { $records = $collector->get_records(); - $this->assertInternalType( 'array', $records ); + $this->assertIsArray( $records ); $this->assertCount( 2, $records ); $this->assertInstanceOf( Record_Interface::class, $records[0] ); } diff --git a/tests/Record/IteratorTest.php b/tests/Record/IteratorTest.php index b56224c..ce1c527 100644 --- a/tests/Record/IteratorTest.php +++ b/tests/Record/IteratorTest.php @@ -53,7 +53,7 @@ class IteratorTest extends LapsTestCase { $this->assertTrue( $iterator->valid() ); $records = $iterator->current(); - $this->assertInternalType( 'array', $records ); + $this->assertIsArray( $records ); $this->assertArrayHasKey( 'description', $records[0] ); $this->assertArrayHasKey( 'category', $records[0] ); @@ -64,7 +64,7 @@ class IteratorTest extends LapsTestCase { $this->assertTrue( $iterator->valid() ); $records = $iterator->current(); - $this->assertInternalType( 'array', $records ); + $this->assertIsArray( $records ); $iterator->next(); $this->assertFalse( $iterator->valid() ); diff --git a/tests/Record/RecordTest.php b/tests/Record/RecordTest.php index 297c812..1526124 100644 --- a/tests/Record/RecordTest.php +++ b/tests/Record/RecordTest.php @@ -24,8 +24,8 @@ class RecordTest extends LapsTestCase { $this->assertEquals( $name, $record->get_name() ); $this->assertEquals( $origin, $record->get_origin() ); $this->assertEquals( $duration, $record->get_duration() ); - $this->assertContains( $name, $record->get_description() ); - $this->assertContains( (string) ( $duration * 1000 ), $record->get_description() ); + $this->assertStringContainsString( $name, $record->get_description() ); + $this->assertStringContainsString( (string) ( $duration * 1000 ), $record->get_description() ); $this->assertEmpty( $record->get_category() ); $record = new Record( $name, $origin, $duration, $description, $category ); diff --git a/tests/Record/SqlTest.php b/tests/Record/SqlTest.php index 89c9cf4..315991b 100644 --- a/tests/Record/SqlTest.php +++ b/tests/Record/SqlTest.php @@ -38,15 +38,15 @@ class SqlTest extends LapsTestCase { $records = $collector->get_records(); - $this->assertInternalType( 'array', $records ); + $this->assertIsArray( $records ); $this->assertCount( 1, $records ); $record = $records[0]; $this->assertInstanceOf( Record::class, $record ); $this->assertEquals( $query, $record->get_name() ); - $this->assertContains( $query, $record->get_description() ); - $this->assertInternalType( 'float', $record->get_origin() ); + $this->assertStringContainsString( $query, $record->get_description() ); + $this->assertIsFloat( $record->get_origin() ); $this->assertEquals( $duration, $record->get_duration() ); $this->assertEquals( 'sql-read', $record->get_category() ); } diff --git a/tests/Record/StopwatchTest.php b/tests/Record/StopwatchTest.php index e36df26..b27e866 100644 --- a/tests/Record/StopwatchTest.php +++ b/tests/Record/StopwatchTest.php @@ -26,7 +26,7 @@ class StopwatchTest extends LapsTestCase { $records = $collector->get_records(); - $this->assertInternalType( 'array', $records ); + $this->assertIsArray( $records ); $this->assertCount( 1, $records ); $this->assertInstanceOf( Stopwatch_Record::class, $records[0] ); @@ -47,6 +47,6 @@ class StopwatchTest extends LapsTestCase { $this->assertEquals( 'info', $record->get_category() ); $this->assertEquals( $event->getOrigin() / 1000, $record->get_origin() ); $this->assertEquals( $event->getDuration() / 1000, $record->get_duration() ); - $this->assertContains( 'Event', $record->get_description() ); + $this->assertStringContainsString( 'Event', $record->get_description() ); } }