From 5ee99cddd4b801bfa64fc539d16117841a6de6f9 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Mon, 19 Mar 2018 22:44:36 +0200 Subject: [PATCH] Fixed tests adding wp_normalize_path() mocks. --- tests/PluginTest.php | 7 +++++++ tests/Provider/RecordTest.php | 7 +++++++ tests/Record/SqlTest.php | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 076472a..4b79bd5 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -2,6 +2,7 @@ namespace Rarst\Laps\Tests; +use Brain\Monkey\Functions; use Pimple\ServiceProviderInterface; use Rarst\Laps\Provider\Bootable_Provider_Interface; @@ -24,6 +25,12 @@ class PluginTest extends LapsTestCase { ->method( 'boot' ) ->with( $container ); + if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', '/wp' ); + define( 'WP_CONTENT_DIR', '/wp-content/' ); + } + Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg(); + $container->run(); } } diff --git a/tests/Provider/RecordTest.php b/tests/Provider/RecordTest.php index fbee7aa..346a3e5 100644 --- a/tests/Provider/RecordTest.php +++ b/tests/Provider/RecordTest.php @@ -2,6 +2,7 @@ namespace Rarst\Laps\Tests\Provider; +use Brain\Monkey\Functions; use Pimple\Exception\FrozenServiceException; use Rarst\Laps\Plugin; use Rarst\Laps\Provider\Record_Provider; @@ -24,6 +25,12 @@ class RecordTest extends LapsTestCase { $this->assertNotSame( $stopwatch_a, $stopwatch_b ); + if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', '/wp' ); + define( 'WP_CONTENT_DIR', '/wp-content/' ); + } + Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg(); + $this->assertArrayHasKey( 'records', $container ); $container->extend( 'collectors', function () {} ); diff --git a/tests/Record/SqlTest.php b/tests/Record/SqlTest.php index 66fc47d..e42b5c3 100644 --- a/tests/Record/SqlTest.php +++ b/tests/Record/SqlTest.php @@ -2,6 +2,7 @@ namespace Rarst\Laps\Tests\Record; +use Brain\Monkey\Functions; use Rarst\Laps\Record\Record; use Rarst\Laps\Record\Sql_Record_Collector; use Rarst\Laps\Tests\LapsTestCase; @@ -15,6 +16,12 @@ class SqlTest extends LapsTestCase { define( 'SAVEQUERIES', true ); + if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', '/wp' ); + define( 'WP_CONTENT_DIR', '/wp-content/' ); + } + Functions\expect( 'wp_normalize_path' )->zeroOrMoreTimes()->andReturnFirstArg(); + $collector = new Sql_Record_Collector(); $this->assertTrue( has_filter( 'query', [ $collector, 'query' ] ) ); @@ -27,7 +34,7 @@ class SqlTest extends LapsTestCase { $wpdb = new \stdClass(); $duration = 100; - $wpdb->queries[] = [ $query, $duration ]; + $wpdb->queries[] = [ $query, $duration, 'foo(), bar()' ]; $records = $collector->get_records();